From ee1a3bfc599664718487f3c5b5aedc05e2714cf3 Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Sun, 8 Jan 2017 09:36:13 +0100 Subject: [PATCH] make all stations playable --- appinfo/database.xml | 23 +++++----------------- appinfo/info.xml | 2 +- appinfo/routes.php | 9 +++++++++ appinfo/version | 1 - db/stream.php | 6 +----- js/main.js | 45 +++++++++++++++++++++++++++++++++++++++----- 6 files changed, 56 insertions(+), 30 deletions(-) delete mode 100755 appinfo/version diff --git a/appinfo/database.xml b/appinfo/database.xml index f8f8243..78ff613 100755 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -5,33 +5,20 @@ false utf8 - *dbprefix*radio_streams + *dbprefix*radio_stations id integer - 0 true - 1 - 4 + 6 - name + user_id text + 200 + true - 64 - - - url - text - true - 100 - - - image - text - true - 100
diff --git a/appinfo/info.xml b/appinfo/info.xml index 28d00ce..bee0a19 100755 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -3,7 +3,7 @@ radio Radio Listening to your favorite radio stations in Nextcloud - 0.2 + 0.3 MIT Jonas Heinrich diff --git a/appinfo/routes.php b/appinfo/routes.php index eefb4fc..ef20c69 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -10,3 +10,12 @@ $this->create('radio_index', '/') ->actionInclude('radio/index.php'); $this->create('radio_ajax_seturl', 'ajax/seturl.php') ->actionInclude('radio/ajax/seturl.php'); + +return [ + 'resources' => [ + 'station' => ['url' => '/stations'], + ], + 'routes' => [ + ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], + ] +]; diff --git a/appinfo/version b/appinfo/version deleted file mode 100755 index 49d5957..0000000 --- a/appinfo/version +++ /dev/null @@ -1 +0,0 @@ -0.1 diff --git a/db/stream.php b/db/stream.php index d4cd495..067cd88 100644 --- a/db/stream.php +++ b/db/stream.php @@ -7,15 +7,11 @@ use OCP\AppFramework\Db\Entity; class Stream extends Entity implements JsonSerializable { - protected $title; - protected $content; protected $userId; public function jsonSerialize() { return [ - 'name' => $this->name, - 'url' => $this->url, - 'image' => $this->image + 'id' => $this->id ]; } } diff --git a/js/main.js b/js/main.js index 1397d12..f5a82dd 100644 --- a/js/main.js +++ b/js/main.js @@ -1,13 +1,25 @@ $(window).on('load', function(){ $('body').on('click', 'tr', function() { - var sourceUrl = $(this).attr('data-src'); - $("#player").attr("src", sourceUrl); - $('#player').trigger('play'); + var stationid = $(this).attr('data-id'); + play_station(stationid); }); + function play_station(stationid){ + $.ajax({ + method: "GET", + url: "http://www.radio-browser.info/webservice/v2/json/url/"+stationid, + dataType: 'json', + success: function(data){ + var sourceUrl = data['url']; + $("#player").attr("src", sourceUrl); + $('#player').trigger('play'); + return true; + } + }); + }; + function render_result(data){ - $("tbody > tr").remove(); $.each(data, function(i, station) { $('tbody').append('\ \ @@ -26,6 +38,21 @@ $(window).on('load', function(){ }); } + function get_station_ids(){ + return ["89920","44707"] + }; + + function render_stations(station_ids){ + for (stationid in station_ids){ + $.ajax({ + method: "GET", + url: "https://www.radio-browser.info/webservice/json/stations/byid/"+station_ids[stationid], + dataType: 'json', + success: render_result + }); + }; + }; + function radio_query(type, query){ switch (type) { case 0: @@ -50,7 +77,8 @@ $(window).on('load', function(){ }; function switch_menu(type) { - $('#app-navigation').find('li').removeClass("active");; + $('#app-navigation').find('li').removeClass("active"); + $("tbody > tr").remove(); switch (type) { case 0: $('li.nav-files').addClass('active'); @@ -62,11 +90,14 @@ $(window).on('load', function(){ break; case 2: $('li.nav-favorite').addClass('active'); + station_ids = get_station_ids() + render_stations(station_ids) break; } } $('#radiosearch').submit(function() { + $("tbody > tr").remove(); var query = $('#radioquery').val(); radio_query(0, query); }); @@ -79,5 +110,9 @@ $(window).on('load', function(){ switch_menu(1); }); + $('a.nav-icon-favorites').click(function() { + switch_menu(2); + }); + switch_menu(0); });