optimazation, fix mpd update
This commit is contained in:
parent
dfa222a5f2
commit
7b1fd5cbe4
@ -69,7 +69,6 @@ class Luniebox(object):
|
|||||||
self.zspotify_path = self.get_setting('spotify', 'zspotify_path')
|
self.zspotify_path = self.get_setting('spotify', 'zspotify_path')
|
||||||
if self.zspotify_path and self.mpd:
|
if self.zspotify_path and self.mpd:
|
||||||
self.spotifydl_connect()
|
self.spotifydl_connect()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.getLogger('luniebox').info("spotify disabled")
|
logging.getLogger('luniebox').info("spotify disabled")
|
||||||
self.spotify = False
|
self.spotify = False
|
||||||
@ -82,9 +81,9 @@ class Luniebox(object):
|
|||||||
self.service = PlayerService.NONE
|
self.service = PlayerService.NONE
|
||||||
|
|
||||||
if self.current != None:
|
if self.current != None:
|
||||||
if self.current.startswith("spotify:"):
|
if self.current.startswith('spotify:'):
|
||||||
self.service = PlayerService.SPOTIFY
|
self.service = PlayerService.SPOTIFY
|
||||||
elif self.current.startswith("mpd:"):
|
elif self.current.startswith('mpd:'):
|
||||||
self.service = PlayerService.MPD
|
self.service = PlayerService.MPD
|
||||||
|
|
||||||
self.volume_max = int(self.get_setting('luniebox', 'volume_max', 100))
|
self.volume_max = int(self.get_setting('luniebox', 'volume_max', 100))
|
||||||
@ -160,12 +159,8 @@ class Luniebox(object):
|
|||||||
logging.getLogger('luniebox').warn("spotifydl disabled!")
|
logging.getLogger('luniebox').warn("spotifydl disabled!")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
username = self.spotify.get_setting("username")
|
|
||||||
password = self.spotify.get_setting("password")
|
|
||||||
root = self.get_setting('mpd', 'library_path')
|
|
||||||
try:
|
try:
|
||||||
self.spotifydl = SpotifyDL(
|
self.spotifydl = SpotifyDL(luniebox)
|
||||||
self.zspotify_path, username, password, root)
|
|
||||||
logging.getLogger('luniebox').info("spotifydl enabled!")
|
logging.getLogger('luniebox').info("spotifydl enabled!")
|
||||||
return True
|
return True
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
@ -275,85 +270,84 @@ class Luniebox(object):
|
|||||||
|
|
||||||
def play(self, text):
|
def play(self, text):
|
||||||
if text != "":
|
if text != "":
|
||||||
if text.startswith("spotify:"):
|
if text.startswith('spotify:') and self.spotify:
|
||||||
self.service = PlayerService.SPOTIFY
|
self.service = PlayerService.SPOTIFY
|
||||||
elif text.startswith("mpd:"):
|
elif text.startswith('mpd:') and self.mpd:
|
||||||
self.service = PlayerService.MPD
|
self.service = PlayerService.MPD
|
||||||
|
else:
|
||||||
|
self.service = PlayerService.NONE
|
||||||
|
|
||||||
if self.service == PlayerService.SPOTIFY and self.spotifydl_connect():
|
if self.service == PlayerService.SPOTIFY and self.spotifydl_connect():
|
||||||
downloadStatus = self.spotifydl.downloadStatus(text)
|
downloadStatus = self.spotifydl.downloadStatus(text)
|
||||||
if downloadStatus == SpotifyDLStatus.FINISHED:
|
if downloadStatus == SpotifyDLStatus.FINISHED and self.mpd_connect():
|
||||||
self.mpd.update(text.replace('mpd:', ''))
|
self.mpd.update()
|
||||||
|
self.mpd.idle('update')
|
||||||
self.service = PlayerService.MPD
|
self.service = PlayerService.MPD
|
||||||
elif self.get_setting('spotify', 'auto_download') == 'True' and downloadStatus == SpotifyDLStatus.NONE or downloadStatus == SpotifyDLStatus.ERROR:
|
elif self.get_setting('spotify', 'auto_download') == 'True' and downloadStatus == SpotifyDLStatus.NONE or downloadStatus == SpotifyDLStatus.ERROR:
|
||||||
self.spotifydl.download(text)
|
self.spotifydl.download(text)
|
||||||
|
|
||||||
if self.service == PlayerService.SPOTIFY:
|
if self.service == PlayerService.SPOTIFY and self.spotify_connect():
|
||||||
if text != self.current:
|
if text != self.current:
|
||||||
if self.spotify_connect():
|
self.spotify.volume(self.volume)
|
||||||
self.spotify.volume(self.volume)
|
if self.spotify.play(text):
|
||||||
if self.spotify.play(text):
|
|
||||||
self.current = text
|
|
||||||
self.set_setting(
|
|
||||||
'luniebox', 'current', self.current)
|
|
||||||
self.resume = False
|
|
||||||
logging.getLogger('luniebox').debug(
|
|
||||||
"play spotify: " + self.current)
|
|
||||||
else:
|
|
||||||
logging.getLogger('luniebox').warn(
|
|
||||||
"cannot play spotify: " + self.current)
|
|
||||||
elif self.resume and text == self.current:
|
|
||||||
if self.spotify_connect():
|
|
||||||
self.spotify.volume(self.volume)
|
|
||||||
play = self.current
|
|
||||||
if self.spotify.is_active():
|
|
||||||
play = None
|
|
||||||
if self.spotify.play(play):
|
|
||||||
self.resume = False
|
|
||||||
logging.getLogger('luniebox').debug(
|
|
||||||
"resume spotify: " + self.current)
|
|
||||||
else:
|
|
||||||
logging.getLogger('luniebox').warn(
|
|
||||||
"cannot resume spotify: " + self.current)
|
|
||||||
return True
|
|
||||||
elif self.service == PlayerService.MPD:
|
|
||||||
if text != self.current:
|
|
||||||
if self.mpd_connect():
|
|
||||||
try:
|
|
||||||
self.mpd.setvol(self.volume)
|
|
||||||
self.mpd.clear()
|
|
||||||
text = text.replace('mpd:', '')
|
|
||||||
self.mpd.add(text)
|
|
||||||
self.mpd.play()
|
|
||||||
except Exception as exception:
|
|
||||||
logging.getLogger('luniebox').warning(
|
|
||||||
"cannot not play mpd '" + text + "': " + str(exception))
|
|
||||||
return False
|
|
||||||
self.current = text
|
self.current = text
|
||||||
self.set_setting('luniebox', 'current', self.current)
|
self.set_setting(
|
||||||
|
'luniebox', 'current', self.current)
|
||||||
self.resume = False
|
self.resume = False
|
||||||
if text.startswith('spotify:'):
|
logging.getLogger('luniebox').debug(
|
||||||
logging.getLogger('luniebox').debug(
|
"play spotify: " + self.current)
|
||||||
"play spotify from mpd: " + text)
|
else:
|
||||||
else:
|
logging.getLogger('luniebox').warn(
|
||||||
logging.getLogger('luniebox').debug(
|
"cannot play spotify: " + self.current)
|
||||||
"play mpd: " + self.current)
|
|
||||||
elif self.resume and text == self.current:
|
elif self.resume and text == self.current:
|
||||||
if self.mpd_connect():
|
self.spotify.volume(self.volume)
|
||||||
try:
|
play = self.current
|
||||||
self.mpd.setvol(self.volume)
|
if self.spotify.is_active():
|
||||||
self.mpd.play()
|
play = None
|
||||||
except Exception as exception:
|
if self.spotify.play(play):
|
||||||
logging.getLogger('luniebox').warning(
|
|
||||||
"cannot not resume mpd '" + self.current + "': " + str(exception))
|
|
||||||
return False
|
|
||||||
self.resume = False
|
self.resume = False
|
||||||
if text.startswith('spotify:'):
|
logging.getLogger('luniebox').debug(
|
||||||
logging.getLogger('luniebox').debug(
|
"resume spotify: " + self.current)
|
||||||
"resume spotify from mpd: " + text)
|
else:
|
||||||
else:
|
logging.getLogger('luniebox').warn(
|
||||||
logging.getLogger('luniebox').debug(
|
"cannot resume spotify: " + self.current)
|
||||||
"resume mpd: " + self.current)
|
return True
|
||||||
|
elif self.service == PlayerService.MPD and self.mpd_connect():
|
||||||
|
if text != self.current:
|
||||||
|
try:
|
||||||
|
self.mpd.setvol(self.volume)
|
||||||
|
self.mpd.clear()
|
||||||
|
mpd_uri = text.replace('mpd:', '')
|
||||||
|
self.mpd.add(mpd_uri)
|
||||||
|
self.mpd.play()
|
||||||
|
except Exception as exception:
|
||||||
|
logging.getLogger('luniebox').warning(
|
||||||
|
"cannot not play mpd '" + text + "': " + str(exception))
|
||||||
|
return False
|
||||||
|
self.current = text
|
||||||
|
self.set_setting('luniebox', 'current', self.current)
|
||||||
|
self.resume = False
|
||||||
|
if text.startswith('spotify:'):
|
||||||
|
logging.getLogger('luniebox').debug(
|
||||||
|
"play spotify from mpd: " + text)
|
||||||
|
else:
|
||||||
|
logging.getLogger('luniebox').debug(
|
||||||
|
"play mpd: " + self.current)
|
||||||
|
elif self.resume and text == self.current:
|
||||||
|
try:
|
||||||
|
self.mpd.setvol(self.volume)
|
||||||
|
self.mpd.play()
|
||||||
|
except Exception as exception:
|
||||||
|
logging.getLogger('luniebox').warning(
|
||||||
|
"cannot not resume mpd '" + self.current + "': " + str(exception))
|
||||||
|
return False
|
||||||
|
self.resume = False
|
||||||
|
if text.startswith('spotify:'):
|
||||||
|
logging.getLogger('luniebox').debug(
|
||||||
|
"resume spotify from mpd: " + text)
|
||||||
|
else:
|
||||||
|
logging.getLogger('luniebox').debug(
|
||||||
|
"resume mpd: " + self.current)
|
||||||
return True
|
return True
|
||||||
elif text != None:
|
elif text != None:
|
||||||
logging.getLogger('luniebox').info(
|
logging.getLogger('luniebox').info(
|
||||||
|
@ -23,19 +23,27 @@ class SpotifyDLStatus(Enum):
|
|||||||
|
|
||||||
class SpotifyDL():
|
class SpotifyDL():
|
||||||
|
|
||||||
def __init__(self, zspotify_path, username, password, root, credentialsLocation=defaultCredentialsLocation):
|
def __init__(self, luniebox, credentialsLocation=defaultCredentialsLocation):
|
||||||
if zspotify_path:
|
|
||||||
self.zspotify_path = zspotify_path
|
if not luniebox.zspotify_path:
|
||||||
else:
|
|
||||||
raise ValueError("No zspotify path provivded!")
|
raise ValueError("No zspotify path provivded!")
|
||||||
|
else:
|
||||||
|
self.zspotify_path = luniebox.zspotify_path
|
||||||
|
|
||||||
if credentialsLocation:
|
if credentialsLocation:
|
||||||
self.credentialsLocation = credentialsLocation
|
self.credentialsLocation = credentialsLocation
|
||||||
else:
|
else:
|
||||||
raise ValueError("No credentialsLocation provivded!")
|
raise ValueError("No credentialsLocation provivded!")
|
||||||
|
|
||||||
|
username = luniebox.spotify.get_setting("username")
|
||||||
if not username:
|
if not username:
|
||||||
raise ValueError("No username provided!")
|
raise ValueError("No username provided!")
|
||||||
|
|
||||||
|
password = luniebox.spotify.get_setting("password")
|
||||||
if not password:
|
if not password:
|
||||||
raise ValueError("No password provided!")
|
raise ValueError("No password provided!")
|
||||||
|
|
||||||
|
root = luniebox.get_setting('mpd', 'library_path')
|
||||||
if root:
|
if root:
|
||||||
if not root.endswith("/"):
|
if not root.endswith("/"):
|
||||||
root = root + "/"
|
root = root + "/"
|
||||||
|
Loading…
Reference in New Issue
Block a user