Browse/Library menus (file structure vs ID3 tags)

This commit is contained in:
rickybiscus 2017-01-09 01:02:37 +01:00
parent 3ed7b231cc
commit c6e9cc92e8
6 changed files with 95 additions and 60 deletions

View File

@ -2,6 +2,7 @@
## v2.0.X
Released XXX
* Browse/Library menus (file structure vs ID3 tags)
* Added multilanguage support
## v2.0.5

View File

@ -140,6 +140,7 @@ class SubsonicClient(libsonic.Connection):
def getArtists(self, *args, **kwargs):
"""
(ID3 tags)
Improve the getArtists method. Ensures IDs are integers.
"""
@ -162,6 +163,7 @@ class SubsonicClient(libsonic.Connection):
def getArtist(self, *args, **kwargs):
"""
(ID3 tags)
Improve the getArtist method. Ensures IDs are integers.
"""
@ -209,6 +211,7 @@ class SubsonicClient(libsonic.Connection):
def getAlbum(self, *args, **kwargs):
"""
(ID3 tags)
Improve the getAlbum method. Ensures the IDs are real integers.
"""
@ -304,16 +307,9 @@ class SubsonicClient(libsonic.Connection):
response = self.getIndexes(folder_id)
for index in response["indexes"]["index"]:
for index in index["artist"]:
for item in self.walk_directory(index["id"]):
yield item
for artist in index["artist"]:
yield artist
for child in response["indexes"]["child"]:
if child.get("isDir"):
for child in self.walk_directory(child["id"]):
yield child
else:
yield child
def walk_playlists(self):
"""
@ -367,6 +363,7 @@ class SubsonicClient(libsonic.Connection):
def walk_artists(self):
"""
(ID3 tags)
Request all artists and iterate over each item.
"""
@ -409,7 +406,7 @@ class SubsonicClient(libsonic.Connection):
def walk_album(self, album_id):
"""
Request an alum and iterate over each item.
Request an album and iterate over each item.
"""
response = self.getAlbum(album_id)

125
main.py
View File

@ -81,9 +81,14 @@ def root(params):
listing = []
menus = {
'artists': {
'folders': {
'name': 'Browse',
'callback': 'browse_folders',
'thumb': None
},
'library': {
'name': lang.getLocalizedString(30019),
'callback': 'list_artists',
'callback': 'browse_library',
'thumb': None
},
'albums': {
@ -100,11 +105,6 @@ def root(params):
'name': lang.getLocalizedString(30022),
'callback': 'list_playlists',
'thumb': None
},
'folders': {
'name': 'Browse',
'callback': 'list_folders',
'thumb': None
}
}
@ -131,7 +131,7 @@ def root(params):
#succeeded = True, #if False Kodi wont open a new listing and stays on the current level.
#update_listing = False, #if True, Kodi wont open a sub-listing but refresh the current one.
#cache_to_disk = True, #cache this view to disk.
#sort_methods = None, #he list of integer constants representing virtual folder sort methods.
sort_methods = None, #he list of integer constants representing virtual folder sort methods.
#view_mode = None, #a numeric code for a skin view mode. View mode codes are different in different skins except for 50 (basic listing).
#content = None #string - current plugin content, e.g. movies or episodes.
)
@ -256,7 +256,7 @@ def menu_tracks(params):
@plugin.action()
#@plugin.cached(cachetime) #if cache is enabled, cache data for the following function
def list_artists(params):
def browse_library(params):
# get connection
connection = get_connection()
@ -806,38 +806,7 @@ def list_playlists(params):
)
@plugin.action()
def list_indexes(params):
# get connection
connection = get_connection()
if connection is False:
return
listing = []
# Get items
folder_id = params.get('folder_id')
items = connection.walk_index(folder_id)
plugin.log('list_indexes:')
# Iterate through items
for item in items:
entry = {
'label': item.get('name'),
'url': plugin.get_url(
action= 'list_albums',
artist_id= item.get('id'),
menu_id= params.get('menu_id')
)
}
listing.append(entry)
return plugin.create_listing(
listing
)
@plugin.action()
def list_folders(params):
def browse_folders(params):
# get connection
connection = get_connection()
@ -854,7 +823,7 @@ def list_folders(params):
entry = {
'label': item.get('name'),
'url': plugin.get_url(
action= 'list_indexes',
action= 'browse_indexes',
folder_id= item.get('id'),
menu_id= params.get('menu_id')
@ -863,11 +832,79 @@ def list_folders(params):
listing.append(entry)
if len(listing) == 1:
plugin.log('One single Media Folder found; do return listing from list_indexes()...')
return list_indexes(params)
plugin.log('One single Media Folder found; do return listing from browse_indexes()...')
return browse_indexes(params)
else:
return plugin.create_listing(listing)
@plugin.action()
def browse_indexes(params):
# get connection
connection = get_connection()
if connection is False:
return
listing = []
# Get items
# optional folder ID
folder_id = params.get('folder_id')
items = connection.walk_index(folder_id)
# Iterate through items
for item in items:
entry = {
'label': item.get('name'),
'url': plugin.get_url(
action= 'list_directory',
id= item.get('id'),
menu_id= params.get('menu_id')
)
}
listing.append(entry)
return plugin.create_listing(
listing
)
@plugin.action()
def list_directory(params):
# get connection
connection = get_connection()
if connection is False:
return
listing = []
# Get items
id = params.get('id')
items = connection.walk_directory(id)
# Iterate through items
for item in items:
#is a directory
if (item.get('isDir')==True):
entry = {
'label': item.get('title'),
'url': plugin.get_url(
action= 'list_directory',
id= item.get('id'),
menu_id= params.get('menu_id')
)
}
else:
entry = get_entry_track(item,params)
listing.append(entry)
return plugin.create_listing(
listing
)
def get_entry_playlist(item,params):
image = connection.getCoverArtUrl(item.get('coverArt'))
return {

View File

@ -81,7 +81,7 @@ msgid "Cache datas time"
msgstr ""
msgctxt "#30019"
msgid "Artists"
msgid "Library"
msgstr ""
msgctxt "#30020"

View File

@ -46,7 +46,7 @@ msgstr "Télécharger"
msgctxt "#30009"
msgid "Download folder"
msgstr "Télécharger le répertoire"
msgstr "Répertoire de téléchargement"
msgctxt "#30010"
msgid "Streaming"
@ -81,8 +81,8 @@ msgid "Cache datas time"
msgstr "Durée du cache pour les données"
msgctxt "#30019"
msgid "Artists"
msgstr "Artistes"
msgid "Library"
msgstr "Bibliothèque"
msgctxt "#30020"
msgid "Albums"

View File

@ -81,8 +81,8 @@ msgid "Cache datas time"
msgstr "Speicher Daten Zeit"
msgctxt "#30019"
msgid "Artists"
msgstr "Künstler"
msgid "Library"
msgstr "Bibliothek"
msgctxt "#30020"
msgid "Albums"