diff --git a/script.radioparadise/CHANGELOG.md b/script.radioparadise/CHANGELOG.md index d336bef27..325139a81 100644 --- a/script.radioparadise/CHANGELOG.md +++ b/script.radioparadise/CHANGELOG.md @@ -1,3 +1,7 @@ +## v2.0.1 + +- Use new metadata API + ## v2.0.0 - Updates for Kodi v20 diff --git a/script.radioparadise/addon.xml b/script.radioparadise/addon.xml index e32e7f783..27f1c05fc 100644 --- a/script.radioparadise/addon.xml +++ b/script.radioparadise/addon.xml @@ -1,5 +1,5 @@ - + @@ -12,7 +12,7 @@ Radio Paradise addon for Kodi An eclectic DJ-mixed blend of rock, indie, electronica, world music, and more. Listener supported & always 100% commercial free. https://radioparadise.com/ - https://github.com/alxndr42/script.radioparadise + https://codeberg.org/alxndr42/script.radioparadise GPL-3.0-or-later all diff --git a/script.radioparadise/resources/lib/radioparadise.py b/script.radioparadise/resources/lib/radioparadise.py index ce5f31df7..bac8883b6 100644 --- a/script.radioparadise/resources/lib/radioparadise.py +++ b/script.radioparadise/resources/lib/radioparadise.py @@ -5,7 +5,7 @@ import requests -NOWPLAYING_URL = 'https://api.radioparadise.com/api/nowplaying_list?chan={}' +NOWPLAYING_URL = 'https://api.radioparadise.com/api/nowplaying_list_v2022?chan={}&list_num=10' COVER_URL = 'https://img.radioparadise.com/{}' SLIDESHOW_URL = 'https://img.radioparadise.com/slideshow/720/{}.jpg' @@ -87,7 +87,7 @@ def set_channel(self, channel): def update(self): """Update song information from the API, if necessary. - Calls the API only if the "refresh" timer has expired. + Calls the API only when the "current" song ends. Raises an exception on error responses or timeouts. """ @@ -105,8 +105,7 @@ def update(self): next_key = None data = res.json() - song_items = sorted(list(data['song'].items()), key=lambda s: int(s[0])) - for index, song in song_items: + for index, song in enumerate(data['song']): if song['artist'] is None: song['artist'] = 'Unknown Artist' if song['title'] is None: @@ -119,7 +118,7 @@ def update(self): key = build_key((song['artist'], song['title'])) self.songs[key] = song next_key = key - if index == '0': + if index == 0: self.current = song if (break_key := build_key(BREAK_SONG)) not in self.songs: self.songs[break_key] = { @@ -128,7 +127,14 @@ def update(self): 'cover': BREAK_COVER_URL, 'duration': '30000', } - self.next_update = time.time() + data['refresh'] + + now = time.time() + next_update = (self.current['play_time'] + int(self.current['duration'])) / 1000 + if next_update > now: + self.next_update = next_update + else: + self.next_update = now + UPDATE_WAIT + while len(self.songs) > MAX_SONGS: self.songs.popitem(last=False) diff --git a/script.radioparadise/resources/lib/service.py b/script.radioparadise/resources/lib/service.py index c96612c39..b456d6e50 100644 --- a/script.radioparadise/resources/lib/service.py +++ b/script.radioparadise/resources/lib/service.py @@ -113,7 +113,7 @@ def update_player(self): tag.setTitle(song.data['title']) tag.setGenres([]) tag.setAlbum(song.data.get('album', '')) - rating = float(song.data.get('rating', 0)) + rating = song.data.get('listener_rating', 0) tag.setRating(rating) tag.setUserRating(int(round(rating))) tag.setYear(int(song.data.get('year', 0))) @@ -164,11 +164,14 @@ def update_song(self): start_time = None song_data = None # Try to match API metadata on song changes - if song and song.key != player_key and not song.expired(): + if song is None: + start_time = 0 + song_data = self.now_playing.get_song_data(player_key) + elif song.key != player_key and not song.expired(): start_time = self.tracked_time song_data = self.now_playing.get_song_data(player_key) # Show "next" song if the song change was missed - elif song and song.expired(): + elif song.expired(): start_time = song.start_time + song.duration song_data = self.now_playing.get_next_song(player_key) # Without API metadata, show the stream metadata @@ -176,9 +179,6 @@ def update_song(self): song.start_time = 0 self.slideshow.set_slides(None) self.clear_player() - # Show "current" song after starting playback - elif song is None: - song_data = self.now_playing.current # API metadata may not be available yet if song_data is None: return @@ -193,6 +193,7 @@ def update_song(self): else: self.slideshow.set_slides(None) fanart = None + song_key = build_key((song_data['artist'], song_data['title'])) self.song = Song(song_key, song_data, fanart, start_time) log(f'Song: {self.song}')