Skip to content

Commit 17d8dd1

Browse files
committed
[plugin.audio.ampache@matrix] 3.2.4+matrix.1
1 parent 1b15c18 commit 17d8dd1

File tree

5 files changed

+85
-43
lines changed

5 files changed

+85
-43
lines changed

plugin.audio.ampache/addon.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<addon id="plugin.audio.ampache" version="3.2.3+matrix.1" name="Ampache" provider-name="lusum">
2+
<addon id="plugin.audio.ampache" version="3.2.4+matrix.1" name="Ampache" provider-name="lusum">
33
<requires>
44
<import addon="script.module.future" version="1.0.0"/>
55
<import addon="xbmc.python" version="3.0.0"/>

plugin.audio.ampache/resources/lib/ampache_connect.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def getCodeMessError(self,tree):
100100
return errormess
101101

102102
def getHashedPassword(self,timeStamp):
103+
if self._connectionData is None:
104+
raise self.ConnectionError
103105
enablePass = self._connectionData["enable_password"]
104106
if enablePass:
105107
sdf = self._connectionData["password"]
@@ -117,6 +119,8 @@ def getHashedPassword(self,timeStamp):
117119
return passwordHash
118120

119121
def get_user_pwd_login_url(self,nTime):
122+
if self._connectionData is None:
123+
raise self.ConnectionError
120124
myTimeStamp = str(nTime)
121125
myPassphrase = self.getHashedPassword(myTimeStamp)
122126
myURL = self._connectionData["url"] + self.getBaseUrl() + '?action=handshake&auth='
@@ -125,6 +129,8 @@ def get_user_pwd_login_url(self,nTime):
125129
return myURL
126130

127131
def get_auth_key_login_url(self):
132+
if self._connectionData is None:
133+
raise self.ConnectionError
128134
myURL = self._connectionData["url"] + self.getBaseUrl() + '?action=handshake&auth='
129135
myURL += self._connectionData["api_key"]
130136
myURL += '&version=' + self.version
@@ -169,6 +175,8 @@ def handle_request(self,url):
169175
return headers,contents
170176

171177
def AMPACHECONNECT(self,showok=False):
178+
if self._connectionData is None:
179+
raise self.ConnectionError
172180
socket.setdefaulttimeout(3600)
173181
nTime = int(time.time())
174182
use_api_key = self._connectionData["use_api_key"]
@@ -244,6 +252,8 @@ def ampache_http_request(self,action):
244252
return tree
245253

246254
def build_ampache_url(self,action):
255+
if self._connectionData is None:
256+
raise self.ConnectionError
247257
token = self._ampache.getSetting("token")
248258
thisURL = self._connectionData["url"] + self.getBaseUrl() + '?action=' + action
249259
thisURL += '&auth=' + token
Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import xbmc
22
import xbmcaddon
33

4-
#service class
4+
# service class
55
ampache = xbmcaddon.Addon("plugin.audio.ampache")
66

77
from resources.lib.utils import get_objectId_from_fileURL
88

9-
class AmpacheMonitor( xbmc.Monitor ):
9+
10+
class AmpacheMonitor(xbmc.Monitor):
1011
# Monitor for Ampache service events
1112

1213
onPlay = False
1314

1415
def __init__(self):
15-
xbmc.log( 'AmpacheMonitor::ServiceMonitor called', xbmc.LOGDEBUG)
16+
xbmc.log("AmpacheMonitor::ServiceMonitor called", xbmc.LOGDEBUG)
1617

1718
# start mainloop
1819
def run(self):
@@ -25,35 +26,51 @@ def close(self):
2526
pass
2627

2728
def onNotification(self, sender, method, data):
28-
xbmc.log('AmpacheMonitor::onNotification called - method: %s, sender: %s' % (method, sender), xbmc.LOGDEBUG)
29+
xbmc.log(
30+
"AmpacheMonitor::onNotification called - method: %s, sender: %s"
31+
% (method, sender),
32+
xbmc.LOGDEBUG,
33+
)
2934

3035
if not sender or not method or not data:
3136
xbmc.log("AmpacheMonitor::Invalid notification data", xbmc.LOGWARNING)
3237
return
3338

34-
#a little hack to avoid calling rate every time a song start
35-
if method == 'Player.OnStop':
39+
# a little hack to avoid calling rate every time a song start
40+
if method == "Player.OnStop":
3641
self.onPlay = False
3742
xbmc.log("AmpacheMonitor::onPlay status changed to False", xbmc.LOGDEBUG)
38-
elif method == 'Player.OnPlay':
43+
elif method == "Player.OnPlay":
3944
self.onPlay = True
4045
xbmc.log("AmpacheMonitor::onPlay status changed to True", xbmc.LOGDEBUG)
41-
elif method == 'Info.OnChanged' and self.onPlay:
46+
elif method == "Info.OnChanged" and self.onPlay:
4247
if xbmc.Player().isPlaying():
4348
try:
4449
file_url = xbmc.Player().getPlayingFile()
4550
if not file_url:
46-
raise ValueError("No playing file")
51+
xbmc.log(
52+
"AmpacheMonitor::No playing file, skipping", xbmc.LOGDEBUG
53+
)
54+
return
4755

4856
if not get_objectId_from_fileURL(file_url):
49-
raise ValueError("No object ID found in URL")
57+
xbmc.log(
58+
"AmpacheMonitor::No object ID found in URL, skipping",
59+
xbmc.LOGDEBUG,
60+
)
61+
return
5062

51-
xbmc.log("AmpacheMonitor::Starting setRating for URL: %s" % file_url, xbmc.LOGDEBUG)
52-
xbmc.executebuiltin('RunPlugin(plugin://plugin.audio.ampache/?mode=205)')
63+
xbmc.log(
64+
"AmpacheMonitor::Starting setRating for URL: %s" % file_url,
65+
xbmc.LOGDEBUG,
66+
)
67+
xbmc.executebuiltin(
68+
"RunPlugin(plugin://plugin.audio.ampache/?mode=205)"
69+
)
5370
except ValueError as e:
5471
xbmc.log("AmpacheMonitor::Value error: %s" % str(e), xbmc.LOGDEBUG)
5572
except Exception as e:
56-
xbmc.log("AmpacheMonitor::Error in onNotification: %s" % repr(e), xbmc.LOGERROR)
57-
58-
59-
73+
xbmc.log(
74+
"AmpacheMonitor::Error in onNotification: %s" % repr(e),
75+
xbmc.LOGERROR,
76+
)
Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
from future.utils import PY2
22
import os
3-
import xbmc,xbmcaddon
3+
import xbmc, xbmcaddon
44
import xbmcvfs
55

66
from datetime import datetime, timedelta
7-
#split the art library to not have import problems, as the function is used by
8-
#service and the main plugin
9-
#library used both by service and main plugin, DO NOT INCLUDE OTHER LOCAL
10-
#LIBRARIES
7+
# split the art library to not have import problems, as the function is used by
8+
# service and the main plugin
9+
# library used both by service and main plugin, DO NOT INCLUDE OTHER LOCAL
10+
# LIBRARIES
1111

1212
ampache = xbmcaddon.Addon("plugin.audio.ampache")
1313

1414
# Cache configuration constants
1515
ART_CACHE_EXPIRY_DAYS = 30
1616
ART_CACHE_TYPES = ["album", "artist", "song", "podcast", "playlist"]
1717

18-
#different functions in kodi 19 (python3) and kodi 18 (python2)
18+
# different functions in kodi 19 (python3) and kodi 18 (python2)
1919
if PY2:
20-
user_dir = xbmc.translatePath( ampache.getAddonInfo('profile'))
21-
user_dir = user_dir.decode('utf-8')
20+
user_dir = xbmc.translatePath(ampache.getAddonInfo("profile"))
21+
user_dir = user_dir.decode("utf-8")
2222
else:
23-
user_dir = xbmcvfs.translatePath( ampache.getAddonInfo('profile'))
24-
user_mediaDir = os.path.join( user_dir , 'media' )
25-
cacheDir = os.path.join( user_mediaDir , 'cache' )
23+
user_dir = xbmcvfs.translatePath(ampache.getAddonInfo("profile"))
24+
user_mediaDir = os.path.join(user_dir, "media")
25+
cacheDir = os.path.join(user_mediaDir, "cache")
26+
2627

2728
def clean_settings():
2829
ampache.setSetting("session_expire", "")
@@ -37,9 +38,10 @@ def clean_settings():
3738
ampache.setSetting("podcasts", "")
3839
ampache.setSetting("live_streams", "")
3940

40-
#hack to force the creation of profile directory if don't exists
41+
# hack to force the creation of profile directory if don't exists
4142
if not os.path.isdir(user_dir):
42-
ampache.setSetting("api-version","350001")
43+
ampache.setSetting("api-version", "350001")
44+
4345

4446
def is_expired(cache_file_path: str) -> bool:
4547
"""Check if the cache file has expired (older than one month)."""
@@ -52,42 +54,55 @@ def is_expired(cache_file_path: str) -> bool:
5254
last_modified = datetime.fromtimestamp(mod_time)
5355

5456
# Calculate if more than a month has passed since modification
55-
expiration_duration = timedelta(days=ART_CACHE_EXPIRY_DAYS) # ART_CACHE_EXPIRY_DAYS
57+
expiration_duration = timedelta(
58+
days=ART_CACHE_EXPIRY_DAYS
59+
) # ART_CACHE_EXPIRY_DAYS
5660

5761
return (now - last_modified) > expiration_duration
5862
except FileNotFoundError:
5963
return True # Treat missing files as expired
6064

65+
6166
def delete_expired_files():
6267

6368
for c_type in ART_CACHE_TYPES:
64-
cacheDirType = os.path.join( cacheDir , c_type )
69+
cacheDirType = os.path.join(cacheDir, c_type)
6570
if not os.path.isdir(cacheDirType):
6671
continue
6772
for currentFile in os.listdir(cacheDirType):
68-
#xbmc.log("Clear Cache Art " + str(currentFile),xbmc.LOGDEBUG)
69-
pathDel = os.path.join( cacheDirType, currentFile)
73+
# xbmc.log("Clear Cache Art " + str(currentFile),xbmc.LOGDEBUG)
74+
pathDel = os.path.join(cacheDirType, currentFile)
7075
if is_expired(pathDel):
7176
try:
7277
os.remove(pathDel)
7378
except OSError as e:
74-
raise
79+
xbmc.log(
80+
"AmpachePlugin::art_clean: Failed to delete file %s: %s"
81+
% (pathDel, repr(e)),
82+
xbmc.LOGDEBUG,
83+
)
84+
continue
85+
7586

7687
def remove_expired():
7788
try:
7889
print("Starting cache cleanup...")
7990
delete_expired_files()
8091
print("Cache cleanup completed.")
8192
except Exception as e:
82-
xbmc.log("AmpachePlugin::Service failed to cleanup cache: %s" % repr(e), xbmc.LOGERROR)
93+
xbmc.log(
94+
"AmpachePlugin::Service failed to cleanup cache: %s" % repr(e),
95+
xbmc.LOGERROR,
96+
)
97+
8398

8499
def init_cache():
85-
#if cacheDir doesn't exist, create it
100+
# if cacheDir doesn't exist, create it
86101
if not os.path.isdir(user_mediaDir):
87102
os.mkdir(user_mediaDir)
88103
if not os.path.isdir(cacheDir):
89104
os.mkdir(cacheDir)
90105
for c_type in ART_CACHE_TYPES:
91-
cacheDirType = os.path.join( cacheDir , c_type )
106+
cacheDirType = os.path.join(cacheDir, c_type)
92107
if not os.path.isdir(cacheDirType):
93-
os.mkdir( cacheDirType )
108+
os.mkdir(cacheDirType)

plugin.audio.ampache/resources/lib/servers_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def switchServer():
9292
try:
9393
ampacheConnect = ampache_connect.AmpacheConnect()
9494
ampacheConnect.AMPACHECONNECT(showok=True)
95-
except:
96-
pass
95+
except Exception as e:
96+
xbmc.log("AmpachePlugin::switchServer error: %s" % repr(e), xbmc.LOGERROR)
9797

9898
def addServer():
9999
xbmc.log("AmpachePlugin::addServer" , xbmc.LOGDEBUG )
@@ -203,5 +203,5 @@ def modifyServer():
203203
try:
204204
ampacheConnect = ampache_connect.AmpacheConnect()
205205
ampacheConnect.AMPACHECONNECT()
206-
except:
207-
pass
206+
except Exception as e:
207+
xbmc.log("AmpachePlugin::modifyServer error: %s" % repr(e), xbmc.LOGERROR)

0 commit comments

Comments
 (0)