Clean up main.py
This commit is contained in:
parent
1703d433a3
commit
2efa209227
142
main.py
142
main.py
|
@ -1276,22 +1276,22 @@ def create_listing(listing, succeeded=True, update_listing=False, cache_to_disk=
|
||||||
|
|
||||||
|
|
||||||
def resolve_url(path='', play_item=None, succeeded=True):
|
def resolve_url(path='', play_item=None, succeeded=True):
|
||||||
"""
|
"""
|
||||||
Create and return a context dict to resolve a playable URL
|
Create and return a context dict to resolve a playable URL
|
||||||
:param path: the path to a playable media.
|
:param path: the path to a playable media.
|
||||||
:type path: str or unicode
|
:type path: str or unicode
|
||||||
:param play_item: a dict of item properties as described in the class docstring.
|
:param play_item: a dict of item properties as described in the class docstring.
|
||||||
It allows to set additional properties for the item being played, like graphics, metadata etc.
|
It allows to set additional properties for the item being played, like graphics, metadata etc.
|
||||||
if ``play_item`` parameter==present, then ``path`` value==ignored, and the path must be set via
|
if ``play_item`` parameter==present, then ``path`` value==ignored, and the path must be set via
|
||||||
``'path'`` property of a ``play_item`` dict.
|
``'path'`` property of a ``play_item`` dict.
|
||||||
:type play_item: dict
|
:type play_item: dict
|
||||||
:param succeeded: if ``False``, Kodi won't play anything
|
:param succeeded: if ``False``, Kodi won't play anything
|
||||||
:type succeeded: bool
|
:type succeeded: bool
|
||||||
:return: context object containing necessary parameters
|
:return: context object containing necessary parameters
|
||||||
for Kodi to play the selected media.
|
for Kodi to play the selected media.
|
||||||
:rtype: PlayContext
|
:rtype: PlayContext
|
||||||
"""
|
"""
|
||||||
return PlayContext(path, play_item, succeeded)
|
return PlayContext(path, play_item, succeeded)
|
||||||
|
|
||||||
#@plugin.cached(cachetime) #cache (in minutes)
|
#@plugin.cached(cachetime) #cache (in minutes)
|
||||||
def create_list_item(item):
|
def create_list_item(item):
|
||||||
|
@ -1360,44 +1360,44 @@ def _set_resolved_url(context):
|
||||||
|
|
||||||
#@plugin.cached(cachetime) #cache (in minutes)
|
#@plugin.cached(cachetime) #cache (in minutes)
|
||||||
def add_directory_items(context):
|
def add_directory_items(context):
|
||||||
plugin.log_debug('Creating listing from {0}'.format(str(context)))
|
plugin.log_debug('Creating listing from {0}'.format(str(context)))
|
||||||
if context.category is not None:
|
if context.category is not None:
|
||||||
xbmcplugin.setPluginCategory(plugin.handle, context.category)
|
xbmcplugin.setPluginCategory(plugin.handle, context.category)
|
||||||
if context.content is not None:
|
if context.content is not None:
|
||||||
xbmcplugin.setContent(plugin.handle, context.content) # This must be at the beginning
|
xbmcplugin.setContent(plugin.handle, context.content) # This must be at the beginning
|
||||||
for item in context.listing:
|
for item in context.listing:
|
||||||
is_folder = item.get('is_folder', True)
|
is_folder = item.get('is_folder', True)
|
||||||
if item.get('list_item') is not None:
|
if item.get('list_item') is not None:
|
||||||
list_item = item['list_item']
|
list_item = item['list_item']
|
||||||
else:
|
else:
|
||||||
list_item = create_list_item(item)
|
list_item = create_list_item(item)
|
||||||
if item.get('is_playable'):
|
if item.get('is_playable'):
|
||||||
list_item.setProperty('IsPlayable', 'true')
|
list_item.setProperty('IsPlayable', 'true')
|
||||||
is_folder = False
|
is_folder = False
|
||||||
xbmcplugin.addDirectoryItem(plugin.handle, item['url'], list_item, is_folder)
|
xbmcplugin.addDirectoryItem(plugin.handle, item['url'], list_item, is_folder)
|
||||||
if context.sort_methods is not None:
|
if context.sort_methods is not None:
|
||||||
if isinstance(context.sort_methods, (int, dict)):
|
if isinstance(context.sort_methods, (int, dict)):
|
||||||
sort_methods = [context.sort_methods]
|
sort_methods = [context.sort_methods]
|
||||||
elif isinstance(context.sort_methods, (tuple, list)):
|
elif isinstance(context.sort_methods, (tuple, list)):
|
||||||
sort_methods = context.sort_methods
|
sort_methods = context.sort_methods
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
'sort_methods parameter must be of int, dict, tuple or list type!')
|
||||||
|
for method in sort_methods:
|
||||||
|
if isinstance(method, int):
|
||||||
|
xbmcplugin.addSortMethod(plugin.handle, method)
|
||||||
|
elif isinstance(method, dict):
|
||||||
|
xbmcplugin.addSortMethod(plugin.handle, **method)
|
||||||
else:
|
else:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
'sort_methods parameter must be of int, dict, tuple or list type!')
|
'method parameter must be of int or dict type!')
|
||||||
for method in sort_methods:
|
|
||||||
if isinstance(method, int):
|
xbmcplugin.endOfDirectory(plugin.handle,
|
||||||
xbmcplugin.addSortMethod(plugin.handle, method)
|
context.succeeded,
|
||||||
elif isinstance(method, dict):
|
context.update_listing,
|
||||||
xbmcplugin.addSortMethod(plugin.handle, **method)
|
context.cache_to_disk)
|
||||||
else:
|
if context.view_mode is not None:
|
||||||
raise TypeError(
|
xbmc.executebuiltin('Container.SetViewMode({0})'.format(context.view_mode))
|
||||||
'method parameter must be of int or dict type!')
|
|
||||||
|
|
||||||
xbmcplugin.endOfDirectory(plugin.handle,
|
|
||||||
context.succeeded,
|
|
||||||
context.update_listing,
|
|
||||||
context.cache_to_disk)
|
|
||||||
if context.view_mode is not None:
|
|
||||||
xbmc.executebuiltin('Container.SetViewMode({0})'.format(context.view_mode))
|
|
||||||
|
|
||||||
def walk_index(folder_id=None):
|
def walk_index(folder_id=None):
|
||||||
"""
|
"""
|
||||||
|
@ -1411,24 +1411,24 @@ def walk_index(folder_id=None):
|
||||||
yield 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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
response = connection.getPlaylists()
|
response = connection.getPlaylists()
|
||||||
|
|
||||||
for child in response["playlists"]["playlist"]:
|
for child in response["playlists"]["playlist"]:
|
||||||
yield child
|
yield child
|
||||||
|
|
||||||
|
|
||||||
def walk_playlist(playlist_id):
|
def walk_playlist(playlist_id):
|
||||||
"""
|
"""
|
||||||
Request Subsonic's playlist items and iterate over each item.
|
Request Subsonic's playlist items and iterate over each item.
|
||||||
"""
|
"""
|
||||||
response = connection.getPlaylist(playlist_id)
|
response = connection.getPlaylist(playlist_id)
|
||||||
|
|
||||||
for child in response["playlist"]["entry"]:
|
for child in response["playlist"]["entry"]:
|
||||||
yield child
|
yield child
|
||||||
|
|
||||||
def walk_folders():
|
def walk_folders():
|
||||||
response = connection.getMusicFolders()
|
response = connection.getMusicFolders()
|
||||||
|
@ -1440,10 +1440,8 @@ def walk_directory(directory_id):
|
||||||
"""
|
"""
|
||||||
Request a Subsonic music directory and iterate over each item.
|
Request a Subsonic music directory and iterate over each item.
|
||||||
"""
|
"""
|
||||||
#directory_id = 16906
|
|
||||||
response = connection.getMusicDirectory(directory_id)
|
response = connection.getMusicDirectory(directory_id)
|
||||||
xbmc.log(directory_id,xbmc.LOGINFO)
|
|
||||||
#xbmc.log(str(response),xbmc.LOGINFO)
|
|
||||||
try:
|
try:
|
||||||
for child in response["directory"]["child"]:
|
for child in response["directory"]["child"]:
|
||||||
if child.get("isDir"):
|
if child.get("isDir"):
|
||||||
|
@ -1548,13 +1546,3 @@ if __name__ == "__main__":
|
||||||
# Map actions
|
# Map actions
|
||||||
# Note that we map callable objects without brackets ()
|
# Note that we map callable objects without brackets ()
|
||||||
plugin.run()
|
plugin.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue