changed about
[enigtomb.git] / DreamboxBouqets.php
1 <?php
2 /**
3 * Fetches bouqet information from the dreambox
4 *
5 * @author Christian Weiske <cweiske@cweiske.de>
6 * @license  LGPL http://www.gnu.org/copyleft/lesser.html
7 */
8 class DreamboxBouqets
9 {
10     /**
11     * Fetch radio bouqets
12     *
13     * @param string $ip IP-address or hostname of the dreambox
14     *
15     * @return array Array of bouqets and the items
16     */
17     public static function fetchRadioBouqets($ip)
18     {
19         $host       = 'http://' . $ip;
20         $streamhost = 'http://' . $ip . ':8001';
21         $url_getServices     = $host . "/web/getservices?sRef=";
22         $url_stream_playlist = $host . '/web/stream.m3u?ref=';
23         $url_bouqet_epg      = $host . '/web/epgnow?bRef=';
24         $url_stream          = $streamhost . '/';
25
26         //TODO: fetch from dreambox config.js
27         $bouqet_radio = '1:7:2:0:0:0:0:0:0:0:(type == 2)FROM BOUQUET "bouquets.radio" ORDER BY bouquet';
28
29
30         $url = $url_getServices . urlencode($bouqet_radio);
31         $radiobouqets = new SimpleXMLElement(
32             file_get_contents($url)
33         );
34
35         $arBouqets = array();
36         foreach ($radiobouqets->e2service as $bouqet) {
37             $strBouqetName = self::properBouqetName($bouqet->e2servicename);
38             $arBouqets[$strBouqetName] = array();
39
40             $strRef = $bouqet->e2servicereference;
41             $url    = $url_getServices . urlencode($strRef);
42             $epgurl = $url_bouqet_epg  . urlencode($strRef);
43
44             $stations = new SimpleXMLElement(
45                 file_get_contents(
46                     $url
47                 )
48             );
49             foreach ($stations->e2service as $station) {
50                 $strStationRef = (string)$station->e2servicereference;
51                 $arBouqets[$strBouqetName][$strStationRef] = array(
52                     'name'     => (string)$station->e2servicename,
53                     'playlist' => $url_stream_playlist . $strStationRef,
54                     'stream'   => $url_stream . $strStationRef
55                 );
56             }
57
58             $epgs = new SimpleXMLElement(
59                 file_get_contents($epgurl)
60             );
61             foreach ($epgs->e2event as $epg) {
62                 $strStationRef = (string)$epg->e2eventservicereference;
63                 $arBouqets[$strBouqetName][$strStationRef] = array_merge(
64                     $arBouqets[$strBouqetName][$strStationRef],
65                     array(
66                         'epgtitle'        => (string)$epg->e2eventtitle,
67                         'epgdescription'  => (string)$epg->e2eventdescription,
68                         'epgdescription2' => (string)$epg->e2eventdescriptionextendet,
69                     )
70                 );
71             }
72
73         }
74
75         return $arBouqets;
76     }//public static function fetchRadioBouqets(..)
77
78
79
80     protected static function properBouqetName($name)
81     {
82         return trim(preg_replace('#\(.+\)$#', '', $name));
83     }
84 }
85
86 ?>