changed about
[enigtomb.git] / copy-radio-bouqets.php
1 <?php
2 /**
3 * Copies all radio bouqets into a folder on mediatomb.
4 * Deletes/clears the folder at first.
5 *
6 * @author   Christian Weiske <cweiske@php.net>
7 * @license  LGPL http://www.gnu.org/copyleft/lesser.html
8 */
9 require_once 'DreamboxBouqets.php';
10 require_once 'Services/MediaTomb.php';
11 require_once 'config.php';
12
13 echo "fetching bouqets\n";
14 $arBouqets = DreamboxBouqets::fetchRadioBouqets(
15     $GLOBALS['enigtombConfig']['dreambox']['host']
16 );
17
18 $mt = new Services_MediaTomb(
19     $GLOBALS['enigtombConfig']['mediatomb']['user'],
20     $GLOBALS['enigtombConfig']['mediatomb']['pass'],
21     $GLOBALS['enigtombConfig']['mediatomb']['host'],
22     $GLOBALS['enigtombConfig']['mediatomb']['port']
23 );
24
25 $strRadiodir = $GLOBALS['enigtombConfig']['mediatomb']['radiodir'];
26
27 $radiodir = $mt->getContainerByPath($strRadiodir);
28 if ($radiodir !== null) {
29     $mt->delete($radiodir);
30 }
31
32 foreach ($arBouqets as $strBouqetName => $arStations) {
33     echo "adding " . $strBouqetName . "\n";
34     if ($strBouqetName == $GLOBALS['enigtombConfig']['mediatomb']['rootBouqet']) {
35         $dir = $mt->getContainerByPath($strRadiodir);
36         if ($dir === null) {
37             $dir = $mt->createContainerByPath($strRadiodir);
38         }
39     } else {
40         $dir = $mt->createContainerByPath($strRadiodir . '/' . $strBouqetName);
41     }
42
43     foreach ($arStations as $arStation) {
44         echo " adding " . $arStation['name'] . "\n";
45         $strName = $arStation['name'];
46         if ($arStation['epgtitle']) {
47             $strName .= ' - ' . $arStation['epgtitle'];
48         }
49         if ($arStation['epgdescription']) {
50             $strDescription = $arStation['epgdescription'];
51         } else {
52             $strDescription = '';
53         }
54         if ($arStation['epgdescription2']) {
55             $strDescription .= ' ' . $arStation['epgdescription2'];
56         }
57         if (!$strDescription) {
58             $strDescription = $strName;
59         }
60         $mt->createExternalLink(
61             $dir->id, $strName, $arStation['stream'], trim($strDescription),
62             $GLOBALS['enigtombConfig']['mediatomb']['mimetype'],
63             Services_MediaTomb::PROTOCOL_HTTP_GET
64         );
65     }
66 }
67
68 ?>