Merge pull request #1135 from adamcik/feature/mpd-spring-cleaning
MPD spring cleaning
This commit is contained in:
commit
a3a32229b2
@ -8,7 +8,7 @@ def disableoutput(context, outputid):
|
||||
"""
|
||||
*musicpd.org, audio output section:*
|
||||
|
||||
``disableoutput``
|
||||
``disableoutput {ID}``
|
||||
|
||||
Turns an output off.
|
||||
"""
|
||||
@ -25,7 +25,7 @@ def enableoutput(context, outputid):
|
||||
"""
|
||||
*musicpd.org, audio output section:*
|
||||
|
||||
``enableoutput``
|
||||
``enableoutput {ID}``
|
||||
|
||||
Turns an output on.
|
||||
"""
|
||||
|
||||
@ -64,17 +64,21 @@ def addid(context, uri, songpos=None):
|
||||
"""
|
||||
if not uri:
|
||||
raise exceptions.MpdNoExistError('No such song')
|
||||
if songpos is not None and songpos > context.core.tracklist.length.get():
|
||||
|
||||
length = context.core.tracklist.get_length()
|
||||
if songpos is not None and songpos > length.get():
|
||||
raise exceptions.MpdArgError('Bad song index')
|
||||
|
||||
tl_tracks = context.core.tracklist.add(
|
||||
uris=[uri], at_position=songpos).get()
|
||||
|
||||
if not tl_tracks:
|
||||
raise exceptions.MpdNoExistError('No such song')
|
||||
return ('Id', tl_tracks[0].tlid)
|
||||
|
||||
|
||||
@protocol.commands.add('delete', position=protocol.RANGE)
|
||||
def delete(context, position):
|
||||
@protocol.commands.add('delete', songrange=protocol.RANGE)
|
||||
def delete(context, songrange):
|
||||
"""
|
||||
*musicpd.org, current playlist section:*
|
||||
|
||||
@ -82,10 +86,10 @@ def delete(context, position):
|
||||
|
||||
Deletes a song from the playlist.
|
||||
"""
|
||||
start = position.start
|
||||
end = position.stop
|
||||
start = songrange.start
|
||||
end = songrange.stop
|
||||
if end is None:
|
||||
end = context.core.tracklist.length.get()
|
||||
end = context.core.tracklist.get_length().get()
|
||||
tl_tracks = context.core.tracklist.slice(start, end).get()
|
||||
if not tl_tracks:
|
||||
raise exceptions.MpdArgError('Bad song index', command='delete')
|
||||
@ -119,8 +123,8 @@ def clear(context):
|
||||
context.core.tracklist.clear()
|
||||
|
||||
|
||||
@protocol.commands.add('move', position=protocol.RANGE, to=protocol.UINT)
|
||||
def move_range(context, position, to):
|
||||
@protocol.commands.add('move', songrange=protocol.RANGE, to=protocol.UINT)
|
||||
def move_range(context, songrange, to):
|
||||
"""
|
||||
*musicpd.org, current playlist section:*
|
||||
|
||||
@ -129,10 +133,10 @@ def move_range(context, position, to):
|
||||
Moves the song at ``FROM`` or range of songs at ``START:END`` to
|
||||
``TO`` in the playlist.
|
||||
"""
|
||||
start = position.start
|
||||
end = position.stop
|
||||
start = songrange.start
|
||||
end = songrange.stop
|
||||
if end is None:
|
||||
end = context.core.tracklist.length.get()
|
||||
end = context.core.tracklist.get_length().get()
|
||||
context.core.tracklist.move(start, end, to)
|
||||
|
||||
|
||||
@ -211,7 +215,7 @@ def playlistid(context, tlid=None):
|
||||
return translator.track_to_mpd_format(tl_tracks[0], position=position)
|
||||
else:
|
||||
return translator.tracks_to_mpd_format(
|
||||
context.core.tracklist.tl_tracks.get())
|
||||
context.core.tracklist.get_tl_tracks().get())
|
||||
|
||||
|
||||
@protocol.commands.add('playlistinfo')
|
||||
@ -236,7 +240,7 @@ def playlistinfo(context, parameter=None):
|
||||
tracklist_slice = protocol.RANGE(parameter)
|
||||
start, end = tracklist_slice.start, tracklist_slice.stop
|
||||
|
||||
tl_tracks = context.core.tracklist.tl_tracks.get()
|
||||
tl_tracks = context.core.tracklist.get_tl_tracks().get()
|
||||
if start and start > len(tl_tracks):
|
||||
raise exceptions.MpdArgError('Bad song index')
|
||||
if end and end > len(tl_tracks):
|
||||
@ -279,10 +283,10 @@ def plchanges(context, version):
|
||||
- Calls ``plchanges "-1"`` two times per second to get the entire playlist.
|
||||
"""
|
||||
# XXX Naive implementation that returns all tracks as changed
|
||||
tracklist_version = context.core.tracklist.version.get()
|
||||
tracklist_version = context.core.tracklist.get_version().get()
|
||||
if version < tracklist_version:
|
||||
return translator.tracks_to_mpd_format(
|
||||
context.core.tracklist.tl_tracks.get())
|
||||
context.core.tracklist.get_tl_tracks().get())
|
||||
elif version == tracklist_version:
|
||||
# A version match could indicate this is just a metadata update, so
|
||||
# check for a stream ref and let the client know about the change.
|
||||
@ -290,7 +294,7 @@ def plchanges(context, version):
|
||||
if stream_title is None:
|
||||
return None
|
||||
|
||||
tl_track = context.core.playback.current_tl_track.get()
|
||||
tl_track = context.core.playback.get_current_tl_track().get()
|
||||
position = context.core.tracklist.index(tl_track).get()
|
||||
return translator.track_to_mpd_format(
|
||||
tl_track, position=position, stream_title=stream_title)
|
||||
@ -311,17 +315,17 @@ def plchangesposid(context, version):
|
||||
``playlistlength`` returned by status command.
|
||||
"""
|
||||
# XXX Naive implementation that returns all tracks as changed
|
||||
if int(version) != context.core.tracklist.version.get():
|
||||
if int(version) != context.core.tracklist.get_version().get():
|
||||
result = []
|
||||
for (position, (tlid, _)) in enumerate(
|
||||
context.core.tracklist.tl_tracks.get()):
|
||||
context.core.tracklist.get_tl_tracks().get()):
|
||||
result.append(('cpos', position))
|
||||
result.append(('Id', tlid))
|
||||
return result
|
||||
|
||||
|
||||
@protocol.commands.add('shuffle', position=protocol.RANGE)
|
||||
def shuffle(context, position=None):
|
||||
@protocol.commands.add('shuffle', songrange=protocol.RANGE)
|
||||
def shuffle(context, songrange=None):
|
||||
"""
|
||||
*musicpd.org, current playlist section:*
|
||||
|
||||
@ -330,10 +334,10 @@ def shuffle(context, position=None):
|
||||
Shuffles the current playlist. ``START:END`` is optional and
|
||||
specifies a range of songs.
|
||||
"""
|
||||
if position is None:
|
||||
if songrange is None:
|
||||
start, end = None, None
|
||||
else:
|
||||
start, end = position.start, position.stop
|
||||
start, end = songrange.start, songrange.stop
|
||||
context.core.tracklist.shuffle(start, end)
|
||||
|
||||
|
||||
@ -346,7 +350,7 @@ def swap(context, songpos1, songpos2):
|
||||
|
||||
Swaps the positions of ``SONG1`` and ``SONG2``.
|
||||
"""
|
||||
tracks = context.core.tracklist.tracks.get()
|
||||
tracks = context.core.tracklist.get_tracks().get()
|
||||
song1 = tracks[songpos1]
|
||||
song2 = tracks[songpos2]
|
||||
del tracks[songpos1]
|
||||
|
||||
@ -2,7 +2,6 @@ from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import functools
|
||||
import itertools
|
||||
import warnings
|
||||
|
||||
from mopidy.models import Track
|
||||
from mopidy.mpd import exceptions, protocol, translator
|
||||
@ -174,10 +173,9 @@ def findadd(context, *args):
|
||||
|
||||
results = context.core.library.search(query=query, exact=True).get()
|
||||
|
||||
with warnings.catch_warnings():
|
||||
with deprecation.ignore('core.tracklist.add:tracks_arg'):
|
||||
# TODO: for now just use tracks as other wise we have to lookup the
|
||||
# tracks we just got from the search.
|
||||
warnings.filterwarnings('ignore', 'tracklist.add.*"tracks" argument.*')
|
||||
context.core.tracklist.add(tracks=_get_tracks(results)).get()
|
||||
|
||||
|
||||
@ -452,10 +450,9 @@ def searchadd(context, *args):
|
||||
|
||||
results = context.core.library.search(query).get()
|
||||
|
||||
with warnings.catch_warnings():
|
||||
with deprecation.ignore('core.tracklist.add:tracks_arg'):
|
||||
# TODO: for now just use tracks as other wise we have to lookup the
|
||||
# tracks we just got from the search.
|
||||
warnings.filterwarnings('ignore', 'tracklist.add.*"tracks".*')
|
||||
context.core.tracklist.add(_get_tracks(results)).get()
|
||||
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ def consume(context, state):
|
||||
1. When consume is activated, each song played is removed from
|
||||
playlist.
|
||||
"""
|
||||
context.core.tracklist.consume = state
|
||||
context.core.tracklist.set_consume(state)
|
||||
|
||||
|
||||
@protocol.commands.add('crossfade', seconds=protocol.UINT)
|
||||
@ -135,9 +135,10 @@ def pause(context, state=None):
|
||||
if state is None:
|
||||
deprecation.warn('mpd.protocol.playback.pause:state_arg')
|
||||
|
||||
if (context.core.playback.state.get() == PlaybackState.PLAYING):
|
||||
playback_state = context.core.playback.get_state().get()
|
||||
if (playback_state == PlaybackState.PLAYING):
|
||||
context.core.playback.pause()
|
||||
elif (context.core.playback.state.get() == PlaybackState.PAUSED):
|
||||
elif (playback_state == PlaybackState.PAUSED):
|
||||
context.core.playback.resume()
|
||||
elif state:
|
||||
context.core.playback.pause()
|
||||
@ -145,8 +146,8 @@ def pause(context, state=None):
|
||||
context.core.playback.resume()
|
||||
|
||||
|
||||
@protocol.commands.add('play', tlid=protocol.INT)
|
||||
def play(context, tlid=None):
|
||||
@protocol.commands.add('play', songpos=protocol.INT)
|
||||
def play(context, songpos=None):
|
||||
"""
|
||||
*musicpd.org, playback section:*
|
||||
|
||||
@ -170,31 +171,34 @@ def play(context, tlid=None):
|
||||
|
||||
- issues ``play 6`` without quotes around the argument.
|
||||
"""
|
||||
if tlid is None:
|
||||
if songpos is None:
|
||||
return context.core.playback.play().get()
|
||||
elif tlid == -1:
|
||||
elif songpos == -1:
|
||||
return _play_minus_one(context)
|
||||
|
||||
try:
|
||||
tl_track = context.core.tracklist.slice(tlid, tlid + 1).get()[0]
|
||||
tl_track = context.core.tracklist.slice(songpos, songpos + 1).get()[0]
|
||||
return context.core.playback.play(tl_track).get()
|
||||
except IndexError:
|
||||
raise exceptions.MpdArgError('Bad song index')
|
||||
|
||||
|
||||
def _play_minus_one(context):
|
||||
if (context.core.playback.state.get() == PlaybackState.PLAYING):
|
||||
playback_state = context.core.playback.get_state().get()
|
||||
if playback_state == PlaybackState.PLAYING:
|
||||
return # Nothing to do
|
||||
elif (context.core.playback.state.get() == PlaybackState.PAUSED):
|
||||
elif playback_state == PlaybackState.PAUSED:
|
||||
return context.core.playback.resume().get()
|
||||
elif context.core.playback.current_tl_track.get() is not None:
|
||||
tl_track = context.core.playback.current_tl_track.get()
|
||||
return context.core.playback.play(tl_track).get()
|
||||
elif context.core.tracklist.slice(0, 1).get():
|
||||
tl_track = context.core.tracklist.slice(0, 1).get()[0]
|
||||
return context.core.playback.play(tl_track).get()
|
||||
else:
|
||||
return # Fail silently
|
||||
|
||||
current_tl_track = context.core.playback.get_current_tl_track().get()
|
||||
if current_tl_track is not None:
|
||||
return context.core.playback.play(current_tl_track).get()
|
||||
|
||||
tl_tracks = context.core.tracklist.slice(0, 1).get()
|
||||
if tl_tracks:
|
||||
return context.core.playback.play(tl_tracks[0]).get()
|
||||
|
||||
return # Fail silently
|
||||
|
||||
|
||||
@protocol.commands.add('playid', tlid=protocol.INT)
|
||||
@ -279,7 +283,7 @@ def random(context, state):
|
||||
|
||||
Sets random state to ``STATE``, ``STATE`` should be 0 or 1.
|
||||
"""
|
||||
context.core.tracklist.random = state
|
||||
context.core.tracklist.set_random(state)
|
||||
|
||||
|
||||
@protocol.commands.add('repeat', state=protocol.BOOL)
|
||||
@ -291,7 +295,7 @@ def repeat(context, state):
|
||||
|
||||
Sets repeat state to ``STATE``, ``STATE`` should be 0 or 1.
|
||||
"""
|
||||
context.core.tracklist.repeat = state
|
||||
context.core.tracklist.set_repeat(state)
|
||||
|
||||
|
||||
@protocol.commands.add('replay_gain_mode')
|
||||
@ -324,8 +328,8 @@ def replay_gain_status(context):
|
||||
return 'off' # TODO
|
||||
|
||||
|
||||
@protocol.commands.add('seek', tlid=protocol.UINT, seconds=protocol.UINT)
|
||||
def seek(context, tlid, seconds):
|
||||
@protocol.commands.add('seek', songpos=protocol.UINT, seconds=protocol.UINT)
|
||||
def seek(context, songpos, seconds):
|
||||
"""
|
||||
*musicpd.org, playback section:*
|
||||
|
||||
@ -338,9 +342,9 @@ def seek(context, tlid, seconds):
|
||||
|
||||
- issues ``seek 1 120`` without quotes around the arguments.
|
||||
"""
|
||||
tl_track = context.core.playback.current_tl_track.get()
|
||||
if context.core.tracklist.index(tl_track).get() != tlid:
|
||||
play(context, tlid)
|
||||
tl_track = context.core.playback.get_current_tl_track().get()
|
||||
if context.core.tracklist.index(tl_track).get() != songpos:
|
||||
play(context, songpos)
|
||||
context.core.playback.seek(seconds * 1000).get()
|
||||
|
||||
|
||||
@ -353,7 +357,7 @@ def seekid(context, tlid, seconds):
|
||||
|
||||
Seeks to the position ``TIME`` (in seconds) of song ``SONGID``.
|
||||
"""
|
||||
tl_track = context.core.playback.current_tl_track.get()
|
||||
tl_track = context.core.playback.get_current_tl_track().get()
|
||||
if not tl_track or tl_track.tlid != tlid:
|
||||
playid(context, tlid)
|
||||
context.core.playback.seek(seconds * 1000).get()
|
||||
@ -370,7 +374,7 @@ def seekcur(context, time):
|
||||
'+' or '-', then the time is relative to the current playing position.
|
||||
"""
|
||||
if time.startswith(('+', '-')):
|
||||
position = context.core.playback.time_position.get()
|
||||
position = context.core.playback.get_time_position().get()
|
||||
position += protocol.INT(time) * 1000
|
||||
context.core.playback.seek(position).get()
|
||||
else:
|
||||
@ -409,7 +413,7 @@ def single(context, state):
|
||||
single is activated, playback is stopped after current song, or
|
||||
song is repeated if the ``repeat`` mode is enabled.
|
||||
"""
|
||||
context.core.tracklist.single = state
|
||||
context.core.tracklist.set_single(state)
|
||||
|
||||
|
||||
@protocol.commands.add('stop')
|
||||
|
||||
@ -107,4 +107,4 @@ def urlhandlers(context):
|
||||
"""
|
||||
return [
|
||||
('handler', uri_scheme)
|
||||
for uri_scheme in context.core.uri_schemes.get()]
|
||||
for uri_scheme in context.core.get_uri_schemes().get()]
|
||||
|
||||
@ -34,7 +34,7 @@ def currentsong(context):
|
||||
Displays the song info of the current song (same song that is
|
||||
identified in status).
|
||||
"""
|
||||
tl_track = context.core.playback.current_tl_track.get()
|
||||
tl_track = context.core.playback.get_current_tl_track().get()
|
||||
stream_title = context.core.playback.get_stream_title().get()
|
||||
if tl_track is not None:
|
||||
position = context.core.tracklist.index(tl_track).get()
|
||||
@ -172,20 +172,20 @@ def status(context):
|
||||
- ``elapsed``: Higher resolution means time in seconds with three
|
||||
decimal places for millisecond precision.
|
||||
"""
|
||||
tl_track = context.core.playback.get_current_tl_track()
|
||||
|
||||
futures = {
|
||||
'tracklist.length': context.core.tracklist.length,
|
||||
'tracklist.version': context.core.tracklist.version,
|
||||
'tracklist.length': context.core.tracklist.get_length(),
|
||||
'tracklist.version': context.core.tracklist.get_version(),
|
||||
'mixer.volume': context.core.mixer.get_volume(),
|
||||
'tracklist.consume': context.core.tracklist.consume,
|
||||
'tracklist.random': context.core.tracklist.random,
|
||||
'tracklist.repeat': context.core.tracklist.repeat,
|
||||
'tracklist.single': context.core.tracklist.single,
|
||||
'playback.state': context.core.playback.state,
|
||||
'playback.current_tl_track': context.core.playback.current_tl_track,
|
||||
'tracklist.index': (
|
||||
context.core.tracklist.index(
|
||||
context.core.playback.current_tl_track.get())),
|
||||
'playback.time_position': context.core.playback.time_position,
|
||||
'tracklist.consume': context.core.tracklist.get_consume(),
|
||||
'tracklist.random': context.core.tracklist.get_random(),
|
||||
'tracklist.repeat': context.core.tracklist.get_repeat(),
|
||||
'tracklist.single': context.core.tracklist.get_single(),
|
||||
'playback.state': context.core.playback.get_state(),
|
||||
'playback.current_tl_track': tl_track,
|
||||
'tracklist.index': context.core.tracklist.index(tl_track.get()),
|
||||
'playback.time_position': context.core.playback.get_time_position(),
|
||||
}
|
||||
pykka.get_all(futures.values())
|
||||
result = [
|
||||
@ -199,6 +199,7 @@ def status(context):
|
||||
('xfade', _status_xfade(futures)),
|
||||
('state', _status_state(futures)),
|
||||
]
|
||||
# TODO: add nextsong and nextsongid
|
||||
if futures['playback.current_tl_track'].get() is not None:
|
||||
result.append(('song', _status_songpos(futures)))
|
||||
result.append(('songid', _status_songid(futures)))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user