Add internet radio item

This commit is contained in:
warwickh 2023-08-05 15:37:27 +10:00
parent 4fffcd143e
commit d122e8da0c
4 changed files with 64 additions and 0 deletions

52
main.py
View File

@ -111,6 +111,11 @@ def root(params):
'name': Addon().get_localized_string(30045),
'callback': 'search_album',
'thumb': None
},
'radio': {
'name': Addon().get_localized_string(30046),
'callback': 'browse_radio',
'thumb': None
},
}
@ -243,6 +248,31 @@ def menu_tracks(params):
listing,
))
@plugin.action()
def browse_radio(params):
# get connection
connection = get_connection()
if connection==False:
return
listing = []
# Get items
items = walk_radio()
# Iterate through items
for item in items:
print(item)
entry = get_entry_radio(item,params)
listing.append(entry)
add_directory_items(create_listing(
listing,
sort_methods = get_sort_methods('playlists',params), #he list of integer constants representing virtual folder sort methods.
))
@plugin.action()
def browse_folders(params):
# get connection
@ -880,6 +910,17 @@ def get_entry_album(item, params):
return entry
def get_entry_radio(item,params):
menu_id = params.get('menu_id')
entry = {
'label': item.get('name'),
'url': item.get('streamUrl'),
'is_playable': True
}
return entry
def get_entry_track(item,params):
menu_id = params.get('menu_id')
image = connection.getCoverArtUrl(item.get('coverArt'))
@ -1543,6 +1584,17 @@ def walk_tracks_random(size=None, genre=None, fromYear=None,toYear=None):
except KeyError:
yield from ()
def walk_radio():
"""
Request Subsonic's radio stations and iterate over each item.
"""
response = connection.getInternetRadioStations()
try:
for station in response["internetRadioStations"]["internetRadioStation"]:
yield station
except KeyError:
yield from ()
def walk_tracks_starred():
"""
Request Subsonic's starred songs and iterate over each item.

View File

@ -180,3 +180,7 @@ msgstr ""
msgctxt "#30045"
msgid "Search Albums"
msgstr ""
msgctxt "#30046"
msgid "Radio"
msgstr "Radio"

View File

@ -180,3 +180,7 @@ msgstr ""
msgctxt "#30045"
msgid "Search Albums"
msgstr "Rechercher Albums"
msgctxt "#30046"
msgid "Radio"
msgstr "Radio"

View File

@ -179,3 +179,7 @@ msgstr ""
msgctxt "#30045"
msgid "Search Albums"
msgstr "Suche Albums"
msgctxt "#30046"
msgid "Radio"
msgstr "Radio"