Fix browse function
This commit is contained in:
78
main.py
78
main.py
@ -21,7 +21,7 @@ from collections import MutableMapping, namedtuple
|
|||||||
sys.path.append(xbmcvfs.translatePath(os.path.join(xbmcaddon.Addon("plugin.audio.subsonic").getAddonInfo("path"), "lib")))
|
sys.path.append(xbmcvfs.translatePath(os.path.join(xbmcaddon.Addon("plugin.audio.subsonic").getAddonInfo("path"), "lib")))
|
||||||
|
|
||||||
|
|
||||||
import libsonic#Removed libsonic_extra
|
import libsonic#_extra #TO FIX - we should get rid of this and use only libsonic
|
||||||
|
|
||||||
from simpleplugin import Plugin
|
from simpleplugin import Plugin
|
||||||
from simpleplugin import Addon
|
from simpleplugin import Addon
|
||||||
@ -46,19 +46,22 @@ def popup(text, time=5000, image=None):
|
|||||||
def get_connection():
|
def get_connection():
|
||||||
global connection
|
global connection
|
||||||
|
|
||||||
if connection==None:
|
if connection==None:
|
||||||
connected = False
|
|
||||||
|
connected = False
|
||||||
|
|
||||||
# Create connection
|
# Create connection
|
||||||
|
|
||||||
try:
|
try:
|
||||||
connection = libsonic.Connection(
|
connection = libsonic.Connection(
|
||||||
baseUrl=Addon().get_setting('subsonic_url'),
|
baseUrl=Addon().get_setting('subsonic_url'),
|
||||||
username=Addon().get_setting('username', convert=False),
|
username=Addon().get_setting('username', convert=False),
|
||||||
password=Addon().get_setting('password', convert=False),
|
password=Addon().get_setting('password', convert=False),
|
||||||
port=4040,#TO FIX
|
port=4040,
|
||||||
apiVersion=Addon().get_setting('apiversion'),
|
apiVersion=Addon().get_setting('apiversion'),
|
||||||
insecure=Addon().get_setting('insecure') == 'true',
|
insecure=Addon().get_setting('insecure') == 'true',
|
||||||
legacyAuth=Addon().get_setting('legacyauth') == 'true',
|
legacyAuth=Addon().get_setting('legacyauth') == 'true',
|
||||||
useGET=True,#Addon().get_setting('useget') == 'True', #TO FIX
|
useGET=True,#Addon().get_setting('useget') == 'True',
|
||||||
)
|
)
|
||||||
connected = connection.ping()
|
connected = connection.ping()
|
||||||
except:
|
except:
|
||||||
@ -1293,7 +1296,6 @@ def resolve_url(path='', play_item=None, succeeded=True):
|
|||||||
def create_list_item(item):
|
def create_list_item(item):
|
||||||
"""
|
"""
|
||||||
Create an :class:`xbmcgui.ListItem` instance from an item dict
|
Create an :class:`xbmcgui.ListItem` instance from an item dict
|
||||||
|
|
||||||
:param item: a dict of ListItem properties
|
:param item: a dict of ListItem properties
|
||||||
:type item: dict
|
:type item: dict
|
||||||
:return: ListItem instance
|
:return: ListItem instance
|
||||||
@ -1305,30 +1307,23 @@ def create_list_item(item):
|
|||||||
label2=item.get('label2', ''),
|
label2=item.get('label2', ''),
|
||||||
path=item.get('path', ''),
|
path=item.get('path', ''),
|
||||||
offscreen=item.get('offscreen', False))
|
offscreen=item.get('offscreen', False))
|
||||||
else:
|
|
||||||
list_item = xbmcgui.ListItem(label=item.get('label', ''),
|
|
||||||
label2=item.get('label2', ''),
|
art = item.get('art', {})
|
||||||
path=item.get('path', ''))
|
art['thumb'] = item.get('thumb', '')
|
||||||
if major_version >= '16':
|
art['icon'] = item.get('icon', '')
|
||||||
art = item.get('art', {})
|
art['fanart'] = item.get('fanart', '')
|
||||||
art['thumb'] = item.get('thumb', '')
|
item['art'] = art
|
||||||
art['icon'] = item.get('icon', '')
|
cont_look = item.get('content_lookup')
|
||||||
art['fanart'] = item.get('fanart', '')
|
if cont_look is not None:
|
||||||
item['art'] = art
|
list_item.setContentLookup(cont_look)
|
||||||
cont_look = item.get('content_lookup')
|
|
||||||
if cont_look is not None:
|
|
||||||
list_item.setContentLookup(cont_look)
|
|
||||||
else:
|
|
||||||
list_item.setThumbnailImage(item.get('thumb', ''))
|
|
||||||
list_item.setIconImage(item.get('icon', ''))
|
|
||||||
list_item.setProperty('fanart_image', item.get('fanart', ''))
|
|
||||||
if item.get('art'):
|
if item.get('art'):
|
||||||
list_item.setArt(item['art'])
|
list_item.setArt(item['art'])
|
||||||
if item.get('stream_info'):
|
if item.get('stream_info'):
|
||||||
for stream, stream_info in item['stream_info'].iteritems():
|
for stream, stream_info in item['stream_info'].items():
|
||||||
list_item.addStreamInfo(stream, stream_info)
|
list_item.addStreamInfo(stream, stream_info)
|
||||||
if item.get('info'):
|
if item.get('info'):
|
||||||
for media, info in item['info'].iteritems():
|
for media, info in item['info'].items():
|
||||||
list_item.setInfo(media, info)
|
list_item.setInfo(media, info)
|
||||||
if item.get('context_menu') is not None:
|
if item.get('context_menu') is not None:
|
||||||
list_item.addContextMenuItems(item['context_menu'])
|
list_item.addContextMenuItems(item['context_menu'])
|
||||||
@ -1337,7 +1332,7 @@ def create_list_item(item):
|
|||||||
if item.get('mime'):
|
if item.get('mime'):
|
||||||
list_item.setMimeType(item['mime'])
|
list_item.setMimeType(item['mime'])
|
||||||
if item.get('properties'):
|
if item.get('properties'):
|
||||||
for key, value in item['properties'].iteritems():
|
for key, value in item['properties'].items():
|
||||||
list_item.setProperty(key, value)
|
list_item.setProperty(key, value)
|
||||||
if major_version >= '17':
|
if major_version >= '17':
|
||||||
cast = item.get('cast')
|
cast = item.get('cast')
|
||||||
@ -1403,6 +1398,17 @@ def add_directory_items(context):
|
|||||||
if context.view_mode is not None:
|
if context.view_mode is not None:
|
||||||
xbmc.executebuiltin('Container.SetViewMode({0})'.format(context.view_mode))
|
xbmc.executebuiltin('Container.SetViewMode({0})'.format(context.view_mode))
|
||||||
|
|
||||||
|
def walk_index(folder_id=None):
|
||||||
|
"""
|
||||||
|
Request Subsonic's index and iterate each item.
|
||||||
|
"""
|
||||||
|
|
||||||
|
response = connection.getIndexes(folder_id)
|
||||||
|
|
||||||
|
for index in response["indexes"]["index"]:
|
||||||
|
for artist in index["artist"]:
|
||||||
|
yield artist
|
||||||
|
|
||||||
def walk_playlists():
|
def walk_playlists():
|
||||||
"""
|
"""
|
||||||
Request Subsonic's playlists and iterate over each item.
|
Request Subsonic's playlists and iterate over each item.
|
||||||
@ -1423,6 +1429,26 @@ def walk_playlist(playlist_id):
|
|||||||
for child in response["playlist"]["entry"]:
|
for child in response["playlist"]["entry"]:
|
||||||
yield child
|
yield child
|
||||||
|
|
||||||
|
def walk_folders():
|
||||||
|
response = connection.getMusicFolders()
|
||||||
|
|
||||||
|
for child in response["musicFolders"]["musicFolder"]:
|
||||||
|
yield child
|
||||||
|
|
||||||
|
def walk_directory(directory_id):
|
||||||
|
"""
|
||||||
|
Request a Subsonic music directory and iterate over each item.
|
||||||
|
"""
|
||||||
|
|
||||||
|
response = connection.getMusicDirectory(directory_id)
|
||||||
|
|
||||||
|
for child in response["directory"]["child"]:
|
||||||
|
if child.get("isDir"):
|
||||||
|
for child in walk_directory(child["id"]):
|
||||||
|
yield child
|
||||||
|
else:
|
||||||
|
yield child
|
||||||
|
|
||||||
def walk_artist(artist_id):
|
def walk_artist(artist_id):
|
||||||
"""
|
"""
|
||||||
Request a Subsonic artist and iterate over each album.
|
Request a Subsonic artist and iterate over each album.
|
||||||
|
|||||||
Reference in New Issue
Block a user