Skip to content

Commit

Permalink
Merge pull request #12 from gordielachance/media-folders
Browse files Browse the repository at this point in the history
Media folders
  • Loading branch information
gordielachance authored Jan 14, 2017
2 parents 0cda25e + e6b00af commit 10bb432
Show file tree
Hide file tree
Showing 10 changed files with 575 additions and 412 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Changelog

## v2.0.X
Released XXX
## v2.0.6
Released 14 January 2017
* Upgrade to simpleplugin 2.1.0
* Browse/Library menus (file structure vs ID3 tags)
* Added multilanguage support

## v2.0.5
Expand Down
2 changes: 1 addition & 1 deletion 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="plugin.audio.subsonic" name="Subsonic" version="2.0.5" provider-name="BasilFX,grosbouff">
<addon id="plugin.audio.subsonic" name="Subsonic" version="2.0.6" provider-name="BasilFX,grosbouff">
<requires>
<import addon="xbmc.python" version="2.14.0"/>
<import addon="script.module.dateutil" version="2.4.2"/>
Expand Down
30 changes: 18 additions & 12 deletions lib/libsonic_extra/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def _entries_iterator(entries):

def getArtists(self, *args, **kwargs):
"""
(ID3 tags)
Improve the getArtists method. Ensures IDs are integers.
"""

Expand All @@ -162,6 +163,7 @@ def _index_iterator(index):

def getArtist(self, *args, **kwargs):
"""
(ID3 tags)
Improve the getArtist method. Ensures IDs are integers.
"""

Expand Down Expand Up @@ -209,6 +211,7 @@ def _children_iterator(children):

def getAlbum(self, *args, **kwargs):
"""
(ID3 tags)
Improve the getAlbum method. Ensures the IDs are real integers.
"""

Expand Down Expand Up @@ -296,24 +299,17 @@ def _doBinReq(self, *args, **kwargs):
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"]:
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):
"""
Expand All @@ -334,6 +330,12 @@ def walk_playlist(self, playlist_id):

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):
"""
Expand Down Expand Up @@ -361,6 +363,7 @@ def walk_artist(self, artist_id):

def walk_artists(self):
"""
(ID3 tags)
Request all artists and iterate over each item.
"""

Expand All @@ -372,6 +375,7 @@ def walk_artists(self):

def walk_genres(self):
"""
(ID3 tags)
Request all genres and iterate over each item.
"""

Expand All @@ -382,6 +386,7 @@ def walk_genres(self):

def walk_albums(self, ltype, size=None, fromYear=None,toYear=None, genre=None, offset=None):
"""
(ID3 tags)
Request all albums for a given genre and iterate over each album.
"""

Expand All @@ -403,7 +408,8 @@ def walk_albums(self, ltype, size=None, fromYear=None,toYear=None, genre=None, o

def walk_album(self, album_id):
"""
Request an alum and iterate over each item.
(ID3 tags)
Request an album and iterate over each item.
"""

response = self.getAlbum(album_id)
Expand Down
2 changes: 1 addition & 1 deletion lib/simpleplugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#v2.0.1
#v2.1.0
#https://github.com/romanvm/script.module.simpleplugin/releases

from simpleplugin import *
22 changes: 15 additions & 7 deletions lib/simpleplugin/simpleplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,24 @@ def config_dir(self):
"""
return self._configdir

@property
def version(self):
"""
Addon version
:return: addon version
:rtype: str
"""
return self._addon.getAddonInfo('version')

def get_localized_string(self, id_):
"""
Get localized UI string
:param id_: UI string ID
:type id_: int
:return: UI string in the current language
:rtype: unicode
:rtype: str
"""
return self._addon.getLocalizedString(id_).encode('utf-8')

Expand Down Expand Up @@ -327,7 +337,7 @@ def set_setting(self, id_, value):
value = str(value)
self._addon.setSetting(id_, value)

def log(self, message, level=0):
def log(self, message, level=xbmc.LOGDEBUG):
"""
Add message to Kodi log starting with Addon ID
Expand All @@ -339,7 +349,7 @@ def log(self, message, level=0):
"""
if isinstance(message, unicode):
message = message.encode('utf-8')
xbmc.log('{0}: {1}'.format(self.id, message), level)
xbmc.log('{0} [v.{1}]: {2}'.format(self.id, self.version, message), level)

def log_notice(self, message):
"""
Expand Down Expand Up @@ -879,7 +889,6 @@ def _add_directory_items(self, context):
self.log_debug('Creating listing from {0}'.format(str(context)))
if context.content is not None:
xbmcplugin.setContent(self._handle, context.content) # This must be at the beginning
listing = []
for item in context.listing:
is_folder = item.get('is_folder', True)
if item.get('list_item') is not None:
Expand All @@ -889,8 +898,7 @@ def _add_directory_items(self, context):
if item.get('is_playable'):
list_item.setProperty('IsPlayable', 'true')
is_folder = False
listing.append((item['url'], list_item, is_folder))
xbmcplugin.addDirectoryItems(self._handle, listing, len(listing))
xbmcplugin.addDirectoryItem(self._handle, item['url'], list_item, is_folder)
if context.sort_methods is not None:
[xbmcplugin.addSortMethod(self._handle, method) for method in context.sort_methods]
xbmcplugin.endOfDirectory(self._handle,
Expand All @@ -912,4 +920,4 @@ def _set_resolved_url(self, context):
list_item = xbmcgui.ListItem(path=context.path)
else:
list_item = self.create_list_item(context.play_item)
xbmcplugin.setResolvedUrl(self._handle, context.succeeded, list_item)
xbmcplugin.setResolvedUrl(self._handle, context.succeeded, list_item)
Loading

0 comments on commit 10bb432

Please sign in to comment.