diff --git a/addon.xml b/addon.xml index bce25b5..05ba157 100644 --- a/addon.xml +++ b/addon.xml @@ -1,13 +1,14 @@ - - - - - - - audio - + + + + + + + audio + + Subsonic music addon for Kodi. Extension Subsonic pour Kodi. diff --git a/lib/libsonic/connection.py b/lib/libsonic/connection.py index ff7b22a..07ab583 100644 --- a/lib/libsonic/connection.py +++ b/lib/libsonic/connection.py @@ -230,9 +230,11 @@ class Connection(object): viewName = '%s.view' % methodName req = self._getRequest(viewName) + xbmc.log("Pinging %s"%str(req.full_url),xbmc.LOGDEBUG) try: res = self._doInfoReq(req) - except: + except Exception as e: + print("Ping failed %s"%e) return False if res['status'] == 'ok': return True diff --git a/resources/language/English/strings.po b/resources/language/English/strings.po index a176b9c..cf0e1e6 100644 --- a/resources/language/English/strings.po +++ b/resources/language/English/strings.po @@ -173,3 +173,6 @@ msgctxt "#30043" msgid "Merge album folders" msgstr "" +msgctxt "#30044" +msgid "Scrobble to Last.FM" +msgstr "" diff --git a/resources/language/French/strings.po b/resources/language/French/strings.po index fbbdd11..88f7515 100644 --- a/resources/language/French/strings.po +++ b/resources/language/French/strings.po @@ -172,3 +172,7 @@ msgstr "" msgctxt "#30043" msgid "Merge album folders" msgstr "" + +msgctxt "#30044" +msgid "Scrobble to Last.FM" +msgstr "" diff --git a/resources/language/German/strings.po b/resources/language/German/strings.po index 2a0bdd6..46ba647 100644 --- a/resources/language/German/strings.po +++ b/resources/language/German/strings.po @@ -171,3 +171,7 @@ msgstr "" msgctxt "#30043" msgid "Merge album folders" msgstr "" + +msgctxt "#30044" +msgid "Scrobble to Last.FM" +msgstr "" diff --git a/resources/settings.xml b/resources/settings.xml index bd921f0..0f09285 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -27,6 +27,7 @@ + diff --git a/service.py b/service.py new file mode 100644 index 0000000..a321a3f --- /dev/null +++ b/service.py @@ -0,0 +1,86 @@ +import re +import xbmc +import xbmcvfs +import os +import xbmcaddon +# Add the /lib folder to sys +sys.path.append(xbmcvfs.translatePath(os.path.join(xbmcaddon.Addon("plugin.audio.subsonic").getAddonInfo("path"), "lib"))) + +import libsonic + +from simpleplugin import Plugin +from simpleplugin import Addon + +# Create plugin instance +plugin = Plugin() +connection = None + +scrobbled = False + +def get_connection(): + global connection + + if connection==None: + connected = False + # Create connection + try: + connection = libsonic.Connection( + baseUrl=Addon().get_setting('subsonic_url'), + username=Addon().get_setting('username', convert=False), + password=Addon().get_setting('password', convert=False), + port=Addon().get_setting('port'), + apiVersion=Addon().get_setting('apiversion'), + insecure=Addon().get_setting('insecure'), + legacyAuth=Addon().get_setting('legacyauth'), + useGET=Addon().get_setting('useget'), + ) + connected = connection.ping() + except: + pass + + if connected==False: + popup('Connection error') + return False + + return connection + +def scrobble_track(track_id): + connection = get_connection() + + if connection==False: + return + res = connection.scrobble(track_id) + xbmc.log("response %s"%(scrobble), xbmc.LOGINFO) + if res['status'] == 'ok': + return True + else: + return False + +if __name__ == '__main__': + monitor = xbmc.Monitor() + + while not monitor.abortRequested(): + if monitor.waitForAbort(10): + break + if (xbmc.getCondVisibility("Player.HasMedia")): + try: + if(Addon().get_setting('scrobble')): + currentFileName = xbmc.getInfoLabel("Player.Filenameandpath") + currentFileProgress = xbmc.getInfoLabel("Player.Progress") + pattern = re.compile(r'plugin:\/\/plugin\.audio\.subsonic\/\?action=play_track&id=(.*?)&') + currentTrackId = re.findall(pattern, currentFileName)[0] + #xbmc.log("Name %s Id %s Progress %s"%(currentFileName,currentTrackId,currentFileProgress), xbmc.LOGDEBUG) + if (int(currentFileProgress)<50): + scrobbled = False + elif (int(currentFileProgress)>=50 and scrobbled == False): + xbmc.log("Scrobbling Track Id %s"%(currentTrackId), xbmc.LOGDEBUG) + scrobble_track(currentTrackId) + scrobbled = True + else: + pass + except Exception as e: + xbmc.log("Script failed %e"%e, xbmc.LOGINFO) + else: + pass + #xbmc.log("Playing stopped", xbmc.LOGINFO) +