Skip to content

Commit

Permalink
Fix Community Radio to use new API
Browse files Browse the repository at this point in the history
  • Loading branch information
fatg3erman committed Aug 7, 2020
1 parent 9645606 commit 2fbb67e
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions streamplugins/04_communityradio.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function __construct() {
}

public function doWhatYoureTold() {

$this->server = $this->get_server();

switch ($this->populate) {
case 0:
$this->doHeader();
Expand Down Expand Up @@ -214,7 +217,7 @@ private function doGenreList() {

private function browse() {
directoryControlHeader('commradio_'.md5($this->url), $this->title);
$bits = getCacheData('http://de1.api.radio-browser.info/'.$this->url, 'commradio', true, true);
$bits = getCacheData('https://'.$this->server.'/'.$this->url, 'commradio', true, true);
$bits = json_decode($bits, true);
if ($this->url == 'json/countries') {
$map = 'bycountryexact/';
Expand All @@ -227,7 +230,7 @@ private function browse() {
}

private function doSearch() {
$url = 'http://de1.api.radio-browser.info/json/stations/search?';
$url = 'https://'.$this->server.'/json/stations/search?';
$ourterms = array();
foreach ($this->searchterms as $t) {
if (array_key_exists($t, $_REQUEST) && $_REQUEST[$t] != '') {
Expand Down Expand Up @@ -256,7 +259,8 @@ private function addBits($url) {
}

private function doRequest() {
$url = $this->addBits('http://de1.api.radio-browser.info/json/stations/'.$this->url.'?');
$url = $this->addBits('https://'.$this->server.'/json/stations/'.$this->url.'?');
logger::log('COMMRADIO','Getting',$url);
$stations = getCacheData($url, 'commradio', true, true);
$stations = json_decode($stations, true);
$title = ($this->title) ? rawurldecode($this->title) : get_int_text('label_communityradio');
Expand Down Expand Up @@ -317,10 +321,10 @@ private function doStation($station, $index) {
private function makeSelector($json, $root) {
if (is_array($json)) {
foreach ($json as $thing) {
$val = strtolower($thing['value']);
$val = strtolower($thing['name']);
$opts = array(
'URL' => $root.rawurlencode($val),
'text' => ucfirst($thing['value']).' ('.$thing['stationcount'].' stations)'
'text' => ucfirst($thing['name']).' ('.$thing['stationcount'].' stations)'
);
printRadioDirectory($opts, true, 'commradio');
}
Expand Down Expand Up @@ -407,17 +411,24 @@ private function comm_radio_sanitise_station($station) {
if ($result['bitrate'] == 0) {
$result['bitrate'] = 'Unknown ';
}
// No real idea whay one works for one player but not the other. MPD won't load the M3U files,
// Mopidy won't load the PLS files. All I do is send a load/add and a URL.....
// if ($prefs['player_backend'] == 'mpd') {
// $result['playurl'] = 'http://www.radio-browser.info/webservice/v2/pls/url/'.$station['id'];
// } else {
// $result['playurl'] = 'http://www.radio-browser.info/webservice/v2/m3u/url/'.$station['id'];
//}
$result['playurl'] = $station['url'];
return $result;
}

private function get_server() {
$servers = dns_get_record('all.api.radio-browser.info');
shuffle($servers);
foreach ($servers as $server) {
if (array_key_exists('ip', $server)) {
$name = gethostbyaddr($server['ip']);
logger::log('COMMRADIO', 'Using server',$name);
return $name;
}
}
logger::warn('COMMRADIO', 'Using fallback server!');
return 'de1.api.radio-browser.info';
}

}


Expand Down

0 comments on commit 2fbb67e

Please sign in to comment.