Fixed LINT warnings and changed MPD filter format (from list to dict)
This commit is contained in:
parent
ed02505dce
commit
42c5bbe0e4
1 changed files with 39 additions and 26 deletions
|
@ -105,7 +105,6 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
Play a track in the current playlist by position number
|
Play a track in the current playlist by position number
|
||||||
|
|
||||||
:param pos: Position number
|
:param pos: Position number
|
||||||
:type resource: int
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self._exec('play', pos)
|
return self._exec('play', pos)
|
||||||
|
@ -115,8 +114,10 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
""" Pause playback """
|
""" Pause playback """
|
||||||
|
|
||||||
status = self.status().output['state']
|
status = self.status().output['state']
|
||||||
if status == 'play': return self._exec('pause')
|
if status == 'play':
|
||||||
else: return self._exec('play')
|
return self._exec('pause')
|
||||||
|
else:
|
||||||
|
return self._exec('play')
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def pause_if_playing(self):
|
def pause_if_playing(self):
|
||||||
|
@ -147,7 +148,6 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
""" Stop playback """
|
""" Stop playback """
|
||||||
return self._exec('stop')
|
return self._exec('stop')
|
||||||
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def play_or_stop(self):
|
def play_or_stop(self):
|
||||||
""" Play or stop (play state toggle) """
|
""" Play or stop (play state toggle) """
|
||||||
|
@ -186,7 +186,7 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
:param vol: Volume value (range: 0-100)
|
:param vol: Volume value (range: 0-100)
|
||||||
:type vol: int
|
:type vol: int
|
||||||
"""
|
"""
|
||||||
return self._exec('setvol', vol)
|
return self._exec('setvol', str(vol))
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def volup(self, delta=10):
|
def volup(self, delta=10):
|
||||||
|
@ -199,7 +199,7 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
|
|
||||||
volume = int(self.status().output['volume'])
|
volume = int(self.status().output['volume'])
|
||||||
new_volume = min(volume + delta, 100)
|
new_volume = min(volume + delta, 100)
|
||||||
return self.setvol(str(new_volume))
|
return self.setvol(new_volume)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def voldown(self, delta=10):
|
def voldown(self, delta=10):
|
||||||
|
@ -212,7 +212,7 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
|
|
||||||
volume = int(self.status().output['volume'])
|
volume = int(self.status().output['volume'])
|
||||||
new_volume = max(volume - delta, 0)
|
new_volume = max(volume - delta, 0)
|
||||||
return self.setvol(str(new_volume))
|
return self.setvol(new_volume)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def random(self, value=None):
|
def random(self, value=None):
|
||||||
|
@ -370,7 +370,8 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
return
|
return
|
||||||
|
|
||||||
m = re.search('^https://open.spotify.com/([^?]+)', resource)
|
m = re.search('^https://open.spotify.com/([^?]+)', resource)
|
||||||
if m: resource = 'spotify:{}'.format(m.group(1).replace('/', ':'))
|
if m:
|
||||||
|
resource = 'spotify:{}'.format(m.group(1).replace('/', ':'))
|
||||||
|
|
||||||
if resource.startswith('spotify:'):
|
if resource.startswith('spotify:'):
|
||||||
resource = resource.split('?')[0]
|
resource = resource.split('?')[0]
|
||||||
|
@ -469,6 +470,7 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
|
|
||||||
return None, error
|
return None, error
|
||||||
|
|
||||||
|
# noinspection PyTypeChecker
|
||||||
@action
|
@action
|
||||||
def currentsong(self):
|
def currentsong(self):
|
||||||
"""
|
"""
|
||||||
|
@ -707,40 +709,50 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
self._exec('play')
|
self._exec('play')
|
||||||
return {'playlist': playlists[0]}
|
return {'playlist': playlists[0]}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _make_filter(f: dict) -> list:
|
||||||
|
ll = []
|
||||||
|
for k, v in f.items():
|
||||||
|
ll.extend([k, v])
|
||||||
|
return ll
|
||||||
|
|
||||||
|
# noinspection PyShadowingBuiltins
|
||||||
@action
|
@action
|
||||||
def find(self, filter, *args, **kwargs):
|
def find(self, filter: dict, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Find in the database/library by filter.
|
Find in the database/library by filter.
|
||||||
|
|
||||||
:param filter: Search filter. MPD treats it as a key-valued list (e.g. ``["artist", "Led Zeppelin", "album", "IV"]``)
|
:param filter: Search filter (e.g. ``{"artist": "Led Zeppelin", "album": "IV"}``)
|
||||||
:type filter: list[str]
|
|
||||||
:returns: list[dict]
|
:returns: list[dict]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
filter = self._make_filter(filter)
|
||||||
return self._exec('find', *filter, *args, return_status=False, **kwargs)
|
return self._exec('find', *filter, *args, return_status=False, **kwargs)
|
||||||
|
|
||||||
|
# noinspection PyShadowingBuiltins
|
||||||
@action
|
@action
|
||||||
def findadd(self, filter, *args, **kwargs):
|
def findadd(self, filter: dict, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Find in the database/library by filter and add to the current playlist.
|
Find in the database/library by filter and add to the current playlist.
|
||||||
|
|
||||||
:param filter: Search filter. MPD treats it as a key-valued list (e.g. ``["artist", "Led Zeppelin", "album", "IV"]``)
|
:param filter: Search filter (e.g. ``{"artist": "Led Zeppelin", "album": "IV"}``)
|
||||||
:type filter: list[str]
|
|
||||||
:returns: list[dict]
|
:returns: list[dict]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
filter = self._make_filter(filter)
|
||||||
return self._exec('findadd', *filter, *args, return_status=False, **kwargs)
|
return self._exec('findadd', *filter, *args, return_status=False, **kwargs)
|
||||||
|
|
||||||
|
# noinspection PyShadowingBuiltins
|
||||||
@action
|
@action
|
||||||
def search(self, filter, *args, **kwargs):
|
def search(self, filter: dict, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Free search by filter.
|
Free search by filter.
|
||||||
|
|
||||||
:param filter: Search filter. MPD treats it as a key-valued list (e.g. ``["artist", "Led Zeppelin", "album", "IV"]``)
|
:param filter: Search filter (e.g. ``{"artist": "Led Zeppelin", "album": "IV"}``)
|
||||||
:type filter: list[str]
|
|
||||||
:returns: list[dict]
|
:returns: list[dict]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
filter = self._make_filter(filter)
|
||||||
items = self._exec('search', *filter, *args, return_status=False, **kwargs)
|
items = self._exec('search', *filter, *args, return_status=False, **kwargs)
|
||||||
|
|
||||||
# Spotify results first
|
# Spotify results first
|
||||||
|
@ -749,17 +761,18 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
# noinspection PyShadowingBuiltins
|
||||||
@action
|
@action
|
||||||
def searchadd(self, filter, *args, **kwargs):
|
def searchadd(self, filter, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Free search by filter and add the results to the current playlist.
|
Free search by filter and add the results to the current playlist.
|
||||||
|
|
||||||
:param filter: Search filter. MPD treats it as a key-valued list (e.g. ``["artist", "Led Zeppelin", "album", "IV"]``)
|
:param filter: Search filter (e.g. ``{"artist": "Led Zeppelin", "album": "IV"}``)
|
||||||
:type filter: list[str]
|
|
||||||
:returns: list[dict]
|
:returns: list[dict]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
filter = self._make_filter(filter)
|
||||||
return self._exec('searchadd', *filter, *args, return_status=False, **kwargs)
|
return self._exec('searchadd', *filter, *args, return_status=False, **kwargs)
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
|
||||||
|
|
||||||
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue