From ac6d786c54cfa00ff4d54dc4e184e3524600ce40 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 17 Dec 2008 06:13:10 +0000 Subject: [PATCH] Mach es ganz --- DreamboxBouqets.php | 106 ++++++++++++++++++++++++++++++++--------- sync-radio-bouqets.php | 4 +- syncfunctions.php | 11 +++-- 3 files changed, 93 insertions(+), 28 deletions(-) diff --git a/DreamboxBouqets.php b/DreamboxBouqets.php index e035b6d..3541e6b 100644 --- a/DreamboxBouqets.php +++ b/DreamboxBouqets.php @@ -10,11 +10,53 @@ class DreamboxBouqets /** * Fetch radio bouqets * - * @param string $ip IP-address or hostname of the dreambox + * @param string $ip IP-address or hostname of the dreambox + * @param boolean $bEpgData If EPG data shall be fetched, too * * @return array Array of bouqets and the items */ - public static function fetchRadioBouqets($ip) + public static function fetchRadioBouqets($ip, $bEpgData = true) + { + return self::fetchBouqets( + $ip, + //TODO: fetch from dreambox config.js + '1:7:2:0:0:0:0:0:0:0:(type == 2)FROM BOUQUET "bouquets.radio" ORDER BY bouquet', + $bEpgData + ); + }//public static function fetchRadioBouqets(..) + + + + /** + * Fetch TV bouqets + * + * @param string $ip IP-address or hostname of the dreambox + * @param boolean $bEpgData If EPG data shall be fetched, too + * + * @return array Array of bouqets and the items + */ + public static function fetchTvBouqets($ip, $bEpgData = true) + { + return self::fetchBouqets( + $ip, + //TODO: fetch from dreambox config.js + '1:7:2:0:0:0:0:0:0:0:(type == 2)FROM BOUQUET "bouquets.tv" ORDER BY bouquet', + $bEpgData + ); + }//public static function fetchTvBouqets(..) + + + + /** + * Fetch bouqets + * + * @param string $ip IP-address or hostname of the dreambox + * @param string $sql SQL query to fetch bouqet from database + * @param boolean $bEpgData If EPG data shall be fetched, too + * + * @return array Array of bouqets (name is key) and the items (sub arrays) + */ + public static function fetchBouqets($ip, $sql, $bEpgData = true) { $host = 'http://' . $ip; $streamhost = 'http://' . $ip . ':8001'; @@ -23,11 +65,8 @@ class DreamboxBouqets $url_bouqet_epg = $host . '/web/epgnow?bRef='; $url_stream = $streamhost . '/'; - //TODO: fetch from dreambox config.js - $bouqet_radio = '1:7:2:0:0:0:0:0:0:0:(type == 2)FROM BOUQUET "bouquets.radio" ORDER BY bouquet'; - - $url = $url_getServices . urlencode($bouqet_radio); + $url = $url_getServices . urlencode($sql); $radiobouqets = new SimpleXMLElement( file_get_contents($url) ); @@ -46,30 +85,32 @@ class DreamboxBouqets $url ) ); + foreach ($stations->e2service as $station) { $strStationRef = (string)$station->e2servicereference; $arBouqets[$strBouqetName][$strStationRef] = array( 'name' => (string)$station->e2servicename, - 'playlist' => $url_stream_playlist . $strStationRef, - 'stream' => $url_stream . $strStationRef + 'playlist' => $url_stream_playlist . self::encodeUrl($strStationRef), + 'stream' => $url_stream . self::encodeUrl($strStationRef), ); } - $epgs = new SimpleXMLElement( - file_get_contents($epgurl) - ); - foreach ($epgs->e2event as $epg) { - $strStationRef = (string)$epg->e2eventservicereference; - $arBouqets[$strBouqetName][$strStationRef] = array_merge( - $arBouqets[$strBouqetName][$strStationRef], - array( - 'epgtitle' => (string)$epg->e2eventtitle, - 'epgdescription' => (string)$epg->e2eventdescription, - 'epgdescription2' => (string)$epg->e2eventdescriptionextendet, - ) + if ($bEpgData) { + $epgs = new SimpleXMLElement( + file_get_contents($epgurl) ); - } - + foreach ($epgs->e2event as $epg) { + $strStationRef = (string)$epg->e2eventservicereference; + $arBouqets[$strBouqetName][$strStationRef] = array_merge( + $arBouqets[$strBouqetName][$strStationRef], + array( + 'epgtitle' => (string)$epg->e2eventtitle, + 'epgdescription' => (string)$epg->e2eventdescription, + 'epgdescription2' => (string)$epg->e2eventdescriptionextendet, + ) + ); + } + }//if $bEpgData } return $arBouqets; @@ -77,10 +118,29 @@ class DreamboxBouqets + /** + * Fix the given bouqet name, make it a nice readable one. + * Removes some special chars and spaces. + * + * @param string $name Bouqet name + * + * @return string Fixed bouqet name + */ protected static function properBouqetName($name) { return trim(preg_replace('#\(.+\)$#', '', $name)); - } + }//protected static function properBouqetName(..) + + + + protected static function encodeUrl($strUrl) + { + return str_replace( + array(' ', '"'), + array('%20', '%22'), + $strUrl + ); + }//protected static function encodeUrl(..) } ?> \ No newline at end of file diff --git a/sync-radio-bouqets.php b/sync-radio-bouqets.php index 1af0868..6f66691 100644 --- a/sync-radio-bouqets.php +++ b/sync-radio-bouqets.php @@ -76,7 +76,7 @@ foreach ($arBouqetNames as $strBouqetName) { //bouqet does not exist anymore -> delete container echo " deleting container " . $strBouqetName . "\n"; if ($bReally) { - $mt->delete($arContainerNames[$strBouqetName]); + $mt->deleteItem($arContainerNames[$strBouqetName]); } } } @@ -150,7 +150,7 @@ foreach ($arValidContainers as $nContainerId => $container) { $arTitles = enigtombGetStationTitle($arBouqetStationsByUri[$strUri]); echo " " . $arTitles['title'] . "\n"; if ($bReally) { - $arStationItemsByUri[$strUri]->createExternalLink( + $container->createExternalLink( $arTitles['title'], $strUri, $arTitles['description'], $GLOBALS['enigtombConfig']['mediatomb']['mimetype'], 'http-get', 'object.item', false diff --git a/syncfunctions.php b/syncfunctions.php index a63d8a0..076a3f0 100644 --- a/syncfunctions.php +++ b/syncfunctions.php @@ -20,7 +20,8 @@ if (!function_exists('enigtombGetStationTitle')) { { $strName = enigtombFixName($arStation['name']); - if ($arStation['epgtitle'] + if (isset($arStation['epgtitle']) + && $arStation['epgtitle'] && $arStation['epgtitle'] != 'None' && $arStation['epgtitle'] != $arStation['name'] ) { @@ -43,12 +44,16 @@ if (!function_exists('enigtombGetStationTitle')) { $strName .= ' - ' . $strEpgTitle; } - if ($arStation['epgdescription'] && $arStation['epgdescription'] != 'None') { + if (isset($arStation['epgdescription']) + && $arStation['epgdescription'] && $arStation['epgdescription'] != 'None' + ) { $strDescription = $arStation['epgdescription']; } else { $strDescription = ''; } - if ($arStation['epgdescription2'] && $arStation['epgdescription2'] != 'None') { + if (isset($arStation['epgdescription2']) + && $arStation['epgdescription2'] && $arStation['epgdescription2'] != 'None' + ) { $strDescription .= ' ' . $arStation['epgdescription2']; } if (!$strDescription) { -- 2.30.2