From 7d26333ce01f487972d40ba79902e9ec5ae73fa4 Mon Sep 17 00:00:00 2001 From: rickybiscus Date: Sun, 8 Jan 2017 11:11:05 +0100 Subject: [PATCH] WIP : list_indexes function (not working yet) --- lib/libsonic_extra/__init__.py | 10 ++++++++-- main.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/libsonic_extra/__init__.py b/lib/libsonic_extra/__init__.py index 29a45df..eca9231 100644 --- a/lib/libsonic_extra/__init__.py +++ b/lib/libsonic_extra/__init__.py @@ -296,12 +296,12 @@ class SubsonicClient(libsonic.Connection): else: return super(SubsonicClient, self)._doBinReq(*args, **kwargs) - def walk_index(self): + def walk_index(self, folder_id=None): """ Request Subsonic's index and iterate each item. """ - response = self.getIndexes() + response = self.getIndexes(folder_id) for index in response["indexes"]["index"]: for index in index["artist"]: @@ -334,6 +334,12 @@ class SubsonicClient(libsonic.Connection): for child in response["playlist"]["entry"]: yield child + + def walk_folders(self): + response = self.getMusicFolders() + + for child in response["musicFolders"]["musicFolder"]: + yield child def walk_directory(self, directory_id): """ diff --git a/main.py b/main.py index 4c70a10..253a839 100644 --- a/main.py +++ b/main.py @@ -805,6 +805,37 @@ def list_playlists(params): #content = None #string - current plugin content, e.g. ‘movies’ or ‘episodes’. ) +@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): # get connection