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

@ -112,6 +112,11 @@ def root(params):
'callback': 'search_album', 'callback': 'search_album',
'thumb': None 'thumb': None
}, },
'radio': {
'name': Addon().get_localized_string(30046),
'callback': 'browse_radio',
'thumb': None
},
} }
# Iterate through categories # Iterate through categories
@ -243,6 +248,31 @@ def menu_tracks(params):
listing, 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() @plugin.action()
def browse_folders(params): def browse_folders(params):
# get connection # get connection
@ -880,6 +910,17 @@ def get_entry_album(item, params):
return entry 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): def get_entry_track(item,params):
menu_id = params.get('menu_id') menu_id = params.get('menu_id')
image = connection.getCoverArtUrl(item.get('coverArt')) image = connection.getCoverArtUrl(item.get('coverArt'))
@ -1543,6 +1584,17 @@ def walk_tracks_random(size=None, genre=None, fromYear=None,toYear=None):
except KeyError: except KeyError:
yield from () 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(): def walk_tracks_starred():
""" """
Request Subsonic's starred songs and iterate over each item. Request Subsonic's starred songs and iterate over each item.

View File

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

View File

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

View File

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