Skip to content
Snippets Groups Projects
Commit 6f1d9d78 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Get error on read file, add sleep if missing file

parent a38a83a1
No related branches found
No related tags found
1 merge request!25Resolve "Sleep if watched log file is missing"
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.spotify.screensaver" <addon id="script.spotify.screensaver"
name="Spotify Screensaver" name="Spotify Screensaver"
version="0.0.17" version="0.0.18"
provider-name="Benoît Harrault"> provider-name="Benoît Harrault">
<requires> <requires>
<import addon="xbmc.python" version="2.25.0"/> <import addon="xbmc.python" version="2.25.0"/>
......
...@@ -121,7 +121,7 @@ class GUI(xbmcgui.WindowXMLDialog): ...@@ -121,7 +121,7 @@ class GUI(xbmcgui.WindowXMLDialog):
self.log('spotify event: ' + spotify_event) self.log('spotify event: ' + spotify_event)
event_split = spotify_event.split(':') event_split = spotify_event.split(':')
event_type = event_split[1] event_type = event_split[1] if len(event_split) > 1 else ''
event_value = event_split[2] if len(event_split) > 2 else '' event_value = event_split[2] if len(event_split) > 2 else ''
if event_type == 'changed' or event_type == 'playing': if event_type == 'changed' or event_type == 'playing':
...@@ -140,7 +140,7 @@ class GUI(xbmcgui.WindowXMLDialog): ...@@ -140,7 +140,7 @@ class GUI(xbmcgui.WindowXMLDialog):
elif event_type == 'volume_set': elif event_type == 'volume_set':
self._unimplemented_event_type(event_type, event_value) self._unimplemented_event_type(event_type, event_value)
else: else:
self.log('unknown event type: ' + event_type, xbmc.LOGERROR) self._unknown_event_type(event_type, event_value)
def _unimplemented_event_type(self, event_type, event_value): def _unimplemented_event_type(self, event_type, event_value):
self.log( self.log(
...@@ -148,6 +148,13 @@ class GUI(xbmcgui.WindowXMLDialog): ...@@ -148,6 +148,13 @@ class GUI(xbmcgui.WindowXMLDialog):
+ ' (value: ' + str(event_value) + ')' + ' (value: ' + str(event_value) + ')'
) )
def _unknown_event_type(self, event_type, event_value):
self.log(
'unknown event type: "' + str(event_type) + '"'
+ ' (value: "' + str(event_value) + '")',
xbmc.LOGERROR
)
def _preload_images(self, track_id): def _preload_images(self, track_id):
self.log('preload images for track: ' + track_id) self.log('preload images for track: ' + track_id)
...@@ -327,11 +334,31 @@ class GUI(xbmcgui.WindowXMLDialog): ...@@ -327,11 +334,31 @@ class GUI(xbmcgui.WindowXMLDialog):
def _get_last_spotify_event(self): def _get_last_spotify_event(self):
last_event = '' last_event = ''
# open file
try: try:
f = open(LIBRESPOT_EVENT_FILE, 'r') f = open(LIBRESPOT_EVENT_FILE, 'r')
last_event = f.readlines()[-1] except Exception as e:
finally: self.log(
f.close() 'failed to get file ' + LIBRESPOT_EVENT_FILE + ': ' + str(e),
xbmc.LOGERROR
)
self.log('sleep 60s...', xbmc.LOGERROR)
xbmc.sleep(60000)
else:
# read file (last line)
try:
last_event = f.readlines()[-1]
except Exception as e:
self.log('failed to get content: ' + str(e), xbmc.LOGERROR)
self.log('sleep 10s...', xbmc.LOGERROR)
xbmc.sleep(10000)
else:
# close file
try:
f.close()
except Exception as e:
self.log('failed to close file: ' + str(e), xbmc.LOGERROR)
last_event = ''.join(last_event.splitlines()) last_event = ''.join(last_event.splitlines())
return last_event return last_event
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment