url = $url; $this->station = $station; $this->image = $image; $this->tracks = array(); $parts = explode(PHP_EOL, $data); $pointer = -1; foreach ($parts as $line) { $bits = explode("=", $line); if (preg_match('/File/', $bits[0])) { $pointer++; $this->tracks[$pointer] = array('TrackUri' => trim(implode('=', array_slice($bits,1))), 'PrettyStream' => ''); } if (preg_match('/Title/', $bits[0])) { $this->tracks[$pointer]['PrettyStream'] = $bits[1]; } } if ($this->tracks[0]['PrettyStream'] != '') { $this->station = checkStationAgain($this->station, $this->tracks[0]['PrettyStream']); } } public function updateDatabase() { $stationid = check_radio_station($this->url, $this->station, $this->image); if ($stationid) { check_radio_tracks($stationid, $this->tracks); } else { logger::error("RADIO", "ERROR! Null station ID!"); header('HTTP/1.1 417 Expectation Failed'); exit(0); } } public function getTracksToAdd() { $tracks = array(); foreach ($this->tracks as $r) { $tracks[] = 'add "'.format_for_mpd($r['TrackUri']).'"'; } return $tracks; } } // // http://www.bbc.co.uk/5livesportsextra/ // BBC Radio 5 live sports extra // BBC // (c) British Broadcasting Corporation // // // // // // // // // class asxFile { public function __construct($data, $url, $station, $image) { $this->url = $url; $xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA); if ($xml === false) { logger::fail("RADIO", "ERROR could not parse XML from",$url); header('HTTP/1.1 417 Expectation Failed'); exit(0); } $this->station = ($xml->TITLE != null && $xml->TITLE != '') ? $xml->TITLE : $station; $this->image = $image; $this->prettystream = ($xml->COPYRIGHT != null && $xml->COPYRIGHT != '') ? $xml->COPYRIGHT : ""; $this->tracks = array(); foreach($xml->Entry as $r) { $this->tracks[] = array('TrackUri' => $r->ref['href'], 'PrettyStream' => $prettystream); } } public function updateDatabase() { $stationid = check_radio_station($this->url, $this->station, $this->image); if ($stationid) { check_radio_tracks($stationid, $this->tracks); } else { logger::error("RADIO", "ERROR! Null station ID!"); header('HTTP/1.1 417 Expectation Failed'); exit(0); } } public function getTracksToAdd() { return array('load "'.format_for_mpd(htmlspecialchars_decode($this->url)).'"'); } } // // I Love Radio (www.iloveradio.de) // http://www.iloveradio.de // // http://87.230.53.70:80/iloveradio1.mp3 // http://80.237.157.79:80/iloveradio1.mp3 // http://80.237.156.44:80/iloveradio1.mp3 // http://87.230.100.70:80/iloveradio1.mp3 // http://80.237.158.62:80/iloveradio1.mp3 // http://80.237.157.81:80/iloveradio1.mp3 // http://80.237.157.76:80/iloveradio1.mp3 // http://80.237.158.76:80/iloveradio1.mp3 // http://89.149.254.214:80/iloveradio1.mp3 // http://80.237.157.64:80/iloveradio1.mp3 // // class xspfFile { public function __construct($data, $url, $station, $image) { $this->url = $url; // Handle badly formed XML that some stations return $data = preg_replace('/ & /', ' & ', $data); $data = preg_replace('/ < /', ' < ', $data); $data = preg_replace('/ > /', ' > ', $data); $xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA); if ($xml === false) { logger::fail("RADIO", "ERROR could not parse XML from",$url); header('HTTP/1.1 417 Expectation Failed'); exit(0); } $this->station = $xml->title != null ? $xml->title : $station; $this->image = $image; $prettystream = $xml->info != null ? $xml->info : ""; $this->tracks = array(); foreach($xml->trackList->track as $r) { $this->tracks[] = array('TrackUri' => (string) $r->location, 'PrettyStream' => $prettystream); } } public function updateDatabase() { $stationid = check_radio_station($this->url, $this->station, $this->image); if ($stationid) { check_radio_tracks($stationid, $this->tracks); } else { logger::error("RADIO", "ERROR! Null station ID!"); header('HTTP/1.1 417 Expectation Failed'); exit(0); } } public function getTracksToAdd() { $tracks = array(); foreach ($this->tracks as $r) { $tracks[] = 'add "'.format_for_mpd($r['TrackUri']).'"'; } return $tracks; } } // #This is a comment // // http://uk1.internet-radio.com:15614/ // or // #EXTM3U // #EXTINF:duration,Artist - Album class m3uFile { public function __construct($data, $url, $station, $image) { logger::log("RADIO PLAYLIST", "New M3U Station ".$station); $this->url = $url; $this->station = $station; $this->image = $image; $this->tracks = array(); $prettystream = ''; $this->url_to_add = $url; $this->secondary = null; $parts = explode(PHP_EOL, $data); foreach ($parts as $line) { if (preg_match('/#EXTINF:(.*?),(.*?)$/', $line, $matches)) { $prettystream = $matches[2]; } else if (preg_match('/^\#/', $line) || preg_match('/^\s*$/', $line)) { } else { $this->tracks[] = array('TrackUri' => trim($line), 'PrettyStream' => $prettystream); } } if (preg_match('/opml\.radiotime\.com/', $url)) { logger::mark("RADIO PLAYLIST", "This is a radiotime tune api, Checking returned playlist"); $this->url_to_add = $this->get_first_track(); $this->secondary = download_internet_playlist($this->url_to_add, null, null); $this->tracks = $this->secondary->tracks; } } public function updateDatabase() { $stationid = check_radio_station($this->url, $this->station, $this->image); if ($stationid) { check_radio_tracks($stationid, $this->tracks); } else { logger::error("RADIO", "ERROR! Null station ID!"); header('HTTP/1.1 417 Expectation Failed'); exit(0); } } public function getTracksToAdd() { if ($this->secondary !== null) { return $this->secondary->getTracksToAdd(); } else { return array('load "'.format_for_mpd(htmlspecialchars_decode($this->url_to_add)).'"'); } } public function get_first_track() { $return = $this->tracks[0]['TrackUri']; foreach ($this->tracks as $track) { $ext = pathinfo($track['TrackUri'], PATHINFO_EXTENSION); if ($ext == 'pls' || $ext == 'm3u' || $ext == 'xspf' || $ext == 'asx') { $return = $track['TrackUri']; break; } } logger::log("RADIO_PLAYLIST", " First Track Is ".$return); return $return; } } // [Reference] // Ref1=http://wmlive-lracl.bbc.co.uk/wms/england/lrleicester?MSWMExt=.asf // Ref2=http://212.58.252.33:80/wms/england/lrleicester?MSWMExt=.asf class asfFile { public function __construct($data, $url, $station, $image) { $this->url = $url; $this->station = $station; $this->image = $image; $this->tracks = array(); $parts = explode(PHP_EOL, $data); foreach ($parts as $line) { if (preg_match('/^Ref\d+=(.*)/', $line, $matches)) { $uri = trim($matches[1]); $this->tracks[] = array('TrackUri' => preg_replace('/http:/','mms:', $uri), 'PrettyStream' => ''); } } } public function updateDatabase() { $stationid = check_radio_station($this->url, $this->station, $this->image); if ($stationid) { check_radio_tracks($stationid, $this->tracks); } else { logger::error("RADIO", "ERROR! Null station ID!"); header('HTTP/1.1 417 Expectation Failed'); exit(0); } } public function getTracksToAdd() { return array('load "'.format_for_mpd(htmlspecialchars_decode($this->url)).'"'); } } // Fallback - if it's not any of the above types, treat it as a single stream URL and see what happens. class possibleStreamUrl { public function __construct($url, $station, $image) { $this->url = $url; $this->station = $station; $this->image = $image; $this->tracks = array(array('TrackUri' => $this->url, 'PrettyStream' => '')); } public function updateDatabase() { $stationid = check_radio_station($this->url, $this->station, $this->image); if ($stationid) { check_radio_tracks($stationid, $this->tracks); } else { logger::error("RADIO", "ERROR! Null station ID!"); header('HTTP/1.1 417 Expectation Failed'); exit(0); } } public function getTracksToAdd() { return array('add "'.format_for_mpd(htmlspecialchars_decode($this->url)).'"'); } } function checkStationAgain($currenttitle, $tracktitle) { // For MPD, we can get a station name from the pls file // For Mopidy, we'll let mopidy's scanner find one for us. This is more accurate global $prefs; $currenttitle = (string)$currenttitle; if (preg_match('/'.ROMPR_UNKNOWN_STREAM.'/', $currenttitle) && $prefs['player_backend'] == "mpd") { $a = preg_replace('/\(.*?\)/', '', $tracktitle); if ($a != '') { $currenttitle = $a; } } return $currenttitle; } ?>