Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[script.radioparadise] 2.0.1 #2642

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions script.radioparadise/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v2.0.1

- Use new metadata API

## v2.0.0

- Updates for Kodi v20
Expand Down
4 changes: 2 additions & 2 deletions script.radioparadise/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.radioparadise" name="Radio Paradise" version="2.0.0" provider-name="Alexander Dietrich">
<addon id="script.radioparadise" name="Radio Paradise" version="2.0.1" provider-name="Alexander Dietrich">
<requires>
<import addon="xbmc.python" version="3.0.1"/>
<import addon="script.module.requests" version="2.0.0"/>
Expand All @@ -12,7 +12,7 @@
<summary lang="en_GB">Radio Paradise addon for Kodi</summary>
<description lang="en_GB">An eclectic DJ-mixed blend of rock, indie, electronica, world music, and more. Listener supported &amp; always 100% commercial free.</description>
<website>https://radioparadise.com/</website>
<source>https://github.com/alxndr42/script.radioparadise</source>
<source>https://codeberg.org/alxndr42/script.radioparadise</source>
<license>GPL-3.0-or-later</license>
<platform>all</platform>
<assets>
Expand Down
18 changes: 12 additions & 6 deletions script.radioparadise/resources/lib/radioparadise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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.
"""
Expand All @@ -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:
Expand All @@ -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] = {
Expand All @@ -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)

Expand Down
13 changes: 7 additions & 6 deletions script.radioparadise/resources/lib/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -164,21 +164,21 @@ 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
if song_data is None and song.start_time:
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
Expand All @@ -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}')
Expand Down
Loading