Skip to content

Commit

Permalink
Cleanup and prepare for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
warwickh committed Sep 2, 2021
1 parent a551df5 commit 358df44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 67 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Subsonic
Kodi plugin to stream, star and download music from Subsonic.
Kodi plugin to stream, star and download music from Subsonic/Airsonic/Navidrome (requires Subsonic API compatibility)

For feature requests / issues:
https://github.com/warwickh/plugin.audio.subsonic/issues
Expand Down Expand Up @@ -27,7 +27,7 @@ or
* Clone this repository: `git clone https://github.com/warwickh/plugin.audio.subsonic.git`
* (Re)start Kodi.

Note: You may need to install dependencies manually if installing this way
Note: You may need to install dependencies manually if installing this way. I recommend installing from zip first, then updating using git clone

## TODO
* Scrobble to Last.FM (http://forum.kodi.tv/showthread.php?tid=195597&pid=2429362#pid2429362)
Expand Down
70 changes: 5 additions & 65 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Module: main
# Author: G.Breant
# Created on: 14 January 2017
# License: GPL v.3 https://www.gnu.org/copyleft/gpl.html

import xbmcvfs
import os
import xbmcaddon
Expand All @@ -22,23 +17,18 @@
# Add the /lib folder to sys
sys.path.append(xbmcvfs.translatePath(os.path.join(xbmcaddon.Addon("plugin.audio.subsonic").getAddonInfo("path"), "lib")))


import libsonic#Removed libsonic_extra
import libsonic

from simpleplugin import Plugin
from simpleplugin import Addon

# Create plugin instance
plugin = Plugin()

# initialize_gettext
#_ = plugin.initialize_gettext()

connection = None
cachetime = int(Addon().get_setting('cachetime'))

local_starred = set({})
plugin.log("This is where the local_stars are cleared")
ListContext = namedtuple('ListContext', ['listing', 'succeeded','update_listing', 'cache_to_disk','sort_methods', 'view_mode','content', 'category'])
PlayContext = namedtuple('PlayContext', ['path', 'play_item', 'succeeded'])
def popup(text, time=5000, image=None):
Expand Down Expand Up @@ -138,12 +128,7 @@ def root(params):

add_directory_items(create_listing(
listing,
#succeeded = True, #if False Kodi won’t open a new listing and stays on the current level.
#update_listing = False, #if True, Kodi won’t 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.
#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’.
sort_methods = None,
))

@plugin.action()
Expand Down Expand Up @@ -180,7 +165,7 @@ def menu_albums(params):
}
}

# Iterate through categories
# Iterate through albums

for menu_id in menus:

Expand All @@ -204,12 +189,6 @@ def menu_albums(params):

add_directory_items(create_listing(
listing,
#succeeded = True, #if False Kodi won’t open a new listing and stays on the current level.
#update_listing = False, #if True, Kodi won’t 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.
#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’.
))

@plugin.action()
Expand Down Expand Up @@ -256,12 +235,6 @@ def menu_tracks(params):

add_directory_items(create_listing(
listing,
#succeeded = True, #if False Kodi won’t open a new listing and stays on the current level.
#update_listing = False, #if True, Kodi won’t 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.
#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’.
))

@plugin.action()
Expand Down Expand Up @@ -298,7 +271,6 @@ def browse_folders(params):
add_directory_items(create_listing(listing))

@plugin.action()
#@plugin.cached(cachetime) # cache (in minutes)
def browse_indexes(params):
# get connection
connection = get_connection()
Expand Down Expand Up @@ -330,7 +302,6 @@ def browse_indexes(params):
))

@plugin.action()
#@plugin.cached(cachetime) # cache (in minutes)
def list_directory(params):
# get connection
connection = get_connection()
Expand Down Expand Up @@ -368,7 +339,6 @@ def list_directory(params):
))

@plugin.action()
#@plugin.cached(cachetime) # cache (in minutes)
def browse_library(params):
"""
List artists from the library (ID3 tags)
Expand Down Expand Up @@ -403,11 +373,8 @@ def browse_library(params):

add_directory_items(create_listing(
listing,
#succeeded = True, #if False Kodi won’t open a new listing and stays on the current level.
#update_listing = False, #if True, Kodi won’t open a sub-listing but refresh the current one.
cache_to_disk = True, #cache this view to disk.
sort_methods = get_sort_methods('artists',params), #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 = 'artists' #string - current plugin content, e.g. ‘movies’ or ‘episodes’.
))

Expand Down Expand Up @@ -480,11 +447,8 @@ def list_albums(params):

add_directory_items(create_listing(
listing,
#succeeded = True, #if False Kodi won’t open a new listing and stays on the current level.
#update_listing = False, #if True, Kodi won’t open a sub-listing but refresh the current one.
cache_to_disk = True, #cache this view to disk.
sort_methods = get_sort_methods('albums',params),
#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 = 'albums' #string - current plugin content, e.g. ‘movies’ or ‘episodes’.
))

Expand Down Expand Up @@ -579,24 +543,18 @@ def list_tracks(params):
#link_next = navigate_next(params)
#listing.append(link_next)



add_directory_items(create_listing(
listing,
#succeeded = True, #if False Kodi won’t open a new listing and stays on the current level.
#update_listing = False, #if True, Kodi won’t open a sub-listing but refresh the current one.
#cache_to_disk = True, #cache this view to disk.
sort_methods= get_sort_methods('tracks',params),
#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 = 'songs' #string - current plugin content, e.g. ‘movies’ or ‘episodes’.
))

#stars (persistent) cache==used to know what context action (star/unstar) we should display.
#run this function every time we get starred items.
#ids can be a single ID or a list
#using a set makes sure that IDs will be unique.

@plugin.action()
#@plugin.cached(cachetime) #cache (in minutes)
def list_playlists(params):

# get connection
Expand All @@ -618,12 +576,7 @@ def list_playlists(params):

add_directory_items(create_listing(
listing,
#succeeded = True, #if False Kodi won’t open a new listing and stays on the current level.
#update_listing = False, #if True, Kodi won’t open a sub-listing but refresh the current one.
#cache_to_disk = True, #cache this view to disk.
sort_methods = get_sort_methods('playlists',params), #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’.
))
@plugin.action()
#@plugin.cached(cachetime) #cache (in minutes)
Expand Down Expand Up @@ -875,7 +828,6 @@ def get_entry_album(item, params):

return entry

#@plugin.cached(cachetime) #cache (in minutes)
def get_entry_track(item,params):

menu_id = params.get('menu_id')
Expand Down Expand Up @@ -923,24 +875,19 @@ def get_entry_track(item,params):

return entry

#@plugin.cached(cachetime) #cache (in minutes)
def get_starred_label(id,label):
if is_starred(id):
label = '[COLOR=FF00FF00]%s[/COLOR]' % label
return label

def is_starred(id):
starred = stars_cache_get()
#plugin.log(starred)
#plugin.log("id in starred %s %s"%(id,id in starred))
#plugin.log("int(id) in starred %s %s"%(id, int(id) in starred))
#id = int(id)
if id in starred:
return True
else:
return False

#@plugin.cached(cachetime) #cache (in minutes)
def get_entry_track_label(item,hide_artist = False):
if hide_artist:
label = item.get('title', '<Unknown>')
Expand All @@ -952,7 +899,6 @@ def get_entry_track_label(item,hide_artist = False):

return get_starred_label(item.get('id'),label)

#@plugin.cached(cachetime) #cache (in minutes)
def get_entry_album_label(item,hide_artist = False):
if hide_artist:
label = item.get('name', '<Unknown>')
Expand All @@ -961,7 +907,6 @@ def get_entry_album_label(item,hide_artist = False):
item.get('name', '<Unknown>'))
return get_starred_label(item.get('id'),label)

#@plugin.cached(cachetime) #cache (in minutes)
def get_sort_methods(type,params):
#sort method for list types
#https://github.com/xbmc/xbmc/blob/master/xbmc/SortFileItem.h
Expand Down Expand Up @@ -1065,10 +1010,9 @@ def cache_refresh(forced=False):
#plugin.log("cache_refresh returning %s items"%len(local_starred))
return

def stars_cache_get(): #Retrieving stars from cache is too slow, so load to local variable
def stars_cache_get():
global local_starred
cache_refresh()
#plugin.log("stars_cache_get returning %s items"%len(local_starred))
return local_starred

def navigate_next(params):
Expand Down Expand Up @@ -1277,11 +1221,9 @@ def download_album(id):

download_tracks(ids)

#@plugin.cached(cachetime) #cache (in minutes)
def create_listing(listing, succeeded=True, update_listing=False, cache_to_disk=False, sort_methods=None,view_mode=None, content=None, category=None):
return ListContext(listing, succeeded, update_listing, cache_to_disk,sort_methods, view_mode, content, category)


def resolve_url(path='', play_item=None, succeeded=True):
"""
Create and return a context dict to resolve a playable URL
Expand All @@ -1300,7 +1242,6 @@ def resolve_url(path='', play_item=None, succeeded=True):
"""
return PlayContext(path, play_item, succeeded)

#@plugin.cached(cachetime) #cache (in minutes)
def create_list_item(item):
"""
Create an :class:`xbmcgui.ListItem` instance from an item dict
Expand Down Expand Up @@ -1365,7 +1306,6 @@ def _set_resolved_url(context):
xbmcplugin.setResolvedUrl(plugin.handle, context.succeeded, list_item)


#@plugin.cached(cachetime) #cache (in minutes)
def add_directory_items(context):
plugin.log_debug('Creating listing from {0}'.format(str(context)))
if context.category is not None:
Expand Down

0 comments on commit 358df44

Please sign in to comment.