Merge branch 'feature/rename-cp-to-tracklist' into develop

Conflicts:
	docs/changes.rst
	mopidy/frontends/mpd/protocol/current_playlist.py
This commit is contained in:
Stein Magnus Jodal 2012-11-13 19:09:18 +01:00
commit dc356a81fd
30 changed files with 599 additions and 604 deletions

View File

@ -43,14 +43,14 @@ every request from a frontend it calls out to one or more backends which does
the real work, and when the backends respond, the core actor is responsible for the real work, and when the backends respond, the core actor is responsible for
combining the responses into a single response to the requesting frontend. combining the responses into a single response to the requesting frontend.
The core actor also keeps track of the current playlist, since it doesn't The core actor also keeps track of the tracklist, since it doesn't belong to a
belong to a specific backend. specific backend.
See :ref:`core-api` for more details. See :ref:`core-api` for more details.
.. digraph:: core_architecture .. digraph:: core_architecture
Core -> "Current\nplaylist\ncontroller" Core -> "Tracklist\ncontroller"
Core -> "Library\ncontroller" Core -> "Library\ncontroller"
Core -> "Playback\ncontroller" Core -> "Playback\ncontroller"
Core -> "Stored\nplaylists\ncontroller" Core -> "Stored\nplaylists\ncontroller"

View File

@ -26,12 +26,12 @@ seek, and volume control.
:members: :members:
Current playlist controller Tracklist controller
=========================== ====================
Manages everything related to the currently loaded playlist. Manages everything related to the tracks we are currently playing.
.. autoclass:: mopidy.core.CurrentPlaylistController .. autoclass:: mopidy.core.TracklistController
:members: :members:

View File

@ -105,6 +105,9 @@ backends:
- The Spotify backend now returns the track if you search for the Spotify track - The Spotify backend now returns the track if you search for the Spotify track
URI. (Fixes: :issue:`233`) URI. (Fixes: :issue:`233`)
- Renamed "current playlist" to "tracklist" everywhere, including the core API
used by frontends.
**Bug fixes** **Bug fixes**
- :issue:`218`: The MPD commands ``listplaylist`` and ``listplaylistinfo`` now - :issue:`218`: The MPD commands ``listplaylist`` and ``listplaylistinfo`` now

View File

@ -2,8 +2,8 @@ from __future__ import unicode_literals
# flake8: noqa # flake8: noqa
from .actor import Core from .actor import Core
from .current_playlist import CurrentPlaylistController
from .library import LibraryController from .library import LibraryController
from .listener import CoreListener from .listener import CoreListener
from .playback import PlaybackController, PlaybackState from .playback import PlaybackController, PlaybackState
from .stored_playlists import StoredPlaylistsController from .stored_playlists import StoredPlaylistsController
from .tracklist import TracklistController

View File

@ -6,17 +6,13 @@ import pykka
from mopidy.audio import AudioListener from mopidy.audio import AudioListener
from .current_playlist import CurrentPlaylistController
from .library import LibraryController from .library import LibraryController
from .playback import PlaybackController from .playback import PlaybackController
from .stored_playlists import StoredPlaylistsController from .stored_playlists import StoredPlaylistsController
from .tracklist import TracklistController
class Core(pykka.ThreadingActor, AudioListener): class Core(pykka.ThreadingActor, AudioListener):
#: The current playlist controller. An instance of
#: :class:`mopidy.core.CurrentPlaylistController`.
current_playlist = None
#: The library controller. An instance of #: The library controller. An instance of
# :class:`mopidy.core.LibraryController`. # :class:`mopidy.core.LibraryController`.
library = None library = None
@ -29,13 +25,15 @@ class Core(pykka.ThreadingActor, AudioListener):
#: :class:`mopidy.core.StoredPlaylistsController`. #: :class:`mopidy.core.StoredPlaylistsController`.
stored_playlists = None stored_playlists = None
#: The tracklist controller. An instance of
#: :class:`mopidy.core.TracklistController`.
tracklist = None
def __init__(self, audio=None, backends=None): def __init__(self, audio=None, backends=None):
super(Core, self).__init__() super(Core, self).__init__()
self.backends = Backends(backends) self.backends = Backends(backends)
self.current_playlist = CurrentPlaylistController(core=self)
self.library = LibraryController(backends=self.backends, core=self) self.library = LibraryController(backends=self.backends, core=self)
self.playback = PlaybackController( self.playback = PlaybackController(
@ -44,6 +42,8 @@ class Core(pykka.ThreadingActor, AudioListener):
self.stored_playlists = StoredPlaylistsController( self.stored_playlists = StoredPlaylistsController(
backends=self.backends, core=self) backends=self.backends, core=self)
self.tracklist = TracklistController(core=self)
@property @property
def uri_schemes(self): def uri_schemes(self):
"""List of URI schemes we can handle""" """List of URI schemes we can handle"""

View File

@ -53,9 +53,9 @@ class PlaybackController(object):
#: The currently playing or selected track. #: The currently playing or selected track.
#: #:
#: A two-tuple of (CPID integer, :class:`mopidy.models.Track`) or #: A two-tuple of (TLID integer, :class:`mopidy.models.Track`) or
#: :class:`None`. #: :class:`None`.
current_cp_track = None current_tl_track = None
#: :class:`True` #: :class:`True`
#: Tracks are selected at random from the playlist. #: Tracks are selected at random from the playlist.
@ -88,53 +88,52 @@ class PlaybackController(object):
self._volume = None self._volume = None
def _get_backend(self): def _get_backend(self):
if self.current_cp_track is None: if self.current_tl_track is None:
return None return None
uri = self.current_cp_track.track.uri uri = self.current_tl_track.track.uri
uri_scheme = urlparse.urlparse(uri).scheme uri_scheme = urlparse.urlparse(uri).scheme
return self.backends.with_playback_by_uri_scheme.get(uri_scheme, None) return self.backends.with_playback_by_uri_scheme.get(uri_scheme, None)
def _get_cpid(self, cp_track): def _get_tlid(self, tl_track):
if cp_track is None: if tl_track is None:
return None return None
return cp_track.cpid return tl_track.tlid
def _get_track(self, cp_track): def _get_track(self, tl_track):
if cp_track is None: if tl_track is None:
return None return None
return cp_track.track return tl_track.track
@property @property
def current_cpid(self): def current_tlid(self):
""" """
The CPID (current playlist ID) of the currently playing or selected The TLID (tracklist ID) of the currently playing or selected
track. track.
Read-only. Extracted from :attr:`current_cp_track` for convenience. Read-only. Extracted from :attr:`current_tl_track` for convenience.
""" """
return self._get_cpid(self.current_cp_track) return self._get_tlid(self.current_tl_track)
@property @property
def current_track(self): def current_track(self):
""" """
The currently playing or selected :class:`mopidy.models.Track`. The currently playing or selected :class:`mopidy.models.Track`.
Read-only. Extracted from :attr:`current_cp_track` for convenience. Read-only. Extracted from :attr:`current_tl_track` for convenience.
""" """
return self._get_track(self.current_cp_track) return self._get_track(self.current_tl_track)
@property @property
def current_playlist_position(self): def tracklist_position(self):
""" """
The position of the current track in the current playlist. The position of the current track in the tracklist.
Read-only. Read-only.
""" """
if self.current_cp_track is None: if self.current_tl_track is None:
return None return None
try: try:
return self.core.current_playlist.cp_tracks.index( return self.core.tracklist.tl_tracks.index(self.current_tl_track)
self.current_cp_track)
except ValueError: except ValueError:
return None return None
@ -144,49 +143,48 @@ class PlaybackController(object):
The track that will be played at the end of the current track. The track that will be played at the end of the current track.
Read-only. A :class:`mopidy.models.Track` extracted from Read-only. A :class:`mopidy.models.Track` extracted from
:attr:`cp_track_at_eot` for convenience. :attr:`tl_track_at_eot` for convenience.
""" """
return self._get_track(self.cp_track_at_eot) return self._get_track(self.tl_track_at_eot)
@property @property
def cp_track_at_eot(self): def tl_track_at_eot(self):
""" """
The track that will be played at the end of the current track. The track that will be played at the end of the current track.
Read-only. A two-tuple of (CPID integer, :class:`mopidy.models.Track`). Read-only. A two-tuple of (TLID integer, :class:`mopidy.models.Track`).
Not necessarily the same track as :attr:`cp_track_at_next`. Not necessarily the same track as :attr:`tl_track_at_next`.
""" """
# pylint: disable = R0911 # pylint: disable = R0911
# Too many return statements # Too many return statements
cp_tracks = self.core.current_playlist.cp_tracks tl_tracks = self.core.tracklist.tl_tracks
if not cp_tracks: if not tl_tracks:
return None return None
if self.random and not self._shuffled: if self.random and not self._shuffled:
if self.repeat or self._first_shuffle: if self.repeat or self._first_shuffle:
logger.debug('Shuffling tracks') logger.debug('Shuffling tracks')
self._shuffled = cp_tracks self._shuffled = tl_tracks
random.shuffle(self._shuffled) random.shuffle(self._shuffled)
self._first_shuffle = False self._first_shuffle = False
if self.random and self._shuffled: if self.random and self._shuffled:
return self._shuffled[0] return self._shuffled[0]
if self.current_cp_track is None: if self.current_tl_track is None:
return cp_tracks[0] return tl_tracks[0]
if self.repeat and self.single: if self.repeat and self.single:
return cp_tracks[self.current_playlist_position] return tl_tracks[self.tracklist_position]
if self.repeat and not self.single: if self.repeat and not self.single:
return cp_tracks[ return tl_tracks[(self.tracklist_position + 1) % len(tl_tracks)]
(self.current_playlist_position + 1) % len(cp_tracks)]
try: try:
return cp_tracks[self.current_playlist_position + 1] return tl_tracks[self.tracklist_position + 1]
except IndexError: except IndexError:
return None return None
@ -196,46 +194,45 @@ class PlaybackController(object):
The track that will be played if calling :meth:`next()`. The track that will be played if calling :meth:`next()`.
Read-only. A :class:`mopidy.models.Track` extracted from Read-only. A :class:`mopidy.models.Track` extracted from
:attr:`cp_track_at_next` for convenience. :attr:`tl_track_at_next` for convenience.
""" """
return self._get_track(self.cp_track_at_next) return self._get_track(self.tl_track_at_next)
@property @property
def cp_track_at_next(self): def tl_track_at_next(self):
""" """
The track that will be played if calling :meth:`next()`. The track that will be played if calling :meth:`next()`.
Read-only. A two-tuple of (CPID integer, :class:`mopidy.models.Track`). Read-only. A two-tuple of (TLID integer, :class:`mopidy.models.Track`).
For normal playback this is the next track in the playlist. If repeat For normal playback this is the next track in the playlist. If repeat
is enabled the next track can loop around the playlist. When random is is enabled the next track can loop around the playlist. When random is
enabled this should be a random track, all tracks should be played once enabled this should be a random track, all tracks should be played once
before the list repeats. before the list repeats.
""" """
cp_tracks = self.core.current_playlist.cp_tracks tl_tracks = self.core.tracklist.tl_tracks
if not cp_tracks: if not tl_tracks:
return None return None
if self.random and not self._shuffled: if self.random and not self._shuffled:
if self.repeat or self._first_shuffle: if self.repeat or self._first_shuffle:
logger.debug('Shuffling tracks') logger.debug('Shuffling tracks')
self._shuffled = cp_tracks self._shuffled = tl_tracks
random.shuffle(self._shuffled) random.shuffle(self._shuffled)
self._first_shuffle = False self._first_shuffle = False
if self.random and self._shuffled: if self.random and self._shuffled:
return self._shuffled[0] return self._shuffled[0]
if self.current_cp_track is None: if self.current_tl_track is None:
return cp_tracks[0] return tl_tracks[0]
if self.repeat: if self.repeat:
return cp_tracks[ return tl_tracks[(self.tracklist_position + 1) % len(tl_tracks)]
(self.current_playlist_position + 1) % len(cp_tracks)]
try: try:
return cp_tracks[self.current_playlist_position + 1] return tl_tracks[self.tracklist_position + 1]
except IndexError: except IndexError:
return None return None
@ -245,29 +242,28 @@ class PlaybackController(object):
The track that will be played if calling :meth:`previous()`. The track that will be played if calling :meth:`previous()`.
Read-only. A :class:`mopidy.models.Track` extracted from Read-only. A :class:`mopidy.models.Track` extracted from
:attr:`cp_track_at_previous` for convenience. :attr:`tl_track_at_previous` for convenience.
""" """
return self._get_track(self.cp_track_at_previous) return self._get_track(self.tl_track_at_previous)
@property @property
def cp_track_at_previous(self): def tl_track_at_previous(self):
""" """
The track that will be played if calling :meth:`previous()`. The track that will be played if calling :meth:`previous()`.
A two-tuple of (CPID integer, :class:`mopidy.models.Track`). A two-tuple of (TLID integer, :class:`mopidy.models.Track`).
For normal playback this is the previous track in the playlist. If For normal playback this is the previous track in the playlist. If
random and/or consume is enabled it should return the current track random and/or consume is enabled it should return the current track
instead. instead.
""" """
if self.repeat or self.consume or self.random: if self.repeat or self.consume or self.random:
return self.current_cp_track return self.current_tl_track
if self.current_playlist_position in (None, 0): if self.tracklist_position in (None, 0):
return None return None
return self.core.current_playlist.cp_tracks[ return self.core.tracklist.tl_tracks[self.tracklist_position - 1]
self.current_playlist_position - 1]
@property @property
def state(self): def state(self):
@ -322,12 +318,12 @@ class PlaybackController(object):
# For testing # For testing
self._volume = volume self._volume = volume
def change_track(self, cp_track, on_error_step=1): def change_track(self, tl_track, on_error_step=1):
""" """
Change to the given track, keeping the current playback state. Change to the given track, keeping the current playback state.
:param cp_track: track to change to :param tl_track: track to change to
:type cp_track: two-tuple (CPID integer, :class:`mopidy.models.Track`) :type tl_track: two-tuple (TLID integer, :class:`mopidy.models.Track`)
or :class:`None` or :class:`None`
:param on_error_step: direction to step at play error, 1 for next :param on_error_step: direction to step at play error, 1 for next
track (default), -1 for previous track track (default), -1 for previous track
@ -336,7 +332,7 @@ class PlaybackController(object):
""" """
old_state = self.state old_state = self.state
self.stop() self.stop()
self.current_cp_track = cp_track self.current_tl_track = tl_track
if old_state == PlaybackState.PLAYING: if old_state == PlaybackState.PLAYING:
self.play(on_error_step=on_error_step) self.play(on_error_step=on_error_step)
elif old_state == PlaybackState.PAUSED: elif old_state == PlaybackState.PAUSED:
@ -349,18 +345,18 @@ class PlaybackController(object):
if self.state == PlaybackState.STOPPED: if self.state == PlaybackState.STOPPED:
return return
original_cp_track = self.current_cp_track original_tl_track = self.current_tl_track
if self.cp_track_at_eot: if self.tl_track_at_eot:
self._trigger_track_playback_ended() self._trigger_track_playback_ended()
self.play(self.cp_track_at_eot) self.play(self.tl_track_at_eot)
else: else:
self.stop(clear_current_track=True) self.stop(clear_current_track=True)
if self.consume: if self.consume:
self.core.current_playlist.remove(cpid=original_cp_track.cpid) self.core.tracklist.remove(tlid=original_tl_track.tlid)
def on_current_playlist_change(self): def on_tracklist_change(self):
""" """
Tell the playback controller that the current playlist has changed. Tell the playback controller that the current playlist has changed.
@ -369,9 +365,9 @@ class PlaybackController(object):
self._first_shuffle = True self._first_shuffle = True
self._shuffled = [] self._shuffled = []
if (not self.core.current_playlist.cp_tracks or if (not self.core.tracklist.tl_tracks or
self.current_cp_track not in self.current_tl_track not in
self.core.current_playlist.cp_tracks): self.core.tracklist.tl_tracks):
self.stop(clear_current_track=True) self.stop(clear_current_track=True)
def next(self): def next(self):
@ -381,9 +377,9 @@ class PlaybackController(object):
The current playback state will be kept. If it was playing, playing The current playback state will be kept. If it was playing, playing
will continue. If it was paused, it will still be paused, etc. will continue. If it was paused, it will still be paused, etc.
""" """
if self.cp_track_at_next: if self.tl_track_at_next:
self._trigger_track_playback_ended() self._trigger_track_playback_ended()
self.change_track(self.cp_track_at_next) self.change_track(self.tl_track_at_next)
else: else:
self.stop(clear_current_track=True) self.stop(clear_current_track=True)
@ -394,46 +390,46 @@ class PlaybackController(object):
self.state = PlaybackState.PAUSED self.state = PlaybackState.PAUSED
self._trigger_track_playback_paused() self._trigger_track_playback_paused()
def play(self, cp_track=None, on_error_step=1): def play(self, tl_track=None, on_error_step=1):
""" """
Play the given track, or if the given track is :class:`None`, play the Play the given track, or if the given track is :class:`None`, play the
currently active track. currently active track.
:param cp_track: track to play :param tl_track: track to play
:type cp_track: two-tuple (CPID integer, :class:`mopidy.models.Track`) :type tl_track: two-tuple (TLID integer, :class:`mopidy.models.Track`)
or :class:`None` or :class:`None`
:param on_error_step: direction to step at play error, 1 for next :param on_error_step: direction to step at play error, 1 for next
track (default), -1 for previous track track (default), -1 for previous track
:type on_error_step: int, -1 or 1 :type on_error_step: int, -1 or 1
""" """
if cp_track is not None: if tl_track is not None:
assert cp_track in self.core.current_playlist.cp_tracks assert tl_track in self.core.tracklist.tl_tracks
elif cp_track is None: elif tl_track is None:
if self.state == PlaybackState.PAUSED: if self.state == PlaybackState.PAUSED:
return self.resume() return self.resume()
elif self.current_cp_track is not None: elif self.current_tl_track is not None:
cp_track = self.current_cp_track tl_track = self.current_tl_track
elif self.current_cp_track is None and on_error_step == 1: elif self.current_tl_track is None and on_error_step == 1:
cp_track = self.cp_track_at_next tl_track = self.tl_track_at_next
elif self.current_cp_track is None and on_error_step == -1: elif self.current_tl_track is None and on_error_step == -1:
cp_track = self.cp_track_at_previous tl_track = self.tl_track_at_previous
if cp_track is not None: if tl_track is not None:
self.current_cp_track = cp_track self.current_tl_track = tl_track
self.state = PlaybackState.PLAYING self.state = PlaybackState.PLAYING
backend = self._get_backend() backend = self._get_backend()
if not backend or not backend.playback.play(cp_track.track).get(): if not backend or not backend.playback.play(tl_track.track).get():
# Track is not playable # Track is not playable
if self.random and self._shuffled: if self.random and self._shuffled:
self._shuffled.remove(cp_track) self._shuffled.remove(tl_track)
if on_error_step == 1: if on_error_step == 1:
self.next() self.next()
elif on_error_step == -1: elif on_error_step == -1:
self.previous() self.previous()
if self.random and self.current_cp_track in self._shuffled: if self.random and self.current_tl_track in self._shuffled:
self._shuffled.remove(self.current_cp_track) self._shuffled.remove(self.current_tl_track)
self._trigger_track_playback_started() self._trigger_track_playback_started()
@ -445,7 +441,7 @@ class PlaybackController(object):
will continue. If it was paused, it will still be paused, etc. will continue. If it was paused, it will still be paused, etc.
""" """
self._trigger_track_playback_ended() self._trigger_track_playback_ended()
self.change_track(self.cp_track_at_previous, on_error_step=-1) self.change_track(self.tl_track_at_previous, on_error_step=-1)
def resume(self): def resume(self):
"""If paused, resume playing the current track.""" """If paused, resume playing the current track."""
@ -464,7 +460,7 @@ class PlaybackController(object):
:type time_position: int :type time_position: int
:rtype: :class:`True` if successful, else :class:`False` :rtype: :class:`True` if successful, else :class:`False`
""" """
if not self.core.current_playlist.tracks: if not self.core.tracklist.tracks:
return False return False
if self.state == PlaybackState.STOPPED: if self.state == PlaybackState.STOPPED:
@ -501,7 +497,7 @@ class PlaybackController(object):
self._trigger_track_playback_ended() self._trigger_track_playback_ended()
self.state = PlaybackState.STOPPED self.state = PlaybackState.STOPPED
if clear_current_track: if clear_current_track:
self.current_cp_track = None self.current_tl_track = None
def _trigger_track_playback_paused(self): def _trigger_track_playback_paused(self):
logger.debug('Triggering track playback paused event') logger.debug('Triggering track playback paused event')

View File

@ -4,7 +4,7 @@ from copy import copy
import logging import logging
import random import random
from mopidy.models import CpTrack from mopidy.models import TlTrack
from . import listener from . import listener
@ -12,23 +12,23 @@ from . import listener
logger = logging.getLogger('mopidy.core') logger = logging.getLogger('mopidy.core')
class CurrentPlaylistController(object): class TracklistController(object):
pykka_traversable = True pykka_traversable = True
def __init__(self, core): def __init__(self, core):
self.core = core self.core = core
self.cp_id = 0 self.tlid = 0
self._cp_tracks = [] self._tl_tracks = []
self._version = 0 self._version = 0
@property @property
def cp_tracks(self): def tl_tracks(self):
""" """
List of two-tuples of (CPID integer, :class:`mopidy.models.Track`). List of two-tuples of (TLID integer, :class:`mopidy.models.Track`).
Read-only. Read-only.
""" """
return [copy(cp_track) for cp_track in self._cp_tracks] return [copy(tl_track) for tl_track in self._tl_tracks]
@property @property
def tracks(self): def tracks(self):
@ -37,14 +37,14 @@ class CurrentPlaylistController(object):
Read-only. Read-only.
""" """
return [cp_track.track for cp_track in self._cp_tracks] return [tl_track.track for tl_track in self._tl_tracks]
@property @property
def length(self): def length(self):
""" """
Length of the current playlist. Length of the current playlist.
""" """
return len(self._cp_tracks) return len(self._tl_tracks)
@property @property
def version(self): def version(self):
@ -57,7 +57,7 @@ class CurrentPlaylistController(object):
@version.setter # noqa @version.setter # noqa
def version(self, version): def version(self, version):
self._version = version self._version = version
self.core.playback.on_current_playlist_change() self.core.playback.on_tracklist_change()
self._trigger_playlist_changed() self._trigger_playlist_changed()
def add(self, track, at_position=None, increase_version=True): def add(self, track, at_position=None, increase_version=True):
@ -71,20 +71,20 @@ class CurrentPlaylistController(object):
:type at_position: int or :class:`None` :type at_position: int or :class:`None`
:param increase_version: if the playlist version should be increased :param increase_version: if the playlist version should be increased
:type increase_version: :class:`True` or :class:`False` :type increase_version: :class:`True` or :class:`False`
:rtype: two-tuple of (CPID integer, :class:`mopidy.models.Track`) that :rtype: two-tuple of (TLID integer, :class:`mopidy.models.Track`) that
was added to the current playlist playlist was added to the current playlist playlist
""" """
assert at_position <= len(self._cp_tracks), \ assert at_position <= len(self._tl_tracks), \
'at_position can not be greater than playlist length' 'at_position can not be greater than playlist length'
cp_track = CpTrack(self.cp_id, track) tl_track = TlTrack(self.tlid, track)
if at_position is not None: if at_position is not None:
self._cp_tracks.insert(at_position, cp_track) self._tl_tracks.insert(at_position, tl_track)
else: else:
self._cp_tracks.append(cp_track) self._tl_tracks.append(tl_track)
if increase_version: if increase_version:
self.version += 1 self.version += 1
self.cp_id += 1 self.tlid += 1
return cp_track return tl_track
def append(self, tracks): def append(self, tracks):
""" """
@ -101,7 +101,7 @@ class CurrentPlaylistController(object):
def clear(self): def clear(self):
"""Clear the current playlist.""" """Clear the current playlist."""
self._cp_tracks = [] self._tl_tracks = []
self.version += 1 self.version += 1
def get(self, **criteria): def get(self, **criteria):
@ -112,7 +112,7 @@ class CurrentPlaylistController(object):
Examples:: Examples::
get(cpid=7) # Returns track with CPID 7 get(tlid=7) # Returns track with TLID 7
# (current playlist ID) # (current playlist ID)
get(id=1) # Returns track with ID 1 get(id=1) # Returns track with ID 1
get(uri='xyz') # Returns track with URI 'xyz' get(uri='xyz') # Returns track with URI 'xyz'
@ -120,12 +120,12 @@ class CurrentPlaylistController(object):
:param criteria: on or more criteria to match by :param criteria: on or more criteria to match by
:type criteria: dict :type criteria: dict
:rtype: two-tuple (CPID integer, :class:`mopidy.models.Track`) :rtype: two-tuple (TLID integer, :class:`mopidy.models.Track`)
""" """
matches = self._cp_tracks matches = self._tl_tracks
for (key, value) in criteria.iteritems(): for (key, value) in criteria.iteritems():
if key == 'cpid': if key == 'tlid':
matches = filter(lambda ct: ct.cpid == value, matches) matches = filter(lambda ct: ct.tlid == value, matches)
else: else:
matches = filter( matches = filter(
lambda ct: getattr(ct.track, key) == value, matches) lambda ct: getattr(ct.track, key) == value, matches)
@ -138,18 +138,18 @@ class CurrentPlaylistController(object):
else: else:
raise LookupError('"%s" match multiple tracks' % criteria_string) raise LookupError('"%s" match multiple tracks' % criteria_string)
def index(self, cp_track): def index(self, tl_track):
""" """
Get index of the given (CPID integer, :class:`mopidy.models.Track`) Get index of the given (TLID integer, :class:`mopidy.models.Track`)
two-tuple in the current playlist. two-tuple in the current playlist.
Raises :exc:`ValueError` if not found. Raises :exc:`ValueError` if not found.
:param cp_track: track to find the index of :param tl_track: track to find the index of
:type cp_track: two-tuple (CPID integer, :class:`mopidy.models.Track`) :type tl_track: two-tuple (TLID integer, :class:`mopidy.models.Track`)
:rtype: int :rtype: int
""" """
return self._cp_tracks.index(cp_track) return self._tl_tracks.index(tl_track)
def move(self, start, end, to_position): def move(self, start, end, to_position):
""" """
@ -165,21 +165,21 @@ class CurrentPlaylistController(object):
if start == end: if start == end:
end += 1 end += 1
cp_tracks = self._cp_tracks tl_tracks = self._tl_tracks
assert start < end, 'start must be smaller than end' assert start < end, 'start must be smaller than end'
assert start >= 0, 'start must be at least zero' assert start >= 0, 'start must be at least zero'
assert end <= len(cp_tracks), \ assert end <= len(tl_tracks), \
'end can not be larger than playlist length' 'end can not be larger than playlist length'
assert to_position >= 0, 'to_position must be at least zero' assert to_position >= 0, 'to_position must be at least zero'
assert to_position <= len(cp_tracks), \ assert to_position <= len(tl_tracks), \
'to_position can not be larger than playlist length' 'to_position can not be larger than playlist length'
new_cp_tracks = cp_tracks[:start] + cp_tracks[end:] new_tl_tracks = tl_tracks[:start] + tl_tracks[end:]
for cp_track in cp_tracks[start:end]: for tl_track in tl_tracks[start:end]:
new_cp_tracks.insert(to_position, cp_track) new_tl_tracks.insert(to_position, tl_track)
to_position += 1 to_position += 1
self._cp_tracks = new_cp_tracks self._tl_tracks = new_tl_tracks
self.version += 1 self.version += 1
def remove(self, **criteria): def remove(self, **criteria):
@ -191,9 +191,9 @@ class CurrentPlaylistController(object):
:param criteria: on or more criteria to match by :param criteria: on or more criteria to match by
:type criteria: dict :type criteria: dict
""" """
cp_track = self.get(**criteria) tl_track = self.get(**criteria)
position = self._cp_tracks.index(cp_track) position = self._tl_tracks.index(tl_track)
del self._cp_tracks[position] del self._tl_tracks[position]
self.version += 1 self.version += 1
def shuffle(self, start=None, end=None): def shuffle(self, start=None, end=None):
@ -206,7 +206,7 @@ class CurrentPlaylistController(object):
:param end: position after last track to shuffle :param end: position after last track to shuffle
:type end: int or :class:`None` :type end: int or :class:`None`
""" """
cp_tracks = self._cp_tracks tl_tracks = self._tl_tracks
if start is not None and end is not None: if start is not None and end is not None:
assert start < end, 'start must be smaller than end' assert start < end, 'start must be smaller than end'
@ -215,14 +215,14 @@ class CurrentPlaylistController(object):
assert start >= 0, 'start must be at least zero' assert start >= 0, 'start must be at least zero'
if end is not None: if end is not None:
assert end <= len(cp_tracks), 'end can not be larger than ' + \ assert end <= len(tl_tracks), 'end can not be larger than ' + \
'playlist length' 'playlist length'
before = cp_tracks[:start or 0] before = tl_tracks[:start or 0]
shuffled = cp_tracks[start:end] shuffled = tl_tracks[start:end]
after = cp_tracks[end or len(cp_tracks):] after = tl_tracks[end or len(tl_tracks):]
random.shuffle(shuffled) random.shuffle(shuffled)
self._cp_tracks = before + shuffled + after self._tl_tracks = before + shuffled + after
self.version += 1 self.version += 1
def slice(self, start, end): def slice(self, start, end):
@ -234,9 +234,9 @@ class CurrentPlaylistController(object):
:type start: int :type start: int
:param end: position after last track to include in slice :param end: position after last track to include in slice
:type end: int :type end: int
:rtype: two-tuple of (CPID integer, :class:`mopidy.models.Track`) :rtype: two-tuple of (TLID integer, :class:`mopidy.models.Track`)
""" """
return [copy(cp_track) for cp_track in self._cp_tracks[start:end]] return [copy(tl_track) for tl_track in self._tl_tracks[start:end]]
def _trigger_playlist_changed(self): def _trigger_playlist_changed(self):
logger.debug('Triggering playlist changed event') logger.debug('Triggering playlist changed event')

View File

@ -24,7 +24,7 @@ def add(context, uri):
return return
track = context.core.library.lookup(uri).get() track = context.core.library.lookup(uri).get()
if track: if track:
context.core.current_playlist.add(track) context.core.tracklist.add(track)
return return
raise MpdNoExistError('directory or file not found', command='add') raise MpdNoExistError('directory or file not found', command='add')
@ -55,11 +55,10 @@ def addid(context, uri, songpos=None):
track = context.core.library.lookup(uri).get() track = context.core.library.lookup(uri).get()
if track is None: if track is None:
raise MpdNoExistError('No such song', command='addid') raise MpdNoExistError('No such song', command='addid')
if songpos and songpos > context.core.current_playlist.length.get(): if songpos and songpos > context.core.tracklist.length.get():
raise MpdArgError('Bad song index', command='addid') raise MpdArgError('Bad song index', command='addid')
cp_track = context.core.current_playlist.add( tl_track = context.core.tracklist.add(track, at_position=songpos).get()
track, at_position=songpos).get() return ('Id', tl_track.tlid)
return ('Id', cp_track.cpid)
@handle_request(r'^delete "(?P<start>\d+):(?P<end>\d+)*"$') @handle_request(r'^delete "(?P<start>\d+):(?P<end>\d+)*"$')
@ -75,12 +74,12 @@ def delete_range(context, start, end=None):
if end is not None: if end is not None:
end = int(end) end = int(end)
else: else:
end = context.core.current_playlist.length.get() end = context.core.tracklist.length.get()
cp_tracks = context.core.current_playlist.slice(start, end).get() tl_tracks = context.core.tracklist.slice(start, end).get()
if not cp_tracks: if not tl_tracks:
raise MpdArgError('Bad song index', command='delete') raise MpdArgError('Bad song index', command='delete')
for (cpid, _) in cp_tracks: for (tlid, _) in tl_tracks:
context.core.current_playlist.remove(cpid=cpid) context.core.tracklist.remove(tlid=tlid)
@handle_request(r'^delete "(?P<songpos>\d+)"$') @handle_request(r'^delete "(?P<songpos>\d+)"$')
@ -88,15 +87,15 @@ def delete_songpos(context, songpos):
"""See :meth:`delete_range`""" """See :meth:`delete_range`"""
try: try:
songpos = int(songpos) songpos = int(songpos)
(cpid, _) = context.core.current_playlist.slice( (tlid, _) = context.core.tracklist.slice(
songpos, songpos + 1).get()[0] songpos, songpos + 1).get()[0]
context.core.current_playlist.remove(cpid=cpid) context.core.tracklist.remove(tlid=tlid)
except IndexError: except IndexError:
raise MpdArgError('Bad song index', command='delete') raise MpdArgError('Bad song index', command='delete')
@handle_request(r'^deleteid "(?P<cpid>\d+)"$') @handle_request(r'^deleteid "(?P<tlid>\d+)"$')
def deleteid(context, cpid): def deleteid(context, tlid):
""" """
*musicpd.org, current playlist section:* *musicpd.org, current playlist section:*
@ -105,10 +104,10 @@ def deleteid(context, cpid):
Deletes the song ``SONGID`` from the playlist Deletes the song ``SONGID`` from the playlist
""" """
try: try:
cpid = int(cpid) tlid = int(tlid)
if context.core.playback.current_cpid.get() == cpid: if context.core.playback.current_tlid.get() == tlid:
context.core.playback.next() context.core.playback.next()
return context.core.current_playlist.remove(cpid=cpid).get() return context.core.tracklist.remove(tlid=tlid).get()
except LookupError: except LookupError:
raise MpdNoExistError('No such song', command='deleteid') raise MpdNoExistError('No such song', command='deleteid')
@ -122,7 +121,7 @@ def clear(context):
Clears the current playlist. Clears the current playlist.
""" """
context.core.current_playlist.clear() context.core.tracklist.clear()
@handle_request(r'^move "(?P<start>\d+):(?P<end>\d+)*" "(?P<to>\d+)"$') @handle_request(r'^move "(?P<start>\d+):(?P<end>\d+)*" "(?P<to>\d+)"$')
@ -136,11 +135,11 @@ def move_range(context, start, to, end=None):
``TO`` in the playlist. ``TO`` in the playlist.
""" """
if end is None: if end is None:
end = context.core.current_playlist.length.get() end = context.core.tracklist.length.get()
start = int(start) start = int(start)
end = int(end) end = int(end)
to = int(to) to = int(to)
context.core.current_playlist.move(start, end, to) context.core.tracklist.move(start, end, to)
@handle_request(r'^move "(?P<songpos>\d+)" "(?P<to>\d+)"$') @handle_request(r'^move "(?P<songpos>\d+)" "(?P<to>\d+)"$')
@ -148,11 +147,11 @@ def move_songpos(context, songpos, to):
"""See :meth:`move_range`.""" """See :meth:`move_range`."""
songpos = int(songpos) songpos = int(songpos)
to = int(to) to = int(to)
context.core.current_playlist.move(songpos, songpos + 1, to) context.core.tracklist.move(songpos, songpos + 1, to)
@handle_request(r'^moveid "(?P<cpid>\d+)" "(?P<to>\d+)"$') @handle_request(r'^moveid "(?P<tlid>\d+)" "(?P<to>\d+)"$')
def moveid(context, cpid, to): def moveid(context, tlid, to):
""" """
*musicpd.org, current playlist section:* *musicpd.org, current playlist section:*
@ -162,11 +161,11 @@ def moveid(context, cpid, to):
the playlist. If ``TO`` is negative, it is relative to the current the playlist. If ``TO`` is negative, it is relative to the current
song in the playlist (if there is one). song in the playlist (if there is one).
""" """
cpid = int(cpid) tlid = int(tlid)
to = int(to) to = int(to)
cp_track = context.core.current_playlist.get(cpid=cpid).get() tl_track = context.core.tracklist.get(tlid=tlid).get()
position = context.core.current_playlist.index(cp_track).get() position = context.core.tracklist.index(tl_track).get()
context.core.current_playlist.move(position, position + 1, to) context.core.tracklist.move(position, position + 1, to)
@handle_request(r'^playlist$') @handle_request(r'^playlist$')
@ -201,16 +200,16 @@ def playlistfind(context, tag, needle):
""" """
if tag == 'filename': if tag == 'filename':
try: try:
cp_track = context.core.current_playlist.get(uri=needle).get() tl_track = context.core.tracklist.get(uri=needle).get()
position = context.core.current_playlist.index(cp_track).get() position = context.core.tracklist.index(tl_track).get()
return translator.track_to_mpd_format(cp_track, position=position) return translator.track_to_mpd_format(tl_track, position=position)
except LookupError: except LookupError:
return None return None
raise MpdNotImplemented # TODO raise MpdNotImplemented # TODO
@handle_request(r'^playlistid( "(?P<cpid>\d+)")*$') @handle_request(r'^playlistid( "(?P<tlid>\d+)")*$')
def playlistid(context, cpid=None): def playlistid(context, tlid=None):
""" """
*musicpd.org, current playlist section:* *musicpd.org, current playlist section:*
@ -219,17 +218,17 @@ def playlistid(context, cpid=None):
Displays a list of songs in the playlist. ``SONGID`` is optional Displays a list of songs in the playlist. ``SONGID`` is optional
and specifies a single song to display info for. and specifies a single song to display info for.
""" """
if cpid is not None: if tlid is not None:
try: try:
cpid = int(cpid) tlid = int(tlid)
cp_track = context.core.current_playlist.get(cpid=cpid).get() tl_track = context.core.tracklist.get(tlid=tlid).get()
position = context.core.current_playlist.index(cp_track).get() position = context.core.tracklist.index(tl_track).get()
return translator.track_to_mpd_format(cp_track, position=position) return translator.track_to_mpd_format(tl_track, position=position)
except LookupError: except LookupError:
raise MpdNoExistError('No such song', command='playlistid') raise MpdNoExistError('No such song', command='playlistid')
else: else:
return translator.tracks_to_mpd_format( return translator.tracks_to_mpd_format(
context.core.current_playlist.cp_tracks.get()) context.core.tracklist.tl_tracks.get())
@handle_request(r'^playlistinfo$') @handle_request(r'^playlistinfo$')
@ -253,20 +252,20 @@ def playlistinfo(context, songpos=None, start=None, end=None):
""" """
if songpos is not None: if songpos is not None:
songpos = int(songpos) songpos = int(songpos)
cp_track = context.core.current_playlist.cp_tracks.get()[songpos] tl_track = context.core.tracklist.tl_tracks.get()[songpos]
return translator.track_to_mpd_format(cp_track, position=songpos) return translator.track_to_mpd_format(tl_track, position=songpos)
else: else:
if start is None: if start is None:
start = 0 start = 0
start = int(start) start = int(start)
if not (0 <= start <= context.core.current_playlist.length.get()): if not (0 <= start <= context.core.tracklist.length.get()):
raise MpdArgError('Bad song index', command='playlistinfo') raise MpdArgError('Bad song index', command='playlistinfo')
if end is not None: if end is not None:
end = int(end) end = int(end)
if end > context.core.current_playlist.length.get(): if end > context.core.tracklist.length.get():
end = None end = None
cp_tracks = context.core.current_playlist.cp_tracks.get() tl_tracks = context.core.tracklist.tl_tracks.get()
return translator.tracks_to_mpd_format(cp_tracks, start, end) return translator.tracks_to_mpd_format(tl_tracks, start, end)
@handle_request(r'^playlistsearch "(?P<tag>[^"]+)" "(?P<needle>[^"]+)"$') @handle_request(r'^playlistsearch "(?P<tag>[^"]+)" "(?P<needle>[^"]+)"$')
@ -306,9 +305,9 @@ def plchanges(context, version):
- Calls ``plchanges "-1"`` two times per second to get the entire playlist. - Calls ``plchanges "-1"`` two times per second to get the entire playlist.
""" """
# XXX Naive implementation that returns all tracks as changed # XXX Naive implementation that returns all tracks as changed
if int(version) < context.core.current_playlist.version.get(): if int(version) < context.core.tracklist.version.get():
return translator.tracks_to_mpd_format( return translator.tracks_to_mpd_format(
context.core.current_playlist.cp_tracks.get()) context.core.tracklist.tl_tracks.get())
@handle_request(r'^plchangesposid "(?P<version>\d+)"$') @handle_request(r'^plchangesposid "(?P<version>\d+)"$')
@ -326,12 +325,12 @@ def plchangesposid(context, version):
``playlistlength`` returned by status command. ``playlistlength`` returned by status command.
""" """
# XXX Naive implementation that returns all tracks as changed # XXX Naive implementation that returns all tracks as changed
if int(version) != context.core.current_playlist.version.get(): if int(version) != context.core.tracklist.version.get():
result = [] result = []
for (position, (cpid, _)) in enumerate( for (position, (tlid, _)) in enumerate(
context.core.current_playlist.cp_tracks.get()): context.core.tracklist.tl_tracks.get()):
result.append(('cpos', position)) result.append(('cpos', position))
result.append(('Id', cpid)) result.append(('Id', tlid))
return result return result
@ -350,7 +349,7 @@ def shuffle(context, start=None, end=None):
start = int(start) start = int(start)
if end is not None: if end is not None:
end = int(end) end = int(end)
context.core.current_playlist.shuffle(start, end) context.core.tracklist.shuffle(start, end)
@handle_request(r'^swap "(?P<songpos1>\d+)" "(?P<songpos2>\d+)"$') @handle_request(r'^swap "(?P<songpos1>\d+)" "(?P<songpos2>\d+)"$')
@ -364,19 +363,19 @@ def swap(context, songpos1, songpos2):
""" """
songpos1 = int(songpos1) songpos1 = int(songpos1)
songpos2 = int(songpos2) songpos2 = int(songpos2)
tracks = context.core.current_playlist.tracks.get() tracks = context.core.tracklist.tracks.get()
song1 = tracks[songpos1] song1 = tracks[songpos1]
song2 = tracks[songpos2] song2 = tracks[songpos2]
del tracks[songpos1] del tracks[songpos1]
tracks.insert(songpos1, song2) tracks.insert(songpos1, song2)
del tracks[songpos2] del tracks[songpos2]
tracks.insert(songpos2, song1) tracks.insert(songpos2, song1)
context.core.current_playlist.clear() context.core.tracklist.clear()
context.core.current_playlist.append(tracks) context.core.tracklist.append(tracks)
@handle_request(r'^swapid "(?P<cpid1>\d+)" "(?P<cpid2>\d+)"$') @handle_request(r'^swapid "(?P<tlid1>\d+)" "(?P<tlid2>\d+)"$')
def swapid(context, cpid1, cpid2): def swapid(context, tlid1, tlid2):
""" """
*musicpd.org, current playlist section:* *musicpd.org, current playlist section:*
@ -384,10 +383,10 @@ def swapid(context, cpid1, cpid2):
Swaps the positions of ``SONG1`` and ``SONG2`` (both song ids). Swaps the positions of ``SONG1`` and ``SONG2`` (both song ids).
""" """
cpid1 = int(cpid1) tlid1 = int(tlid1)
cpid2 = int(cpid2) tlid2 = int(tlid2)
cp_track1 = context.core.current_playlist.get(cpid=cpid1).get() tl_track1 = context.core.tracklist.get(tlid=tlid1).get()
cp_track2 = context.core.current_playlist.get(cpid=cpid2).get() tl_track2 = context.core.tracklist.get(tlid=tlid2).get()
position1 = context.core.current_playlist.index(cp_track1).get() position1 = context.core.tracklist.index(tl_track1).get()
position2 = context.core.current_playlist.index(cp_track2).get() position2 = context.core.tracklist.index(tl_track2).get()
swap(context, position1, position2) swap(context, position1, position2)

View File

@ -129,9 +129,9 @@ def play(context):
return context.core.playback.play().get() return context.core.playback.play().get()
@handle_request(r'^playid (?P<cpid>-?\d+)$') @handle_request(r'^playid (?P<tlid>-?\d+)$')
@handle_request(r'^playid "(?P<cpid>-?\d+)"$') @handle_request(r'^playid "(?P<tlid>-?\d+)"$')
def playid(context, cpid): def playid(context, tlid):
""" """
*musicpd.org, playback section:* *musicpd.org, playback section:*
@ -148,12 +148,12 @@ def playid(context, cpid):
- ``playid "-1"`` when stopped without a current track, e.g. after playlist - ``playid "-1"`` when stopped without a current track, e.g. after playlist
replacement, starts playback at the first track. replacement, starts playback at the first track.
""" """
cpid = int(cpid) tlid = int(tlid)
if cpid == -1: if tlid == -1:
return _play_minus_one(context) return _play_minus_one(context)
try: try:
cp_track = context.core.current_playlist.get(cpid=cpid).get() tl_track = context.core.tracklist.get(tlid=tlid).get()
return context.core.playback.play(cp_track).get() return context.core.playback.play(tl_track).get()
except LookupError: except LookupError:
raise MpdNoExistError('No such song', command='playid') raise MpdNoExistError('No such song', command='playid')
@ -185,9 +185,8 @@ def playpos(context, songpos):
if songpos == -1: if songpos == -1:
return _play_minus_one(context) return _play_minus_one(context)
try: try:
cp_track = context.core.current_playlist.slice( tl_track = context.core.tracklist.slice(songpos, songpos + 1).get()[0]
songpos, songpos + 1).get()[0] return context.core.playback.play(tl_track).get()
return context.core.playback.play(cp_track).get()
except IndexError: except IndexError:
raise MpdArgError('Bad song index', command='play') raise MpdArgError('Bad song index', command='play')
@ -197,12 +196,12 @@ def _play_minus_one(context):
return # Nothing to do return # Nothing to do
elif (context.core.playback.state.get() == PlaybackState.PAUSED): elif (context.core.playback.state.get() == PlaybackState.PAUSED):
return context.core.playback.resume().get() return context.core.playback.resume().get()
elif context.core.playback.current_cp_track.get() is not None: elif context.core.playback.current_tl_track.get() is not None:
cp_track = context.core.playback.current_cp_track.get() tl_track = context.core.playback.current_tl_track.get()
return context.core.playback.play(cp_track).get() return context.core.playback.play(tl_track).get()
elif context.core.current_playlist.slice(0, 1).get(): elif context.core.tracklist.slice(0, 1).get():
cp_track = context.core.current_playlist.slice(0, 1).get()[0] tl_track = context.core.tracklist.slice(0, 1).get()[0]
return context.core.playback.play(cp_track).get() return context.core.playback.play(tl_track).get()
else: else:
return # Fail silently return # Fail silently
@ -331,13 +330,13 @@ def seek(context, songpos, seconds):
- issues ``seek 1 120`` without quotes around the arguments. - issues ``seek 1 120`` without quotes around the arguments.
""" """
if context.core.playback.current_playlist_position != songpos: if context.core.playback.tracklist_position != songpos:
playpos(context, songpos) playpos(context, songpos)
context.core.playback.seek(int(seconds) * 1000) context.core.playback.seek(int(seconds) * 1000)
@handle_request(r'^seekid "(?P<cpid>\d+)" "(?P<seconds>\d+)"$') @handle_request(r'^seekid "(?P<tlid>\d+)" "(?P<seconds>\d+)"$')
def seekid(context, cpid, seconds): def seekid(context, tlid, seconds):
""" """
*musicpd.org, playback section:* *musicpd.org, playback section:*
@ -345,8 +344,8 @@ def seekid(context, cpid, seconds):
Seeks to the position ``TIME`` (in seconds) of song ``SONGID``. Seeks to the position ``TIME`` (in seconds) of song ``SONGID``.
""" """
if context.core.playback.current_cpid != cpid: if context.core.playback.current_tlid != tlid:
playid(context, cpid) playid(context, tlid)
context.core.playback.seek(int(seconds) * 1000) context.core.playback.seek(int(seconds) * 1000)

View File

@ -36,10 +36,10 @@ def currentsong(context):
Displays the song info of the current song (same song that is Displays the song info of the current song (same song that is
identified in status). identified in status).
""" """
current_cp_track = context.core.playback.current_cp_track.get() current_tl_track = context.core.playback.current_tl_track.get()
if current_cp_track is not None: if current_tl_track is not None:
position = context.core.playback.current_playlist_position.get() position = context.core.playback.tracklist_position.get()
return track_to_mpd_format(current_cp_track, position=position) return track_to_mpd_format(current_tl_track, position=position)
@handle_request(r'^idle$') @handle_request(r'^idle$')
@ -175,17 +175,17 @@ def status(context):
decimal places for millisecond precision. decimal places for millisecond precision.
""" """
futures = { futures = {
'current_playlist.length': context.core.current_playlist.length, 'tracklist.length': context.core.tracklist.length,
'current_playlist.version': context.core.current_playlist.version, 'tracklist.version': context.core.tracklist.version,
'playback.volume': context.core.playback.volume, 'playback.volume': context.core.playback.volume,
'playback.consume': context.core.playback.consume, 'playback.consume': context.core.playback.consume,
'playback.random': context.core.playback.random, 'playback.random': context.core.playback.random,
'playback.repeat': context.core.playback.repeat, 'playback.repeat': context.core.playback.repeat,
'playback.single': context.core.playback.single, 'playback.single': context.core.playback.single,
'playback.state': context.core.playback.state, 'playback.state': context.core.playback.state,
'playback.current_cp_track': context.core.playback.current_cp_track, 'playback.current_tl_track': context.core.playback.current_tl_track,
'playback.current_playlist_position': ( 'playback.tracklist_position': (
context.core.playback.current_playlist_position), context.core.playback.tracklist_position),
'playback.time_position': context.core.playback.time_position, 'playback.time_position': context.core.playback.time_position,
} }
pykka.get_all(futures.values()) pykka.get_all(futures.values())
@ -200,7 +200,7 @@ def status(context):
('xfade', _status_xfade(futures)), ('xfade', _status_xfade(futures)),
('state', _status_state(futures)), ('state', _status_state(futures)),
] ]
if futures['playback.current_cp_track'].get() is not None: if futures['playback.current_tl_track'].get() is not None:
result.append(('song', _status_songpos(futures))) result.append(('song', _status_songpos(futures)))
result.append(('songid', _status_songid(futures))) result.append(('songid', _status_songid(futures)))
if futures['playback.state'].get() in ( if futures['playback.state'].get() in (
@ -212,9 +212,9 @@ def status(context):
def _status_bitrate(futures): def _status_bitrate(futures):
current_cp_track = futures['playback.current_cp_track'].get() current_tl_track = futures['playback.current_tl_track'].get()
if current_cp_track is not None: if current_tl_track is not None:
return current_cp_track.track.bitrate return current_tl_track.track.bitrate
def _status_consume(futures): def _status_consume(futures):
@ -225,11 +225,11 @@ def _status_consume(futures):
def _status_playlist_length(futures): def _status_playlist_length(futures):
return futures['current_playlist.length'].get() return futures['tracklist.length'].get()
def _status_playlist_version(futures): def _status_playlist_version(futures):
return futures['current_playlist.version'].get() return futures['tracklist.version'].get()
def _status_random(futures): def _status_random(futures):
@ -245,15 +245,15 @@ def _status_single(futures):
def _status_songid(futures): def _status_songid(futures):
current_cp_track = futures['playback.current_cp_track'].get() current_tl_track = futures['playback.current_tl_track'].get()
if current_cp_track is not None: if current_tl_track is not None:
return current_cp_track.cpid return current_tl_track.tlid
else: else:
return _status_songpos(futures) return _status_songpos(futures)
def _status_songpos(futures): def _status_songpos(futures):
return futures['playback.current_playlist_position'].get() return futures['playback.tracklist_position'].get()
def _status_state(futures): def _status_state(futures):
@ -277,13 +277,13 @@ def _status_time_elapsed(futures):
def _status_time_total(futures): def _status_time_total(futures):
current_cp_track = futures['playback.current_cp_track'].get() current_tl_track = futures['playback.current_tl_track'].get()
if current_cp_track is None: if current_tl_track is None:
return 0 return 0
elif current_cp_track.track.length is None: elif current_tl_track.track.length is None:
return 0 return 0
else: else:
return current_cp_track.track.length return current_tl_track.track.length
def _status_volume(futures): def _status_volume(futures):

View File

@ -102,7 +102,7 @@ def load(context, name):
""" """
try: try:
playlist = context.core.stored_playlists.get(name=name).get() playlist = context.core.stored_playlists.get(name=name).get()
context.core.current_playlist.append(playlist.tracks) context.core.tracklist.append(playlist.tracks)
except LookupError: except LookupError:
raise MpdNoExistError('No such playlist', command='load') raise MpdNoExistError('No such playlist', command='load')

View File

@ -5,7 +5,7 @@ import re
from mopidy import settings from mopidy import settings
from mopidy.frontends.mpd import protocol from mopidy.frontends.mpd import protocol
from mopidy.models import CpTrack from mopidy.models import TlTrack
from mopidy.utils.path import mtime as get_mtime, uri_to_path, split_path from mopidy.utils.path import mtime as get_mtime, uri_to_path, split_path
@ -14,7 +14,7 @@ def track_to_mpd_format(track, position=None):
Format track for output to MPD client. Format track for output to MPD client.
:param track: the track :param track: the track
:type track: :class:`mopidy.models.Track` or :class:`mopidy.models.CpTrack` :type track: :class:`mopidy.models.Track` or :class:`mopidy.models.TlTrack`
:param position: track's position in playlist :param position: track's position in playlist
:type position: integer :type position: integer
:param key: if we should set key :param key: if we should set key
@ -23,10 +23,10 @@ def track_to_mpd_format(track, position=None):
:type mtime: boolean :type mtime: boolean
:rtype: list of two-tuples :rtype: list of two-tuples
""" """
if isinstance(track, CpTrack): if isinstance(track, TlTrack):
(cpid, track) = track (tlid, track) = track
else: else:
(cpid, track) = (None, track) (tlid, track) = (None, track)
result = [ result = [
('file', track.uri or ''), ('file', track.uri or ''),
('Time', track.length and (track.length // 1000) or 0), ('Time', track.length and (track.length // 1000) or 0),
@ -43,9 +43,9 @@ def track_to_mpd_format(track, position=None):
if track.album is not None and track.album.artists: if track.album is not None and track.album.artists:
artists = artists_to_mpd_format(track.album.artists) artists = artists_to_mpd_format(track.album.artists)
result.append(('AlbumArtist', artists)) result.append(('AlbumArtist', artists))
if position is not None and cpid is not None: if position is not None and tlid is not None:
result.append(('Pos', position)) result.append(('Pos', position))
result.append(('Id', cpid)) result.append(('Id', tlid))
if track.album is not None and track.album.musicbrainz_id is not None: if track.album is not None and track.album.musicbrainz_id is not None:
result.append(('MUSICBRAINZ_ALBUMID', track.album.musicbrainz_id)) result.append(('MUSICBRAINZ_ALBUMID', track.album.musicbrainz_id))
# FIXME don't use first and best artist? # FIXME don't use first and best artist?
@ -106,7 +106,7 @@ def tracks_to_mpd_format(tracks, start=0, end=None):
:param tracks: the tracks :param tracks: the tracks
:type tracks: list of :class:`mopidy.models.Track` or :type tracks: list of :class:`mopidy.models.Track` or
:class:`mopidy.models.CpTrack` :class:`mopidy.models.TlTrack`
:param start: position of first track to include in output :param start: position of first track to include in output
:type start: int (positive or negative) :type start: int (positive or negative)
:param end: position after last track to include in output :param end: position after last track to include in output

View File

@ -84,10 +84,10 @@ class MprisObject(dbus.service.Object):
logger.info('Connected to D-Bus') logger.info('Connected to D-Bus')
return bus_name return bus_name
def _get_track_id(self, cp_track): def _get_track_id(self, tl_track):
return '/com/mopidy/track/%d' % cp_track.cpid return '/com/mopidy/track/%d' % tl_track.tlid
def _get_cpid(self, track_id): def _get_tlid(self, track_id):
assert track_id.startswith('/com/mopidy/track/') assert track_id.startswith('/com/mopidy/track/')
return track_id.split('/')[-1] return track_id.split('/')[-1]
@ -234,14 +234,14 @@ class MprisObject(dbus.service.Object):
logger.debug('%s.SetPosition not allowed', PLAYER_IFACE) logger.debug('%s.SetPosition not allowed', PLAYER_IFACE)
return return
position = position // 1000 position = position // 1000
current_cp_track = self.core.playback.current_cp_track.get() current_tl_track = self.core.playback.current_tl_track.get()
if current_cp_track is None: if current_tl_track is None:
return return
if track_id != self._get_track_id(current_cp_track): if track_id != self._get_track_id(current_tl_track):
return return
if position < 0: if position < 0:
return return
if current_cp_track.track.length < position: if current_tl_track.track.length < position:
return return
self.core.playback.seek(position) self.core.playback.seek(position)
@ -260,8 +260,8 @@ class MprisObject(dbus.service.Object):
return return
track = self.core.library.lookup(uri).get() track = self.core.library.lookup(uri).get()
if track is not None: if track is not None:
cp_track = self.core.current_playlist.add(track).get() tl_track = self.core.tracklist.add(track).get()
self.core.playback.play(cp_track) self.core.playback.play(tl_track)
else: else:
logger.debug('Track with URI "%s" not found in library.', uri) logger.debug('Track with URI "%s" not found in library.', uri)
@ -330,12 +330,12 @@ class MprisObject(dbus.service.Object):
self.core.playback.random = False self.core.playback.random = False
def get_Metadata(self): def get_Metadata(self):
current_cp_track = self.core.playback.current_cp_track.get() current_tl_track = self.core.playback.current_tl_track.get()
if current_cp_track is None: if current_tl_track is None:
return {'mpris:trackid': ''} return {'mpris:trackid': ''}
else: else:
(_, track) = current_cp_track (_, track) = current_tl_track
metadata = {'mpris:trackid': self._get_track_id(current_cp_track)} metadata = {'mpris:trackid': self._get_track_id(current_tl_track)}
if track.length: if track.length:
metadata['mpris:length'] = track.length * 1000 metadata['mpris:length'] = track.length * 1000
if track.uri: if track.uri:
@ -384,15 +384,15 @@ class MprisObject(dbus.service.Object):
if not self.get_CanControl(): if not self.get_CanControl():
return False return False
return ( return (
self.core.playback.cp_track_at_next.get() != self.core.playback.tl_track_at_next.get() !=
self.core.playback.current_cp_track.get()) self.core.playback.current_tl_track.get())
def get_CanGoPrevious(self): def get_CanGoPrevious(self):
if not self.get_CanControl(): if not self.get_CanControl():
return False return False
return ( return (
self.core.playback.cp_track_at_previous.get() != self.core.playback.tl_track_at_previous.get() !=
self.core.playback.current_cp_track.get()) self.core.playback.current_tl_track.get())
def get_CanPlay(self): def get_CanPlay(self):
if not self.get_CanControl(): if not self.get_CanControl():

View File

@ -151,7 +151,7 @@ class Album(ImmutableObject):
super(Album, self).__init__(*args, **kwargs) super(Album, self).__init__(*args, **kwargs)
CpTrack = namedtuple('CpTrack', ['cpid', 'track']) TlTrack = namedtuple('TlTrack', ['tlid', 'track'])
class Track(ImmutableObject): class Track(ImmutableObject):

View File

@ -4,7 +4,7 @@ from __future__ import unicode_literals
def populate_playlist(func): def populate_playlist(func):
def wrapper(self): def wrapper(self):
for track in self.tracks: for track in self.tracks:
self.core.current_playlist.add(track) self.core.tracklist.add(track)
return func(self) return func(self)
wrapper.__name__ = func.__name__ wrapper.__name__ = func.__name__

View File

@ -22,7 +22,7 @@ class PlaybackControllerTest(object):
self.backend = self.backend_class.start(audio=self.audio).proxy() self.backend = self.backend_class.start(audio=self.audio).proxy()
self.core = core.Core(backends=[self.backend]) self.core = core.Core(backends=[self.backend])
self.playback = self.core.playback self.playback = self.core.playback
self.current_playlist = self.core.current_playlist self.tracklist = self.core.tracklist
assert len(self.tracks) >= 3, \ assert len(self.tracks) >= 3, \
'Need at least three tracks to run tests.' 'Need at least three tracks to run tests.'
@ -53,13 +53,13 @@ class PlaybackControllerTest(object):
@populate_playlist @populate_playlist
def test_play_track_state(self): def test_play_track_state(self):
self.assertEqual(self.playback.state, PlaybackState.STOPPED) self.assertEqual(self.playback.state, PlaybackState.STOPPED)
self.playback.play(self.current_playlist.cp_tracks[-1]) self.playback.play(self.tracklist.tl_tracks[-1])
self.assertEqual(self.playback.state, PlaybackState.PLAYING) self.assertEqual(self.playback.state, PlaybackState.PLAYING)
@populate_playlist @populate_playlist
def test_play_track_return_value(self): def test_play_track_return_value(self):
self.assertEqual(self.playback.play( self.assertEqual(self.playback.play(
self.current_playlist.cp_tracks[-1]), None) self.tracklist.tl_tracks[-1]), None)
@populate_playlist @populate_playlist
def test_play_when_playing(self): def test_play_when_playing(self):
@ -95,7 +95,7 @@ class PlaybackControllerTest(object):
@populate_playlist @populate_playlist
def test_play_track_sets_current_track(self): def test_play_track_sets_current_track(self):
self.playback.play(self.current_playlist.cp_tracks[-1]) self.playback.play(self.tracklist.tl_tracks[-1])
self.assertEqual(self.playback.current_track, self.tracks[-1]) self.assertEqual(self.playback.current_track, self.tracks[-1])
@populate_playlist @populate_playlist
@ -108,12 +108,12 @@ class PlaybackControllerTest(object):
@populate_playlist @populate_playlist
def test_current_track_after_completed_playlist(self): def test_current_track_after_completed_playlist(self):
self.playback.play(self.current_playlist.cp_tracks[-1]) self.playback.play(self.tracklist.tl_tracks[-1])
self.playback.on_end_of_track() self.playback.on_end_of_track()
self.assertEqual(self.playback.state, PlaybackState.STOPPED) self.assertEqual(self.playback.state, PlaybackState.STOPPED)
self.assertEqual(self.playback.current_track, None) self.assertEqual(self.playback.current_track, None)
self.playback.play(self.current_playlist.cp_tracks[-1]) self.playback.play(self.tracklist.tl_tracks[-1])
self.playback.next() self.playback.next()
self.assertEqual(self.playback.state, PlaybackState.STOPPED) self.assertEqual(self.playback.state, PlaybackState.STOPPED)
self.assertEqual(self.playback.current_track, None) self.assertEqual(self.playback.current_track, None)
@ -162,7 +162,7 @@ class PlaybackControllerTest(object):
def test_previous_skips_to_previous_track_on_failure(self): def test_previous_skips_to_previous_track_on_failure(self):
# If backend's play() returns False, it is a failure. # If backend's play() returns False, it is a failure.
self.backend.playback.play = lambda track: track != self.tracks[1] self.backend.playback.play = lambda track: track != self.tracks[1]
self.playback.play(self.current_playlist.cp_tracks[2]) self.playback.play(self.tracklist.tl_tracks[2])
self.assertEqual(self.playback.current_track, self.tracks[2]) self.assertEqual(self.playback.current_track, self.tracks[2])
self.playback.previous() self.playback.previous()
self.assertNotEqual(self.playback.current_track, self.tracks[1]) self.assertNotEqual(self.playback.current_track, self.tracks[1])
@ -172,13 +172,13 @@ class PlaybackControllerTest(object):
def test_next(self): def test_next(self):
self.playback.play() self.playback.play()
old_position = self.playback.current_playlist_position old_position = self.playback.tracklist_position
old_uri = self.playback.current_track.uri old_uri = self.playback.current_track.uri
self.playback.next() self.playback.next()
self.assertEqual( self.assertEqual(
self.playback.current_playlist_position, old_position + 1) self.playback.tracklist_position, old_position + 1)
self.assertNotEqual(self.playback.current_track.uri, old_uri) self.assertNotEqual(self.playback.current_track.uri, old_uri)
@populate_playlist @populate_playlist
@ -198,7 +198,7 @@ class PlaybackControllerTest(object):
for i, track in enumerate(self.tracks): for i, track in enumerate(self.tracks):
self.assertEqual(self.playback.state, PlaybackState.PLAYING) self.assertEqual(self.playback.state, PlaybackState.PLAYING)
self.assertEqual(self.playback.current_track, track) self.assertEqual(self.playback.current_track, track)
self.assertEqual(self.playback.current_playlist_position, i) self.assertEqual(self.playback.tracklist_position, i)
self.playback.next() self.playback.next()
@ -254,7 +254,7 @@ class PlaybackControllerTest(object):
@populate_playlist @populate_playlist
def test_next_track_at_end_of_playlist(self): def test_next_track_at_end_of_playlist(self):
self.playback.play() self.playback.play()
for _ in self.current_playlist.cp_tracks[1:]: for _ in self.tracklist.tl_tracks[1:]:
self.playback.next() self.playback.next()
self.assertEqual(self.playback.track_at_next, None) self.assertEqual(self.playback.track_at_next, None)
@ -277,7 +277,7 @@ class PlaybackControllerTest(object):
self.playback.consume = True self.playback.consume = True
self.playback.play() self.playback.play()
self.playback.next() self.playback.next()
self.assertIn(self.tracks[0], self.current_playlist.tracks) self.assertIn(self.tracks[0], self.tracklist.tracks)
@populate_playlist @populate_playlist
def test_next_with_single_and_repeat(self): def test_next_with_single_and_repeat(self):
@ -301,20 +301,20 @@ class PlaybackControllerTest(object):
random.seed(1) random.seed(1)
self.playback.random = True self.playback.random = True
self.assertEqual(self.playback.track_at_next, self.tracks[2]) self.assertEqual(self.playback.track_at_next, self.tracks[2])
self.current_playlist.append(self.tracks[:1]) self.tracklist.append(self.tracks[:1])
self.assertEqual(self.playback.track_at_next, self.tracks[1]) self.assertEqual(self.playback.track_at_next, self.tracks[1])
@populate_playlist @populate_playlist
def test_end_of_track(self): def test_end_of_track(self):
self.playback.play() self.playback.play()
old_position = self.playback.current_playlist_position old_position = self.playback.tracklist_position
old_uri = self.playback.current_track.uri old_uri = self.playback.current_track.uri
self.playback.on_end_of_track() self.playback.on_end_of_track()
self.assertEqual( self.assertEqual(
self.playback.current_playlist_position, old_position + 1) self.playback.tracklist_position, old_position + 1)
self.assertNotEqual(self.playback.current_track.uri, old_uri) self.assertNotEqual(self.playback.current_track.uri, old_uri)
@populate_playlist @populate_playlist
@ -334,7 +334,7 @@ class PlaybackControllerTest(object):
for i, track in enumerate(self.tracks): for i, track in enumerate(self.tracks):
self.assertEqual(self.playback.state, PlaybackState.PLAYING) self.assertEqual(self.playback.state, PlaybackState.PLAYING)
self.assertEqual(self.playback.current_track, track) self.assertEqual(self.playback.current_track, track)
self.assertEqual(self.playback.current_playlist_position, i) self.assertEqual(self.playback.tracklist_position, i)
self.playback.on_end_of_track() self.playback.on_end_of_track()
@ -390,7 +390,7 @@ class PlaybackControllerTest(object):
@populate_playlist @populate_playlist
def test_end_of_track_track_at_end_of_playlist(self): def test_end_of_track_track_at_end_of_playlist(self):
self.playback.play() self.playback.play()
for _ in self.current_playlist.cp_tracks[1:]: for _ in self.tracklist.tl_tracks[1:]:
self.playback.on_end_of_track() self.playback.on_end_of_track()
self.assertEqual(self.playback.track_at_next, None) self.assertEqual(self.playback.track_at_next, None)
@ -413,7 +413,7 @@ class PlaybackControllerTest(object):
self.playback.consume = True self.playback.consume = True
self.playback.play() self.playback.play()
self.playback.on_end_of_track() self.playback.on_end_of_track()
self.assertNotIn(self.tracks[0], self.current_playlist.tracks) self.assertNotIn(self.tracks[0], self.tracklist.tracks)
@populate_playlist @populate_playlist
def test_end_of_track_with_random(self): def test_end_of_track_with_random(self):
@ -429,7 +429,7 @@ class PlaybackControllerTest(object):
random.seed(1) random.seed(1)
self.playback.random = True self.playback.random = True
self.assertEqual(self.playback.track_at_next, self.tracks[2]) self.assertEqual(self.playback.track_at_next, self.tracks[2])
self.current_playlist.append(self.tracks[:1]) self.tracklist.append(self.tracks[:1])
self.assertEqual(self.playback.track_at_next, self.tracks[1]) self.assertEqual(self.playback.track_at_next, self.tracks[1])
@populate_playlist @populate_playlist
@ -490,36 +490,36 @@ class PlaybackControllerTest(object):
self.assertEqual(self.playback.current_track, self.tracks[1]) self.assertEqual(self.playback.current_track, self.tracks[1])
@populate_playlist @populate_playlist
def test_initial_current_playlist_position(self): def test_initial_tracklist_position(self):
self.assertEqual(self.playback.current_playlist_position, None) self.assertEqual(self.playback.tracklist_position, None)
@populate_playlist @populate_playlist
def test_current_playlist_position_during_play(self): def test_tracklist_position_during_play(self):
self.playback.play() self.playback.play()
self.assertEqual(self.playback.current_playlist_position, 0) self.assertEqual(self.playback.tracklist_position, 0)
@populate_playlist @populate_playlist
def test_current_playlist_position_after_next(self): def test_tracklist_position_after_next(self):
self.playback.play() self.playback.play()
self.playback.next() self.playback.next()
self.assertEqual(self.playback.current_playlist_position, 1) self.assertEqual(self.playback.tracklist_position, 1)
@populate_playlist @populate_playlist
def test_current_playlist_position_at_end_of_playlist(self): def test_tracklist_position_at_end_of_playlist(self):
self.playback.play(self.current_playlist.cp_tracks[-1]) self.playback.play(self.tracklist.tl_tracks[-1])
self.playback.on_end_of_track() self.playback.on_end_of_track()
self.assertEqual(self.playback.current_playlist_position, None) self.assertEqual(self.playback.tracklist_position, None)
def test_on_current_playlist_change_gets_called(self): def test_on_tracklist_change_gets_called(self):
callback = self.playback.on_current_playlist_change callback = self.playback.on_tracklist_change
def wrapper(): def wrapper():
wrapper.called = True wrapper.called = True
return callback() return callback()
wrapper.called = False wrapper.called = False
self.playback.on_current_playlist_change = wrapper self.playback.on_tracklist_change = wrapper
self.current_playlist.append([Track()]) self.tracklist.append([Track()])
self.assert_(wrapper.called) self.assert_(wrapper.called)
@ -533,25 +533,25 @@ class PlaybackControllerTest(object):
self.assertEqual('end_of_track', message['command']) self.assertEqual('end_of_track', message['command'])
@populate_playlist @populate_playlist
def test_on_current_playlist_change_when_playing(self): def test_on_tracklist_change_when_playing(self):
self.playback.play() self.playback.play()
current_track = self.playback.current_track current_track = self.playback.current_track
self.current_playlist.append([self.tracks[2]]) self.tracklist.append([self.tracks[2]])
self.assertEqual(self.playback.state, PlaybackState.PLAYING) self.assertEqual(self.playback.state, PlaybackState.PLAYING)
self.assertEqual(self.playback.current_track, current_track) self.assertEqual(self.playback.current_track, current_track)
@populate_playlist @populate_playlist
def test_on_current_playlist_change_when_stopped(self): def test_on_tracklist_change_when_stopped(self):
self.current_playlist.append([self.tracks[2]]) self.tracklist.append([self.tracks[2]])
self.assertEqual(self.playback.state, PlaybackState.STOPPED) self.assertEqual(self.playback.state, PlaybackState.STOPPED)
self.assertEqual(self.playback.current_track, None) self.assertEqual(self.playback.current_track, None)
@populate_playlist @populate_playlist
def test_on_current_playlist_change_when_paused(self): def test_on_tracklist_change_when_paused(self):
self.playback.play() self.playback.play()
self.playback.pause() self.playback.pause()
current_track = self.playback.current_track current_track = self.playback.current_track
self.current_playlist.append([self.tracks[2]]) self.tracklist.append([self.tracks[2]])
self.assertEqual(self.playback.state, PlaybackState.PAUSED) self.assertEqual(self.playback.state, PlaybackState.PAUSED)
self.assertEqual(self.playback.current_track, current_track) self.assertEqual(self.playback.current_track, current_track)
@ -642,7 +642,7 @@ class PlaybackControllerTest(object):
@populate_playlist @populate_playlist
def test_seek_when_playing_updates_position(self): def test_seek_when_playing_updates_position(self):
length = self.current_playlist.tracks[0].length length = self.tracklist.tracks[0].length
self.playback.play() self.playback.play()
self.playback.seek(length - 1000) self.playback.seek(length - 1000)
position = self.playback.time_position position = self.playback.time_position
@ -657,7 +657,7 @@ class PlaybackControllerTest(object):
@populate_playlist @populate_playlist
def test_seek_when_paused_updates_position(self): def test_seek_when_paused_updates_position(self):
length = self.current_playlist.tracks[0].length length = self.tracklist.tracks[0].length
self.playback.play() self.playback.play()
self.playback.pause() self.playback.pause()
self.playback.seek(length - 1000) self.playback.seek(length - 1000)
@ -687,8 +687,8 @@ class PlaybackControllerTest(object):
@populate_playlist @populate_playlist
def test_seek_beyond_end_of_song_for_last_track(self): def test_seek_beyond_end_of_song_for_last_track(self):
self.playback.play(self.current_playlist.cp_tracks[-1]) self.playback.play(self.tracklist.tl_tracks[-1])
self.playback.seek(self.current_playlist.tracks[-1].length * 100) self.playback.seek(self.tracklist.tracks[-1].length * 100)
self.assertEqual(self.playback.state, PlaybackState.STOPPED) self.assertEqual(self.playback.state, PlaybackState.STOPPED)
@unittest.SkipTest @unittest.SkipTest
@ -774,9 +774,9 @@ class PlaybackControllerTest(object):
def test_playlist_is_empty_after_all_tracks_are_played_with_consume(self): def test_playlist_is_empty_after_all_tracks_are_played_with_consume(self):
self.playback.consume = True self.playback.consume = True
self.playback.play() self.playback.play()
for _ in range(len(self.current_playlist.tracks)): for _ in range(len(self.tracklist.tracks)):
self.playback.on_end_of_track() self.playback.on_end_of_track()
self.assertEqual(len(self.current_playlist.tracks), 0) self.assertEqual(len(self.tracklist.tracks), 0)
@populate_playlist @populate_playlist
def test_play_with_random(self): def test_play_with_random(self):
@ -811,7 +811,7 @@ class PlaybackControllerTest(object):
@populate_playlist @populate_playlist
def test_end_of_playlist_stops(self): def test_end_of_playlist_stops(self):
self.playback.play(self.current_playlist.cp_tracks[-1]) self.playback.play(self.tracklist.tl_tracks[-1])
self.playback.on_end_of_track() self.playback.on_end_of_track()
self.assertEqual(self.playback.state, PlaybackState.STOPPED) self.assertEqual(self.playback.state, PlaybackState.STOPPED)

View File

@ -7,19 +7,19 @@ import pykka
from mopidy import audio, core from mopidy import audio, core
from mopidy.core import PlaybackState from mopidy.core import PlaybackState
from mopidy.models import CpTrack, Playlist, Track from mopidy.models import TlTrack, Playlist, Track
from tests.backends.base import populate_playlist from tests.backends.base import populate_playlist
class CurrentPlaylistControllerTest(object): class TracklistControllerTest(object):
tracks = [] tracks = []
def setUp(self): def setUp(self):
self.audio = mock.Mock(spec=audio.Audio) self.audio = mock.Mock(spec=audio.Audio)
self.backend = self.backend_class.start(audio=self.audio).proxy() self.backend = self.backend_class.start(audio=self.audio).proxy()
self.core = core.Core(audio=audio, backends=[self.backend]) self.core = core.Core(audio=audio, backends=[self.backend])
self.controller = self.core.current_playlist self.controller = self.core.tracklist
self.playback = self.core.playback self.playback = self.core.playback
assert len(self.tracks) == 3, 'Need three tracks to run tests.' assert len(self.tracks) == 3, 'Need three tracks to run tests.'
@ -28,25 +28,25 @@ class CurrentPlaylistControllerTest(object):
pykka.ActorRegistry.stop_all() pykka.ActorRegistry.stop_all()
def test_length(self): def test_length(self):
self.assertEqual(0, len(self.controller.cp_tracks)) self.assertEqual(0, len(self.controller.tl_tracks))
self.assertEqual(0, self.controller.length) self.assertEqual(0, self.controller.length)
self.controller.append(self.tracks) self.controller.append(self.tracks)
self.assertEqual(3, len(self.controller.cp_tracks)) self.assertEqual(3, len(self.controller.tl_tracks))
self.assertEqual(3, self.controller.length) self.assertEqual(3, self.controller.length)
def test_add(self): def test_add(self):
for track in self.tracks: for track in self.tracks:
cp_track = self.controller.add(track) tl_track = self.controller.add(track)
self.assertEqual(track, self.controller.tracks[-1]) self.assertEqual(track, self.controller.tracks[-1])
self.assertEqual(cp_track, self.controller.cp_tracks[-1]) self.assertEqual(tl_track, self.controller.tl_tracks[-1])
self.assertEqual(track, cp_track.track) self.assertEqual(track, tl_track.track)
def test_add_at_position(self): def test_add_at_position(self):
for track in self.tracks[:-1]: for track in self.tracks[:-1]:
cp_track = self.controller.add(track, 0) tl_track = self.controller.add(track, 0)
self.assertEqual(track, self.controller.tracks[0]) self.assertEqual(track, self.controller.tracks[0])
self.assertEqual(cp_track, self.controller.cp_tracks[0]) self.assertEqual(tl_track, self.controller.tl_tracks[0])
self.assertEqual(track, cp_track.track) self.assertEqual(track, tl_track.track)
@populate_playlist @populate_playlist
def test_add_at_position_outside_of_playlist(self): def test_add_at_position_outside_of_playlist(self):
@ -55,14 +55,14 @@ class CurrentPlaylistControllerTest(object):
self.assertRaises(AssertionError, test) self.assertRaises(AssertionError, test)
@populate_playlist @populate_playlist
def test_get_by_cpid(self): def test_get_by_tlid(self):
cp_track = self.controller.cp_tracks[1] tl_track = self.controller.tl_tracks[1]
self.assertEqual(cp_track, self.controller.get(cpid=cp_track.cpid)) self.assertEqual(tl_track, self.controller.get(tlid=tl_track.tlid))
@populate_playlist @populate_playlist
def test_get_by_uri(self): def test_get_by_uri(self):
cp_track = self.controller.cp_tracks[1] tl_track = self.controller.tl_tracks[1]
self.assertEqual(cp_track, self.controller.get(uri=cp_track.track.uri)) self.assertEqual(tl_track, self.controller.get(uri=tl_track.track.uri))
@populate_playlist @populate_playlist
def test_get_by_uri_raises_error_for_invalid_uri(self): def test_get_by_uri_raises_error_for_invalid_uri(self):
@ -124,7 +124,7 @@ class CurrentPlaylistControllerTest(object):
self.controller.append([track1, track2, track3]) self.controller.append([track1, track2, track3])
self.assertEqual(track2, self.controller.get(uri='b')[1]) self.assertEqual(track2, self.controller.get(uri='b')[1])
def test_append_appends_to_the_current_playlist(self): def test_append_appends_to_the_tracklist(self):
self.controller.append([Track(uri='a'), Track(uri='b')]) self.controller.append([Track(uri='a'), Track(uri='b')])
self.assertEqual(len(self.controller.tracks), 2) self.assertEqual(len(self.controller.tracks), 2)
self.controller.append([Track(uri='c'), Track(uri='d')]) self.controller.append([Track(uri='c'), Track(uri='d')])
@ -154,15 +154,15 @@ class CurrentPlaylistControllerTest(object):
self.assertEqual(self.playback.current_track, None) self.assertEqual(self.playback.current_track, None)
def test_index_returns_index_of_track(self): def test_index_returns_index_of_track(self):
cp_tracks = [] tl_tracks = []
for track in self.tracks: for track in self.tracks:
cp_tracks.append(self.controller.add(track)) tl_tracks.append(self.controller.add(track))
self.assertEquals(0, self.controller.index(cp_tracks[0])) self.assertEquals(0, self.controller.index(tl_tracks[0]))
self.assertEquals(1, self.controller.index(cp_tracks[1])) self.assertEquals(1, self.controller.index(tl_tracks[1]))
self.assertEquals(2, self.controller.index(cp_tracks[2])) self.assertEquals(2, self.controller.index(tl_tracks[2]))
def test_index_raises_value_error_if_item_not_found(self): def test_index_raises_value_error_if_item_not_found(self):
test = lambda: self.controller.index(CpTrack(0, Track())) test = lambda: self.controller.index(TlTrack(0, Track()))
self.assertRaises(ValueError, test) self.assertRaises(ValueError, test)
@populate_playlist @populate_playlist

View File

@ -21,14 +21,14 @@ class BackendEventsTest(unittest.TestCase):
pykka.ActorRegistry.stop_all() pykka.ActorRegistry.stop_all()
def test_pause_sends_track_playback_paused_event(self, send): def test_pause_sends_track_playback_paused_event(self, send):
self.core.current_playlist.add(Track(uri='dummy:a')) self.core.tracklist.add(Track(uri='dummy:a'))
self.core.playback.play().get() self.core.playback.play().get()
send.reset_mock() send.reset_mock()
self.core.playback.pause().get() self.core.playback.pause().get()
self.assertEqual(send.call_args[0][0], 'track_playback_paused') self.assertEqual(send.call_args[0][0], 'track_playback_paused')
def test_resume_sends_track_playback_resumed(self, send): def test_resume_sends_track_playback_resumed(self, send):
self.core.current_playlist.add(Track(uri='dummy:a')) self.core.tracklist.add(Track(uri='dummy:a'))
self.core.playback.play() self.core.playback.play()
self.core.playback.pause().get() self.core.playback.pause().get()
send.reset_mock() send.reset_mock()
@ -36,20 +36,20 @@ class BackendEventsTest(unittest.TestCase):
self.assertEqual(send.call_args[0][0], 'track_playback_resumed') self.assertEqual(send.call_args[0][0], 'track_playback_resumed')
def test_play_sends_track_playback_started_event(self, send): def test_play_sends_track_playback_started_event(self, send):
self.core.current_playlist.add(Track(uri='dummy:a')) self.core.tracklist.add(Track(uri='dummy:a'))
send.reset_mock() send.reset_mock()
self.core.playback.play().get() self.core.playback.play().get()
self.assertEqual(send.call_args[0][0], 'track_playback_started') self.assertEqual(send.call_args[0][0], 'track_playback_started')
def test_stop_sends_track_playback_ended_event(self, send): def test_stop_sends_track_playback_ended_event(self, send):
self.core.current_playlist.add(Track(uri='dummy:a')) self.core.tracklist.add(Track(uri='dummy:a'))
self.core.playback.play().get() self.core.playback.play().get()
send.reset_mock() send.reset_mock()
self.core.playback.stop().get() self.core.playback.stop().get()
self.assertEqual(send.call_args_list[0][0][0], 'track_playback_ended') self.assertEqual(send.call_args_list[0][0][0], 'track_playback_ended')
def test_seek_sends_seeked_event(self, send): def test_seek_sends_seeked_event(self, send):
self.core.current_playlist.add(Track(uri='dummy:a', length=40000)) self.core.tracklist.add(Track(uri='dummy:a', length=40000))
self.core.playback.play().get() self.core.playback.play().get()
send.reset_mock() send.reset_mock()
self.core.playback.seek(1000).get() self.core.playback.seek(1000).get()

View File

@ -27,7 +27,7 @@ class LocalPlaybackControllerTest(PlaybackControllerTest, unittest.TestCase):
def add_track(self, path): def add_track(self, path):
uri = path_to_uri(path_to_data_dir(path)) uri = path_to_uri(path_to_data_dir(path))
track = Track(uri=uri, length=4464) track = Track(uri=uri, length=4464)
self.current_playlist.add(track) self.tracklist.add(track)
def test_uri_scheme(self): def test_uri_scheme(self):
self.assertIn('file', self.core.uri_schemes) self.assertIn('file', self.core.uri_schemes)

View File

@ -5,21 +5,19 @@ from mopidy.backends.local import LocalBackend
from mopidy.models import Track from mopidy.models import Track
from tests import unittest from tests import unittest
from tests.backends.base.current_playlist import CurrentPlaylistControllerTest from tests.backends.base.tracklist import TracklistControllerTest
from tests.backends.local import generate_song from tests.backends.local import generate_song
class LocalCurrentPlaylistControllerTest(CurrentPlaylistControllerTest, class LocalTracklistControllerTest(TracklistControllerTest, unittest.TestCase):
unittest.TestCase):
backend_class = LocalBackend backend_class = LocalBackend
tracks = [ tracks = [
Track(uri=generate_song(i), length=4464) for i in range(1, 4)] Track(uri=generate_song(i), length=4464) for i in range(1, 4)]
def setUp(self): def setUp(self):
settings.BACKENDS = ('mopidy.backends.local.LocalBackend',) settings.BACKENDS = ('mopidy.backends.local.LocalBackend',)
super(LocalCurrentPlaylistControllerTest, self).setUp() super(LocalTracklistControllerTest, self).setUp()
def tearDown(self): def tearDown(self):
super(LocalCurrentPlaylistControllerTest, self).tearDown() super(LocalTracklistControllerTest, self).tearDown()
settings.runtime.clear() settings.runtime.clear()

View File

@ -35,48 +35,48 @@ class CorePlaybackTest(unittest.TestCase):
self.core = Core(audio=None, backends=[ self.core = Core(audio=None, backends=[
self.backend1, self.backend2, self.backend3]) self.backend1, self.backend2, self.backend3])
self.core.current_playlist.append(self.tracks) self.core.tracklist.append(self.tracks)
self.cp_tracks = self.core.current_playlist.cp_tracks self.tl_tracks = self.core.tracklist.tl_tracks
self.unplayable_cp_track = self.cp_tracks[2] self.unplayable_tl_track = self.tl_tracks[2]
def test_play_selects_dummy1_backend(self): def test_play_selects_dummy1_backend(self):
self.core.playback.play(self.cp_tracks[0]) self.core.playback.play(self.tl_tracks[0])
self.playback1.play.assert_called_once_with(self.tracks[0]) self.playback1.play.assert_called_once_with(self.tracks[0])
self.assertFalse(self.playback2.play.called) self.assertFalse(self.playback2.play.called)
def test_play_selects_dummy2_backend(self): def test_play_selects_dummy2_backend(self):
self.core.playback.play(self.cp_tracks[1]) self.core.playback.play(self.tl_tracks[1])
self.assertFalse(self.playback1.play.called) self.assertFalse(self.playback1.play.called)
self.playback2.play.assert_called_once_with(self.tracks[1]) self.playback2.play.assert_called_once_with(self.tracks[1])
def test_play_skips_to_next_on_unplayable_track(self): def test_play_skips_to_next_on_unplayable_track(self):
self.core.playback.play(self.unplayable_cp_track) self.core.playback.play(self.unplayable_tl_track)
self.playback1.play.assert_called_once_with(self.tracks[3]) self.playback1.play.assert_called_once_with(self.tracks[3])
self.assertFalse(self.playback2.play.called) self.assertFalse(self.playback2.play.called)
self.assertEqual(self.core.playback.current_cp_track, self.assertEqual(self.core.playback.current_tl_track,
self.cp_tracks[3]) self.tl_tracks[3])
def test_pause_selects_dummy1_backend(self): def test_pause_selects_dummy1_backend(self):
self.core.playback.play(self.cp_tracks[0]) self.core.playback.play(self.tl_tracks[0])
self.core.playback.pause() self.core.playback.pause()
self.playback1.pause.assert_called_once_with() self.playback1.pause.assert_called_once_with()
self.assertFalse(self.playback2.pause.called) self.assertFalse(self.playback2.pause.called)
def test_pause_selects_dummy2_backend(self): def test_pause_selects_dummy2_backend(self):
self.core.playback.play(self.cp_tracks[1]) self.core.playback.play(self.tl_tracks[1])
self.core.playback.pause() self.core.playback.pause()
self.assertFalse(self.playback1.pause.called) self.assertFalse(self.playback1.pause.called)
self.playback2.pause.assert_called_once_with() self.playback2.pause.assert_called_once_with()
def test_pause_changes_state_even_if_track_is_unplayable(self): def test_pause_changes_state_even_if_track_is_unplayable(self):
self.core.playback.current_cp_track = self.unplayable_cp_track self.core.playback.current_tl_track = self.unplayable_tl_track
self.core.playback.pause() self.core.playback.pause()
self.assertEqual(self.core.playback.state, PlaybackState.PAUSED) self.assertEqual(self.core.playback.state, PlaybackState.PAUSED)
@ -84,7 +84,7 @@ class CorePlaybackTest(unittest.TestCase):
self.assertFalse(self.playback2.pause.called) self.assertFalse(self.playback2.pause.called)
def test_resume_selects_dummy1_backend(self): def test_resume_selects_dummy1_backend(self):
self.core.playback.play(self.cp_tracks[0]) self.core.playback.play(self.tl_tracks[0])
self.core.playback.pause() self.core.playback.pause()
self.core.playback.resume() self.core.playback.resume()
@ -92,7 +92,7 @@ class CorePlaybackTest(unittest.TestCase):
self.assertFalse(self.playback2.resume.called) self.assertFalse(self.playback2.resume.called)
def test_resume_selects_dummy2_backend(self): def test_resume_selects_dummy2_backend(self):
self.core.playback.play(self.cp_tracks[1]) self.core.playback.play(self.tl_tracks[1])
self.core.playback.pause() self.core.playback.pause()
self.core.playback.resume() self.core.playback.resume()
@ -100,7 +100,7 @@ class CorePlaybackTest(unittest.TestCase):
self.playback2.resume.assert_called_once_with() self.playback2.resume.assert_called_once_with()
def test_resume_does_nothing_if_track_is_unplayable(self): def test_resume_does_nothing_if_track_is_unplayable(self):
self.core.playback.current_cp_track = self.unplayable_cp_track self.core.playback.current_tl_track = self.unplayable_tl_track
self.core.playback.state = PlaybackState.PAUSED self.core.playback.state = PlaybackState.PAUSED
self.core.playback.resume() self.core.playback.resume()
@ -109,21 +109,21 @@ class CorePlaybackTest(unittest.TestCase):
self.assertFalse(self.playback2.resume.called) self.assertFalse(self.playback2.resume.called)
def test_stop_selects_dummy1_backend(self): def test_stop_selects_dummy1_backend(self):
self.core.playback.play(self.cp_tracks[0]) self.core.playback.play(self.tl_tracks[0])
self.core.playback.stop() self.core.playback.stop()
self.playback1.stop.assert_called_once_with() self.playback1.stop.assert_called_once_with()
self.assertFalse(self.playback2.stop.called) self.assertFalse(self.playback2.stop.called)
def test_stop_selects_dummy2_backend(self): def test_stop_selects_dummy2_backend(self):
self.core.playback.play(self.cp_tracks[1]) self.core.playback.play(self.tl_tracks[1])
self.core.playback.stop() self.core.playback.stop()
self.assertFalse(self.playback1.stop.called) self.assertFalse(self.playback1.stop.called)
self.playback2.stop.assert_called_once_with() self.playback2.stop.assert_called_once_with()
def test_stop_changes_state_even_if_track_is_unplayable(self): def test_stop_changes_state_even_if_track_is_unplayable(self):
self.core.playback.current_cp_track = self.unplayable_cp_track self.core.playback.current_tl_track = self.unplayable_tl_track
self.core.playback.state = PlaybackState.PAUSED self.core.playback.state = PlaybackState.PAUSED
self.core.playback.stop() self.core.playback.stop()
@ -132,21 +132,21 @@ class CorePlaybackTest(unittest.TestCase):
self.assertFalse(self.playback2.stop.called) self.assertFalse(self.playback2.stop.called)
def test_seek_selects_dummy1_backend(self): def test_seek_selects_dummy1_backend(self):
self.core.playback.play(self.cp_tracks[0]) self.core.playback.play(self.tl_tracks[0])
self.core.playback.seek(10000) self.core.playback.seek(10000)
self.playback1.seek.assert_called_once_with(10000) self.playback1.seek.assert_called_once_with(10000)
self.assertFalse(self.playback2.seek.called) self.assertFalse(self.playback2.seek.called)
def test_seek_selects_dummy2_backend(self): def test_seek_selects_dummy2_backend(self):
self.core.playback.play(self.cp_tracks[1]) self.core.playback.play(self.tl_tracks[1])
self.core.playback.seek(10000) self.core.playback.seek(10000)
self.assertFalse(self.playback1.seek.called) self.assertFalse(self.playback1.seek.called)
self.playback2.seek.assert_called_once_with(10000) self.playback2.seek.assert_called_once_with(10000)
def test_seek_fails_for_unplayable_track(self): def test_seek_fails_for_unplayable_track(self):
self.core.playback.current_cp_track = self.unplayable_cp_track self.core.playback.current_tl_track = self.unplayable_tl_track
self.core.playback.state = PlaybackState.PLAYING self.core.playback.state = PlaybackState.PLAYING
success = self.core.playback.seek(1000) success = self.core.playback.seek(1000)
@ -155,7 +155,7 @@ class CorePlaybackTest(unittest.TestCase):
self.assertFalse(self.playback2.seek.called) self.assertFalse(self.playback2.seek.called)
def test_time_position_selects_dummy1_backend(self): def test_time_position_selects_dummy1_backend(self):
self.core.playback.play(self.cp_tracks[0]) self.core.playback.play(self.tl_tracks[0])
self.core.playback.seek(10000) self.core.playback.seek(10000)
self.core.playback.time_position self.core.playback.time_position
@ -163,7 +163,7 @@ class CorePlaybackTest(unittest.TestCase):
self.assertFalse(self.playback2.get_time_position.called) self.assertFalse(self.playback2.get_time_position.called)
def test_time_position_selects_dummy2_backend(self): def test_time_position_selects_dummy2_backend(self):
self.core.playback.play(self.cp_tracks[1]) self.core.playback.play(self.tl_tracks[1])
self.core.playback.seek(10000) self.core.playback.seek(10000)
self.core.playback.time_position self.core.playback.time_position
@ -171,7 +171,7 @@ class CorePlaybackTest(unittest.TestCase):
self.playback2.get_time_position.assert_called_once_with() self.playback2.get_time_position.assert_called_once_with()
def test_time_position_returns_0_if_track_is_unplayable(self): def test_time_position_returns_0_if_track_is_unplayable(self):
self.core.playback.current_cp_track = self.unplayable_cp_track self.core.playback.current_tl_track = self.unplayable_tl_track
result = self.core.playback.time_position result = self.core.playback.time_position

View File

@ -10,13 +10,13 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
needle = Track(uri='dummy://foo') needle = Track(uri='dummy://foo')
self.backend.library.dummy_library = [ self.backend.library.dummy_library = [
Track(), Track(), needle, Track()] Track(), Track(), needle, Track()]
self.core.current_playlist.append( self.core.tracklist.append(
[Track(), Track(), Track(), Track(), Track()]) [Track(), Track(), Track(), Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.sendRequest('add "dummy://foo"') self.sendRequest('add "dummy://foo"')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 6) self.assertEqual(len(self.core.tracklist.tracks.get()), 6)
self.assertEqual(self.core.current_playlist.tracks.get()[5], needle) self.assertEqual(self.core.tracklist.tracks.get()[5], needle)
self.assertEqualResponse('OK') self.assertEqualResponse('OK')
def test_add_with_uri_not_found_in_library_should_ack(self): def test_add_with_uri_not_found_in_library_should_ack(self):
@ -33,15 +33,15 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
needle = Track(uri='dummy://foo') needle = Track(uri='dummy://foo')
self.backend.library.dummy_library = [ self.backend.library.dummy_library = [
Track(), Track(), needle, Track()] Track(), Track(), needle, Track()]
self.core.current_playlist.append( self.core.tracklist.append(
[Track(), Track(), Track(), Track(), Track()]) [Track(), Track(), Track(), Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.sendRequest('addid "dummy://foo"') self.sendRequest('addid "dummy://foo"')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 6) self.assertEqual(len(self.core.tracklist.tracks.get()), 6)
self.assertEqual(self.core.current_playlist.tracks.get()[5], needle) self.assertEqual(self.core.tracklist.tracks.get()[5], needle)
self.assertInResponse( self.assertInResponse(
'Id: %d' % self.core.current_playlist.cp_tracks.get()[5][0]) 'Id: %d' % self.core.tracklist.tl_tracks.get()[5][0])
self.assertInResponse('OK') self.assertInResponse('OK')
def test_addid_with_empty_uri_acks(self): def test_addid_with_empty_uri_acks(self):
@ -52,24 +52,24 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
needle = Track(uri='dummy://foo') needle = Track(uri='dummy://foo')
self.backend.library.dummy_library = [ self.backend.library.dummy_library = [
Track(), Track(), needle, Track()] Track(), Track(), needle, Track()]
self.core.current_playlist.append( self.core.tracklist.append(
[Track(), Track(), Track(), Track(), Track()]) [Track(), Track(), Track(), Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.sendRequest('addid "dummy://foo" "3"') self.sendRequest('addid "dummy://foo" "3"')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 6) self.assertEqual(len(self.core.tracklist.tracks.get()), 6)
self.assertEqual(self.core.current_playlist.tracks.get()[3], needle) self.assertEqual(self.core.tracklist.tracks.get()[3], needle)
self.assertInResponse( self.assertInResponse(
'Id: %d' % self.core.current_playlist.cp_tracks.get()[3][0]) 'Id: %d' % self.core.tracklist.tl_tracks.get()[3][0])
self.assertInResponse('OK') self.assertInResponse('OK')
def test_addid_with_songpos_out_of_bounds_should_ack(self): def test_addid_with_songpos_out_of_bounds_should_ack(self):
needle = Track(uri='dummy://foo') needle = Track(uri='dummy://foo')
self.backend.library.dummy_library = [ self.backend.library.dummy_library = [
Track(), Track(), needle, Track()] Track(), Track(), needle, Track()]
self.core.current_playlist.append( self.core.tracklist.append(
[Track(), Track(), Track(), Track(), Track()]) [Track(), Track(), Track(), Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.sendRequest('addid "dummy://foo" "6"') self.sendRequest('addid "dummy://foo" "6"')
self.assertEqualResponse('ACK [2@0] {addid} Bad song index') self.assertEqualResponse('ACK [2@0] {addid} Bad song index')
@ -79,85 +79,85 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertEqualResponse('ACK [50@0] {addid} No such song') self.assertEqualResponse('ACK [50@0] {addid} No such song')
def test_clear(self): def test_clear(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(), Track(), Track(), Track(), Track()]) [Track(), Track(), Track(), Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.sendRequest('clear') self.sendRequest('clear')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 0) self.assertEqual(len(self.core.tracklist.tracks.get()), 0)
self.assertEqual(self.core.playback.current_track.get(), None) self.assertEqual(self.core.playback.current_track.get(), None)
self.assertInResponse('OK') self.assertInResponse('OK')
def test_delete_songpos(self): def test_delete_songpos(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(), Track(), Track(), Track(), Track()]) [Track(), Track(), Track(), Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.sendRequest( self.sendRequest(
'delete "%d"' % self.core.current_playlist.cp_tracks.get()[2][0]) 'delete "%d"' % self.core.tracklist.tl_tracks.get()[2][0])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 4) self.assertEqual(len(self.core.tracklist.tracks.get()), 4)
self.assertInResponse('OK') self.assertInResponse('OK')
def test_delete_songpos_out_of_bounds(self): def test_delete_songpos_out_of_bounds(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(), Track(), Track(), Track(), Track()]) [Track(), Track(), Track(), Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.sendRequest('delete "5"') self.sendRequest('delete "5"')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.assertEqualResponse('ACK [2@0] {delete} Bad song index') self.assertEqualResponse('ACK [2@0] {delete} Bad song index')
def test_delete_open_range(self): def test_delete_open_range(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(), Track(), Track(), Track(), Track()]) [Track(), Track(), Track(), Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.sendRequest('delete "1:"') self.sendRequest('delete "1:"')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 1) self.assertEqual(len(self.core.tracklist.tracks.get()), 1)
self.assertInResponse('OK') self.assertInResponse('OK')
def test_delete_closed_range(self): def test_delete_closed_range(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(), Track(), Track(), Track(), Track()]) [Track(), Track(), Track(), Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.sendRequest('delete "1:3"') self.sendRequest('delete "1:3"')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 3) self.assertEqual(len(self.core.tracklist.tracks.get()), 3)
self.assertInResponse('OK') self.assertInResponse('OK')
def test_delete_range_out_of_bounds(self): def test_delete_range_out_of_bounds(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(), Track(), Track(), Track(), Track()]) [Track(), Track(), Track(), Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.sendRequest('delete "5:7"') self.sendRequest('delete "5:7"')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.assertEqual(len(self.core.tracklist.tracks.get()), 5)
self.assertEqualResponse('ACK [2@0] {delete} Bad song index') self.assertEqualResponse('ACK [2@0] {delete} Bad song index')
def test_deleteid(self): def test_deleteid(self):
self.core.current_playlist.append([Track(), Track()]) self.core.tracklist.append([Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 2) self.assertEqual(len(self.core.tracklist.tracks.get()), 2)
self.sendRequest('deleteid "1"') self.sendRequest('deleteid "1"')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 1) self.assertEqual(len(self.core.tracklist.tracks.get()), 1)
self.assertInResponse('OK') self.assertInResponse('OK')
def test_deleteid_does_not_exist(self): def test_deleteid_does_not_exist(self):
self.core.current_playlist.append([Track(), Track()]) self.core.tracklist.append([Track(), Track()])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 2) self.assertEqual(len(self.core.tracklist.tracks.get()), 2)
self.sendRequest('deleteid "12345"') self.sendRequest('deleteid "12345"')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 2) self.assertEqual(len(self.core.tracklist.tracks.get()), 2)
self.assertEqualResponse('ACK [50@0] {deleteid} No such song') self.assertEqualResponse('ACK [50@0] {deleteid} No such song')
def test_move_songpos(self): def test_move_songpos(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
self.sendRequest('move "1" "0"') self.sendRequest('move "1" "0"')
tracks = self.core.current_playlist.tracks.get() tracks = self.core.tracklist.tracks.get()
self.assertEqual(tracks[0].name, 'b') self.assertEqual(tracks[0].name, 'b')
self.assertEqual(tracks[1].name, 'a') self.assertEqual(tracks[1].name, 'a')
self.assertEqual(tracks[2].name, 'c') self.assertEqual(tracks[2].name, 'c')
@ -167,13 +167,13 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_move_open_range(self): def test_move_open_range(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
self.sendRequest('move "2:" "0"') self.sendRequest('move "2:" "0"')
tracks = self.core.current_playlist.tracks.get() tracks = self.core.tracklist.tracks.get()
self.assertEqual(tracks[0].name, 'c') self.assertEqual(tracks[0].name, 'c')
self.assertEqual(tracks[1].name, 'd') self.assertEqual(tracks[1].name, 'd')
self.assertEqual(tracks[2].name, 'e') self.assertEqual(tracks[2].name, 'e')
@ -183,13 +183,13 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_move_closed_range(self): def test_move_closed_range(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
self.sendRequest('move "1:3" "0"') self.sendRequest('move "1:3" "0"')
tracks = self.core.current_playlist.tracks.get() tracks = self.core.tracklist.tracks.get()
self.assertEqual(tracks[0].name, 'b') self.assertEqual(tracks[0].name, 'b')
self.assertEqual(tracks[1].name, 'c') self.assertEqual(tracks[1].name, 'c')
self.assertEqual(tracks[2].name, 'a') self.assertEqual(tracks[2].name, 'a')
@ -199,13 +199,13 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_moveid(self): def test_moveid(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
self.sendRequest('moveid "4" "2"') self.sendRequest('moveid "4" "2"')
tracks = self.core.current_playlist.tracks.get() tracks = self.core.tracklist.tracks.get()
self.assertEqual(tracks[0].name, 'a') self.assertEqual(tracks[0].name, 'a')
self.assertEqual(tracks[1].name, 'b') self.assertEqual(tracks[1].name, 'b')
self.assertEqual(tracks[2].name, 'e') self.assertEqual(tracks[2].name, 'e')
@ -223,7 +223,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.sendRequest('playlistfind "tag" "needle"') self.sendRequest('playlistfind "tag" "needle"')
self.assertEqualResponse('ACK [0@0] {} Not implemented') self.assertEqualResponse('ACK [0@0] {} Not implemented')
def test_playlistfind_by_filename_not_in_current_playlist(self): def test_playlistfind_by_filename_not_in_tracklist(self):
self.sendRequest('playlistfind "filename" "file:///dev/null"') self.sendRequest('playlistfind "filename" "file:///dev/null"')
self.assertEqualResponse('OK') self.assertEqualResponse('OK')
@ -231,8 +231,8 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.sendRequest('playlistfind filename "file:///dev/null"') self.sendRequest('playlistfind filename "file:///dev/null"')
self.assertEqualResponse('OK') self.assertEqualResponse('OK')
def test_playlistfind_by_filename_in_current_playlist(self): def test_playlistfind_by_filename_in_tracklist(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='file:///exists')]) Track(uri='file:///exists')])
self.sendRequest('playlistfind filename "file:///exists"') self.sendRequest('playlistfind filename "file:///exists"')
@ -242,7 +242,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playlistid_without_songid(self): def test_playlistid_without_songid(self):
self.core.current_playlist.append([Track(name='a'), Track(name='b')]) self.core.tracklist.append([Track(name='a'), Track(name='b')])
self.sendRequest('playlistid') self.sendRequest('playlistid')
self.assertInResponse('Title: a') self.assertInResponse('Title: a')
@ -250,7 +250,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playlistid_with_songid(self): def test_playlistid_with_songid(self):
self.core.current_playlist.append([Track(name='a'), Track(name='b')]) self.core.tracklist.append([Track(name='a'), Track(name='b')])
self.sendRequest('playlistid "1"') self.sendRequest('playlistid "1"')
self.assertNotInResponse('Title: a') self.assertNotInResponse('Title: a')
@ -260,13 +260,13 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playlistid_with_not_existing_songid_fails(self): def test_playlistid_with_not_existing_songid_fails(self):
self.core.current_playlist.append([Track(name='a'), Track(name='b')]) self.core.tracklist.append([Track(name='a'), Track(name='b')])
self.sendRequest('playlistid "25"') self.sendRequest('playlistid "25"')
self.assertEqualResponse('ACK [50@0] {playlistid} No such song') self.assertEqualResponse('ACK [50@0] {playlistid} No such song')
def test_playlistinfo_without_songpos_or_range(self): def test_playlistinfo_without_songpos_or_range(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
@ -288,8 +288,8 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
def test_playlistinfo_with_songpos(self): def test_playlistinfo_with_songpos(self):
# Make the track's CPID not match the playlist position # Make the track's CPID not match the playlist position
self.core.current_playlist.cp_id = 17 self.core.tracklist.tlid = 17
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
@ -315,7 +315,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertEqual(response1, response2) self.assertEqual(response1, response2)
def test_playlistinfo_with_open_range(self): def test_playlistinfo_with_open_range(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
@ -336,7 +336,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playlistinfo_with_closed_range(self): def test_playlistinfo_with_closed_range(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
@ -367,7 +367,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertEqualResponse('ACK [0@0] {} Not implemented') self.assertEqualResponse('ACK [0@0] {} Not implemented')
def test_plchanges_with_lower_version_returns_changes(self): def test_plchanges_with_lower_version_returns_changes(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(name='a'), Track(name='b'), Track(name='c')]) [Track(name='a'), Track(name='b'), Track(name='c')])
self.sendRequest('plchanges "0"') self.sendRequest('plchanges "0"')
@ -377,10 +377,10 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_plchanges_with_equal_version_returns_nothing(self): def test_plchanges_with_equal_version_returns_nothing(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(name='a'), Track(name='b'), Track(name='c')]) [Track(name='a'), Track(name='b'), Track(name='c')])
self.assertEqual(self.core.current_playlist.version.get(), 1) self.assertEqual(self.core.tracklist.version.get(), 1)
self.sendRequest('plchanges "1"') self.sendRequest('plchanges "1"')
self.assertNotInResponse('Title: a') self.assertNotInResponse('Title: a')
self.assertNotInResponse('Title: b') self.assertNotInResponse('Title: b')
@ -388,10 +388,10 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_plchanges_with_greater_version_returns_nothing(self): def test_plchanges_with_greater_version_returns_nothing(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(name='a'), Track(name='b'), Track(name='c')]) [Track(name='a'), Track(name='b'), Track(name='c')])
self.assertEqual(self.core.current_playlist.version.get(), 1) self.assertEqual(self.core.tracklist.version.get(), 1)
self.sendRequest('plchanges "2"') self.sendRequest('plchanges "2"')
self.assertNotInResponse('Title: a') self.assertNotInResponse('Title: a')
self.assertNotInResponse('Title: b') self.assertNotInResponse('Title: b')
@ -399,7 +399,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_plchanges_with_minus_one_returns_entire_playlist(self): def test_plchanges_with_minus_one_returns_entire_playlist(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(name='a'), Track(name='b'), Track(name='c')]) [Track(name='a'), Track(name='b'), Track(name='c')])
self.sendRequest('plchanges "-1"') self.sendRequest('plchanges "-1"')
@ -409,7 +409,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_plchanges_without_quotes_works(self): def test_plchanges_without_quotes_works(self):
self.core.current_playlist.append( self.core.tracklist.append(
[Track(name='a'), Track(name='b'), Track(name='c')]) [Track(name='a'), Track(name='b'), Track(name='c')])
self.sendRequest('plchanges 0') self.sendRequest('plchanges 0')
@ -419,39 +419,39 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_plchangesposid(self): def test_plchangesposid(self):
self.core.current_playlist.append([Track(), Track(), Track()]) self.core.tracklist.append([Track(), Track(), Track()])
self.sendRequest('plchangesposid "0"') self.sendRequest('plchangesposid "0"')
cp_tracks = self.core.current_playlist.cp_tracks.get() tl_tracks = self.core.tracklist.tl_tracks.get()
self.assertInResponse('cpos: 0') self.assertInResponse('cpos: 0')
self.assertInResponse('Id: %d' % cp_tracks[0][0]) self.assertInResponse('Id: %d' % tl_tracks[0][0])
self.assertInResponse('cpos: 2') self.assertInResponse('cpos: 2')
self.assertInResponse('Id: %d' % cp_tracks[1][0]) self.assertInResponse('Id: %d' % tl_tracks[1][0])
self.assertInResponse('cpos: 2') self.assertInResponse('cpos: 2')
self.assertInResponse('Id: %d' % cp_tracks[2][0]) self.assertInResponse('Id: %d' % tl_tracks[2][0])
self.assertInResponse('OK') self.assertInResponse('OK')
def test_shuffle_without_range(self): def test_shuffle_without_range(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
version = self.core.current_playlist.version.get() version = self.core.tracklist.version.get()
self.sendRequest('shuffle') self.sendRequest('shuffle')
self.assertLess(version, self.core.current_playlist.version.get()) self.assertLess(version, self.core.tracklist.version.get())
self.assertInResponse('OK') self.assertInResponse('OK')
def test_shuffle_with_open_range(self): def test_shuffle_with_open_range(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
version = self.core.current_playlist.version.get() version = self.core.tracklist.version.get()
self.sendRequest('shuffle "4:"') self.sendRequest('shuffle "4:"')
self.assertLess(version, self.core.current_playlist.version.get()) self.assertLess(version, self.core.tracklist.version.get())
tracks = self.core.current_playlist.tracks.get() tracks = self.core.tracklist.tracks.get()
self.assertEqual(tracks[0].name, 'a') self.assertEqual(tracks[0].name, 'a')
self.assertEqual(tracks[1].name, 'b') self.assertEqual(tracks[1].name, 'b')
self.assertEqual(tracks[2].name, 'c') self.assertEqual(tracks[2].name, 'c')
@ -459,15 +459,15 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_shuffle_with_closed_range(self): def test_shuffle_with_closed_range(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
version = self.core.current_playlist.version.get() version = self.core.tracklist.version.get()
self.sendRequest('shuffle "1:3"') self.sendRequest('shuffle "1:3"')
self.assertLess(version, self.core.current_playlist.version.get()) self.assertLess(version, self.core.tracklist.version.get())
tracks = self.core.current_playlist.tracks.get() tracks = self.core.tracklist.tracks.get()
self.assertEqual(tracks[0].name, 'a') self.assertEqual(tracks[0].name, 'a')
self.assertEqual(tracks[3].name, 'd') self.assertEqual(tracks[3].name, 'd')
self.assertEqual(tracks[4].name, 'e') self.assertEqual(tracks[4].name, 'e')
@ -475,13 +475,13 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_swap(self): def test_swap(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
self.sendRequest('swap "1" "4"') self.sendRequest('swap "1" "4"')
tracks = self.core.current_playlist.tracks.get() tracks = self.core.tracklist.tracks.get()
self.assertEqual(tracks[0].name, 'a') self.assertEqual(tracks[0].name, 'a')
self.assertEqual(tracks[1].name, 'e') self.assertEqual(tracks[1].name, 'e')
self.assertEqual(tracks[2].name, 'c') self.assertEqual(tracks[2].name, 'c')
@ -491,13 +491,13 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_swapid(self): def test_swapid(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(name='a'), Track(name='b'), Track(name='c'), Track(name='a'), Track(name='b'), Track(name='c'),
Track(name='d'), Track(name='e'), Track(name='f'), Track(name='d'), Track(name='e'), Track(name='f'),
]) ])
self.sendRequest('swapid "1" "4"') self.sendRequest('swapid "1" "4"')
tracks = self.core.current_playlist.tracks.get() tracks = self.core.tracklist.tracks.get()
self.assertEqual(tracks[0].name, 'a') self.assertEqual(tracks[0].name, 'a')
self.assertEqual(tracks[1].name, 'e') self.assertEqual(tracks[1].name, 'e')
self.assertEqual(tracks[2].name, 'c') self.assertEqual(tracks[2].name, 'c')

View File

@ -168,7 +168,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_pause_off(self): def test_pause_off(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.sendRequest('play "0"') self.sendRequest('play "0"')
self.sendRequest('pause "1"') self.sendRequest('pause "1"')
@ -177,7 +177,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_pause_on(self): def test_pause_on(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.sendRequest('play "0"') self.sendRequest('play "0"')
self.sendRequest('pause "1"') self.sendRequest('pause "1"')
@ -185,7 +185,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_pause_toggle(self): def test_pause_toggle(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.sendRequest('play "0"') self.sendRequest('play "0"')
self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertEqual(PLAYING, self.core.playback.state.get())
@ -200,28 +200,28 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_play_without_pos(self): def test_play_without_pos(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.sendRequest('play') self.sendRequest('play')
self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertEqual(PLAYING, self.core.playback.state.get())
self.assertInResponse('OK') self.assertInResponse('OK')
def test_play_with_pos(self): def test_play_with_pos(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.sendRequest('play "0"') self.sendRequest('play "0"')
self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertEqual(PLAYING, self.core.playback.state.get())
self.assertInResponse('OK') self.assertInResponse('OK')
def test_play_with_pos_without_quotes(self): def test_play_with_pos_without_quotes(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.sendRequest('play 0') self.sendRequest('play 0')
self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertEqual(PLAYING, self.core.playback.state.get())
self.assertInResponse('OK') self.assertInResponse('OK')
def test_play_with_pos_out_of_bounds(self): def test_play_with_pos_out_of_bounds(self):
self.core.current_playlist.append([]) self.core.tracklist.append([])
self.sendRequest('play "0"') self.sendRequest('play "0"')
self.assertEqual(STOPPED, self.core.playback.state.get()) self.assertEqual(STOPPED, self.core.playback.state.get())
@ -229,7 +229,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
def test_play_minus_one_plays_first_in_playlist_if_no_current_track(self): def test_play_minus_one_plays_first_in_playlist_if_no_current_track(self):
self.assertEqual(self.core.playback.current_track.get(), None) self.assertEqual(self.core.playback.current_track.get(), None)
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:a'),
Track(uri='dummy:b'), Track(uri='dummy:b'),
]) ])
@ -241,7 +241,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_play_minus_one_plays_current_track_if_current_track_is_set(self): def test_play_minus_one_plays_current_track_if_current_track_is_set(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:a'),
Track(uri='dummy:b'), Track(uri='dummy:b'),
]) ])
@ -258,7 +258,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_play_minus_one_on_empty_playlist_does_not_ack(self): def test_play_minus_one_on_empty_playlist_does_not_ack(self):
self.core.current_playlist.clear() self.core.tracklist.clear()
self.sendRequest('play "-1"') self.sendRequest('play "-1"')
self.assertEqual(STOPPED, self.core.playback.state.get()) self.assertEqual(STOPPED, self.core.playback.state.get())
@ -266,7 +266,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_play_minus_is_ignored_if_playing(self): def test_play_minus_is_ignored_if_playing(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a', length=40000)]) Track(uri='dummy:a', length=40000)])
self.core.playback.seek(30000) self.core.playback.seek(30000)
self.assertGreaterEqual( self.assertGreaterEqual(
@ -280,7 +280,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_play_minus_one_resumes_if_paused(self): def test_play_minus_one_resumes_if_paused(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a', length=40000)]) Track(uri='dummy:a', length=40000)])
self.core.playback.seek(30000) self.core.playback.seek(30000)
self.assertGreaterEqual( self.assertGreaterEqual(
@ -296,14 +296,14 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playid(self): def test_playid(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.sendRequest('playid "0"') self.sendRequest('playid "0"')
self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertEqual(PLAYING, self.core.playback.state.get())
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playid_without_quotes(self): def test_playid_without_quotes(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.sendRequest('playid 0') self.sendRequest('playid 0')
self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertEqual(PLAYING, self.core.playback.state.get())
@ -311,7 +311,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
def test_playid_minus_1_plays_first_in_playlist_if_no_current_track(self): def test_playid_minus_1_plays_first_in_playlist_if_no_current_track(self):
self.assertEqual(self.core.playback.current_track.get(), None) self.assertEqual(self.core.playback.current_track.get(), None)
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:a'),
Track(uri='dummy:b'), Track(uri='dummy:b'),
]) ])
@ -323,7 +323,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playid_minus_1_plays_current_track_if_current_track_is_set(self): def test_playid_minus_1_plays_current_track_if_current_track_is_set(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:a'),
Track(uri='dummy:b'), Track(uri='dummy:b'),
]) ])
@ -340,7 +340,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playid_minus_one_on_empty_playlist_does_not_ack(self): def test_playid_minus_one_on_empty_playlist_does_not_ack(self):
self.core.current_playlist.clear() self.core.tracklist.clear()
self.sendRequest('playid "-1"') self.sendRequest('playid "-1"')
self.assertEqual(STOPPED, self.core.playback.state.get()) self.assertEqual(STOPPED, self.core.playback.state.get())
@ -348,7 +348,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playid_minus_is_ignored_if_playing(self): def test_playid_minus_is_ignored_if_playing(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.seek(30000) self.core.playback.seek(30000)
self.assertGreaterEqual( self.assertGreaterEqual(
self.core.playback.time_position.get(), 30000) self.core.playback.time_position.get(), 30000)
@ -361,7 +361,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playid_minus_one_resumes_if_paused(self): def test_playid_minus_one_resumes_if_paused(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.seek(30000) self.core.playback.seek(30000)
self.assertGreaterEqual( self.assertGreaterEqual(
self.core.playback.time_position.get(), 30000) self.core.playback.time_position.get(), 30000)
@ -376,7 +376,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_playid_which_does_not_exist(self): def test_playid_which_does_not_exist(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.sendRequest('playid "12345"') self.sendRequest('playid "12345"')
self.assertInResponse('ACK [50@0] {playid} No such song') self.assertInResponse('ACK [50@0] {playid} No such song')
@ -386,7 +386,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_seek(self): def test_seek(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.sendRequest('seek "0"') self.sendRequest('seek "0"')
self.sendRequest('seek "0" "30"') self.sendRequest('seek "0" "30"')
@ -395,7 +395,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
def test_seek_with_songpos(self): def test_seek_with_songpos(self):
seek_track = Track(uri='dummy:b', length=40000) seek_track = Track(uri='dummy:b', length=40000)
self.core.current_playlist.append( self.core.tracklist.append(
[Track(uri='dummy:a', length=40000), seek_track]) [Track(uri='dummy:a', length=40000), seek_track])
self.sendRequest('seek "1" "30"') self.sendRequest('seek "1" "30"')
@ -403,7 +403,7 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_seek_without_quotes(self): def test_seek_without_quotes(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.sendRequest('seek 0') self.sendRequest('seek 0')
self.sendRequest('seek 0 30') self.sendRequest('seek 0 30')
@ -412,19 +412,19 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase):
self.assertInResponse('OK') self.assertInResponse('OK')
def test_seekid(self): def test_seekid(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.sendRequest('seekid "0" "30"') self.sendRequest('seekid "0" "30"')
self.assertGreaterEqual( self.assertGreaterEqual(
self.core.playback.time_position.get(), 30000) self.core.playback.time_position.get(), 30000)
self.assertInResponse('OK') self.assertInResponse('OK')
def test_seekid_with_cpid(self): def test_seekid_with_tlid(self):
seek_track = Track(uri='dummy:b', length=40000) seek_track = Track(uri='dummy:b', length=40000)
self.core.current_playlist.append( self.core.tracklist.append(
[Track(uri='dummy:a', length=40000), seek_track]) [Track(uri='dummy:a', length=40000), seek_track])
self.sendRequest('seekid "1" "30"') self.sendRequest('seekid "1" "30"')
self.assertEqual(1, self.core.playback.current_cpid.get()) self.assertEqual(1, self.core.playback.current_tlid.get())
self.assertEqual(seek_track, self.core.playback.current_track.get()) self.assertEqual(seek_track, self.core.playback.current_track.get())
self.assertInResponse('OK') self.assertInResponse('OK')

View File

@ -18,7 +18,7 @@ class IssueGH17RegressionTest(protocol.BaseTestCase):
- Press next until you get to the unplayable track - Press next until you get to the unplayable track
""" """
def test(self): def test(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:a'),
Track(uri='dummy:b'), Track(uri='dummy:b'),
Track(uri='dummy:error'), Track(uri='dummy:error'),
@ -59,7 +59,7 @@ class IssueGH18RegressionTest(protocol.BaseTestCase):
""" """
def test(self): def test(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b'), Track(uri='dummy:c'), Track(uri='dummy:a'), Track(uri='dummy:b'), Track(uri='dummy:c'),
Track(uri='dummy:d'), Track(uri='dummy:e'), Track(uri='dummy:f')]) Track(uri='dummy:d'), Track(uri='dummy:e'), Track(uri='dummy:f')])
random.seed(1) random.seed(1)
@ -71,14 +71,14 @@ class IssueGH18RegressionTest(protocol.BaseTestCase):
self.sendRequest('next') self.sendRequest('next')
self.sendRequest('next') self.sendRequest('next')
cp_track_1 = self.core.playback.current_cp_track.get() tl_track_1 = self.core.playback.current_tl_track.get()
self.sendRequest('next') self.sendRequest('next')
cp_track_2 = self.core.playback.current_cp_track.get() tl_track_2 = self.core.playback.current_tl_track.get()
self.sendRequest('next') self.sendRequest('next')
cp_track_3 = self.core.playback.current_cp_track.get() tl_track_3 = self.core.playback.current_tl_track.get()
self.assertNotEqual(cp_track_1, cp_track_2) self.assertNotEqual(tl_track_1, tl_track_2)
self.assertNotEqual(cp_track_2, cp_track_3) self.assertNotEqual(tl_track_2, tl_track_3)
class IssueGH22RegressionTest(protocol.BaseTestCase): class IssueGH22RegressionTest(protocol.BaseTestCase):
@ -95,7 +95,7 @@ class IssueGH22RegressionTest(protocol.BaseTestCase):
""" """
def test(self): def test(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b'), Track(uri='dummy:c'), Track(uri='dummy:a'), Track(uri='dummy:b'), Track(uri='dummy:c'),
Track(uri='dummy:d'), Track(uri='dummy:e'), Track(uri='dummy:f')]) Track(uri='dummy:d'), Track(uri='dummy:e'), Track(uri='dummy:f')])
random.seed(1) random.seed(1)
@ -124,7 +124,7 @@ class IssueGH69RegressionTest(protocol.BaseTestCase):
def test(self): def test(self):
self.core.stored_playlists.create('foo') self.core.stored_playlists.create('foo')
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b'), Track(uri='dummy:c'), Track(uri='dummy:a'), Track(uri='dummy:b'), Track(uri='dummy:c'),
Track(uri='dummy:d'), Track(uri='dummy:e'), Track(uri='dummy:f')]) Track(uri='dummy:d'), Track(uri='dummy:e'), Track(uri='dummy:f')])

View File

@ -12,7 +12,7 @@ class StatusHandlerTest(protocol.BaseTestCase):
def test_currentsong(self): def test_currentsong(self):
track = Track() track = Track()
self.core.current_playlist.append([track]) self.core.tracklist.append([track])
self.core.playback.play() self.core.playback.play()
self.sendRequest('currentsong') self.sendRequest('currentsong')
self.assertInResponse('file: ') self.assertInResponse('file: ')

View File

@ -64,15 +64,15 @@ class StoredPlaylistsHandlerTest(protocol.BaseTestCase):
self.assertInResponse('Last-Modified: 2001-03-17T13:41:17Z') self.assertInResponse('Last-Modified: 2001-03-17T13:41:17Z')
self.assertInResponse('OK') self.assertInResponse('OK')
def test_load_known_playlist_appends_to_current_playlist(self): def test_load_known_playlist_appends_to_tracklist(self):
self.core.current_playlist.append([Track(uri='a'), Track(uri='b')]) self.core.tracklist.append([Track(uri='a'), Track(uri='b')])
self.assertEqual(len(self.core.current_playlist.tracks.get()), 2) self.assertEqual(len(self.core.tracklist.tracks.get()), 2)
self.backend.stored_playlists.playlists = [ self.backend.stored_playlists.playlists = [
Playlist(name='A-list', tracks=[ Playlist(name='A-list', tracks=[
Track(uri='c'), Track(uri='d'), Track(uri='e')])] Track(uri='c'), Track(uri='d'), Track(uri='e')])]
self.sendRequest('load "A-list"') self.sendRequest('load "A-list"')
tracks = self.core.current_playlist.tracks.get() tracks = self.core.tracklist.tracks.get()
self.assertEqual(5, len(tracks)) self.assertEqual(5, len(tracks))
self.assertEqual('a', tracks[0].uri) self.assertEqual('a', tracks[0].uri)
self.assertEqual('b', tracks[1].uri) self.assertEqual('b', tracks[1].uri)
@ -83,7 +83,7 @@ class StoredPlaylistsHandlerTest(protocol.BaseTestCase):
def test_load_unknown_playlist_acks(self): def test_load_unknown_playlist_acks(self):
self.sendRequest('load "unknown playlist"') self.sendRequest('load "unknown playlist"')
self.assertEqual(0, len(self.core.current_playlist.tracks.get())) self.assertEqual(0, len(self.core.tracklist.tracks.get()))
self.assertEqualResponse('ACK [50@0] {load} No such playlist') self.assertEqualResponse('ACK [50@0] {load} No such playlist')
def test_playlistadd(self): def test_playlistadd(self):

View File

@ -6,7 +6,7 @@ import os
from mopidy import settings from mopidy import settings
from mopidy.utils.path import mtime, uri_to_path from mopidy.utils.path import mtime, uri_to_path
from mopidy.frontends.mpd import translator, protocol from mopidy.frontends.mpd import translator, protocol
from mopidy.models import Album, Artist, CpTrack, Playlist, Track from mopidy.models import Album, Artist, TlTrack, Playlist, Track
from tests import unittest from tests import unittest
@ -46,19 +46,19 @@ class TrackMpdFormatTest(unittest.TestCase):
result = translator.track_to_mpd_format(Track(), position=1) result = translator.track_to_mpd_format(Track(), position=1)
self.assertNotIn(('Pos', 1), result) self.assertNotIn(('Pos', 1), result)
def test_track_to_mpd_format_with_cpid(self): def test_track_to_mpd_format_with_tlid(self):
result = translator.track_to_mpd_format(CpTrack(1, Track())) result = translator.track_to_mpd_format(TlTrack(1, Track()))
self.assertNotIn(('Id', 1), result) self.assertNotIn(('Id', 1), result)
def test_track_to_mpd_format_with_position_and_cpid(self): def test_track_to_mpd_format_with_position_and_tlid(self):
result = translator.track_to_mpd_format( result = translator.track_to_mpd_format(
CpTrack(2, Track()), position=1) TlTrack(2, Track()), position=1)
self.assertIn(('Pos', 1), result) self.assertIn(('Pos', 1), result)
self.assertIn(('Id', 2), result) self.assertIn(('Id', 2), result)
def test_track_to_mpd_format_for_nonempty_track(self): def test_track_to_mpd_format_for_nonempty_track(self):
result = translator.track_to_mpd_format( result = translator.track_to_mpd_format(
CpTrack(122, self.track), position=9) TlTrack(122, self.track), position=9)
self.assertIn(('file', 'a uri'), result) self.assertIn(('file', 'a uri'), result)
self.assertIn(('Time', 137), result) self.assertIn(('Time', 137), result)
self.assertIn(('Artist', 'an artist'), result) self.assertIn(('Artist', 'an artist'), result)

View File

@ -131,21 +131,21 @@ class StatusHandlerTest(unittest.TestCase):
self.assertEqual(result['state'], 'pause') self.assertEqual(result['state'], 'pause')
def test_status_method_when_playlist_loaded_contains_song(self): def test_status_method_when_playlist_loaded_contains_song(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.core.playback.play() self.core.playback.play()
result = dict(status.status(self.context)) result = dict(status.status(self.context))
self.assertIn('song', result) self.assertIn('song', result)
self.assertGreaterEqual(int(result['song']), 0) self.assertGreaterEqual(int(result['song']), 0)
def test_status_method_when_playlist_loaded_contains_cpid_as_songid(self): def test_status_method_when_playlist_loaded_contains_tlid_as_songid(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.core.playback.play() self.core.playback.play()
result = dict(status.status(self.context)) result = dict(status.status(self.context))
self.assertIn('songid', result) self.assertIn('songid', result)
self.assertEqual(int(result['songid']), 0) self.assertEqual(int(result['songid']), 0)
def test_status_method_when_playing_contains_time_with_no_length(self): def test_status_method_when_playing_contains_time_with_no_length(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=None)]) self.core.tracklist.append([Track(uri='dummy:a', length=None)])
self.core.playback.play() self.core.playback.play()
result = dict(status.status(self.context)) result = dict(status.status(self.context))
self.assertIn('time', result) self.assertIn('time', result)
@ -155,7 +155,7 @@ class StatusHandlerTest(unittest.TestCase):
self.assertLessEqual(position, total) self.assertLessEqual(position, total)
def test_status_method_when_playing_contains_time_with_length(self): def test_status_method_when_playing_contains_time_with_length(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=10000)]) self.core.tracklist.append([Track(uri='dummy:a', length=10000)])
self.core.playback.play() self.core.playback.play()
result = dict(status.status(self.context)) result = dict(status.status(self.context))
self.assertIn('time', result) self.assertIn('time', result)
@ -165,7 +165,7 @@ class StatusHandlerTest(unittest.TestCase):
self.assertLessEqual(position, total) self.assertLessEqual(position, total)
def test_status_method_when_playing_contains_elapsed(self): def test_status_method_when_playing_contains_elapsed(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=60000)]) self.core.tracklist.append([Track(uri='dummy:a', length=60000)])
self.core.playback.play() self.core.playback.play()
self.core.playback.pause() self.core.playback.pause()
self.core.playback.seek(59123) self.core.playback.seek(59123)
@ -174,7 +174,7 @@ class StatusHandlerTest(unittest.TestCase):
self.assertEqual(result['elapsed'], '59.123') self.assertEqual(result['elapsed'], '59.123')
def test_status_method_when_starting_playing_contains_elapsed_zero(self): def test_status_method_when_starting_playing_contains_elapsed_zero(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=10000)]) self.core.tracklist.append([Track(uri='dummy:a', length=10000)])
self.core.playback.play() self.core.playback.play()
self.core.playback.pause() self.core.playback.pause()
result = dict(status.status(self.context)) result = dict(status.status(self.context))
@ -182,7 +182,7 @@ class StatusHandlerTest(unittest.TestCase):
self.assertEqual(result['elapsed'], '0.000') self.assertEqual(result['elapsed'], '0.000')
def test_status_method_when_playing_contains_bitrate(self): def test_status_method_when_playing_contains_bitrate(self):
self.core.current_playlist.append([Track(uri='dummy:a', bitrate=320)]) self.core.tracklist.append([Track(uri='dummy:a', bitrate=320)])
self.core.playback.play() self.core.playback.play()
result = dict(status.status(self.context)) result = dict(status.status(self.context))
self.assertIn('bitrate', result) self.assertIn('bitrate', result)

View File

@ -60,7 +60,7 @@ class PlayerInterfaceTest(unittest.TestCase):
result = self.mpris.Get(objects.PLAYER_IFACE, 'LoopStatus') result = self.mpris.Get(objects.PLAYER_IFACE, 'LoopStatus')
self.assertEqual('Track', result) self.assertEqual('Track', result)
def test_get_loop_status_is_playlist_when_looping_current_playlist(self): def test_get_loop_status_is_playlist_when_looping_tracklist(self):
self.core.playback.repeat = True self.core.playback.repeat = True
self.core.playback.single = False self.core.playback.single = False
result = self.mpris.Get(objects.PLAYER_IFACE, 'LoopStatus') result = self.mpris.Get(objects.PLAYER_IFACE, 'LoopStatus')
@ -101,7 +101,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_set_rate_is_ignored_if_can_control_is_false(self): def test_set_rate_is_ignored_if_can_control_is_false(self):
self.mpris.get_CanControl = lambda *_: False self.mpris.get_CanControl = lambda *_: False
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
@ -109,7 +109,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
def test_set_rate_to_zero_pauses_playback(self): def test_set_rate_to_zero_pauses_playback(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
@ -149,38 +149,38 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertIn('mpris:trackid', result.keys()) self.assertIn('mpris:trackid', result.keys())
self.assertEqual(result['mpris:trackid'], '') self.assertEqual(result['mpris:trackid'], '')
def test_get_metadata_has_trackid_based_on_cpid(self): def test_get_metadata_has_trackid_based_on_tlid(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.core.playback.play() self.core.playback.play()
(cpid, track) = self.core.playback.current_cp_track.get() (tlid, track) = self.core.playback.current_tl_track.get()
result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata')
self.assertIn('mpris:trackid', result.keys()) self.assertIn('mpris:trackid', result.keys())
self.assertEqual( self.assertEqual(
result['mpris:trackid'], '/com/mopidy/track/%d' % cpid) result['mpris:trackid'], '/com/mopidy/track/%d' % tlid)
def test_get_metadata_has_track_length(self): def test_get_metadata_has_track_length(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata')
self.assertIn('mpris:length', result.keys()) self.assertIn('mpris:length', result.keys())
self.assertEqual(result['mpris:length'], 40000000) self.assertEqual(result['mpris:length'], 40000000)
def test_get_metadata_has_track_uri(self): def test_get_metadata_has_track_uri(self):
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata')
self.assertIn('xesam:url', result.keys()) self.assertIn('xesam:url', result.keys())
self.assertEqual(result['xesam:url'], 'dummy:a') self.assertEqual(result['xesam:url'], 'dummy:a')
def test_get_metadata_has_track_title(self): def test_get_metadata_has_track_title(self):
self.core.current_playlist.append([Track(name='a')]) self.core.tracklist.append([Track(name='a')])
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata')
self.assertIn('xesam:title', result.keys()) self.assertIn('xesam:title', result.keys())
self.assertEqual(result['xesam:title'], 'a') self.assertEqual(result['xesam:title'], 'a')
def test_get_metadata_has_track_artists(self): def test_get_metadata_has_track_artists(self):
self.core.current_playlist.append([Track(artists=[ self.core.tracklist.append([Track(artists=[
Artist(name='a'), Artist(name='b'), Artist(name=None)])]) Artist(name='a'), Artist(name='b'), Artist(name=None)])])
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata')
@ -188,14 +188,14 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(result['xesam:artist'], ['a', 'b']) self.assertEqual(result['xesam:artist'], ['a', 'b'])
def test_get_metadata_has_track_album(self): def test_get_metadata_has_track_album(self):
self.core.current_playlist.append([Track(album=Album(name='a'))]) self.core.tracklist.append([Track(album=Album(name='a'))])
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata')
self.assertIn('xesam:album', result.keys()) self.assertIn('xesam:album', result.keys())
self.assertEqual(result['xesam:album'], 'a') self.assertEqual(result['xesam:album'], 'a')
def test_get_metadata_has_track_album_artists(self): def test_get_metadata_has_track_album_artists(self):
self.core.current_playlist.append([Track(album=Album(artists=[ self.core.tracklist.append([Track(album=Album(artists=[
Artist(name='a'), Artist(name='b'), Artist(name=None)]))]) Artist(name='a'), Artist(name='b'), Artist(name=None)]))])
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata')
@ -203,7 +203,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(result['xesam:albumArtist'], ['a', 'b']) self.assertEqual(result['xesam:albumArtist'], ['a', 'b'])
def test_get_metadata_has_track_number_in_album(self): def test_get_metadata_has_track_number_in_album(self):
self.core.current_playlist.append([Track(track_no=7)]) self.core.tracklist.append([Track(track_no=7)])
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata') result = self.mpris.Get(objects.PLAYER_IFACE, 'Metadata')
self.assertIn('xesam:trackNumber', result.keys()) self.assertIn('xesam:trackNumber', result.keys())
@ -246,7 +246,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.volume.get(), 10) self.assertEqual(self.core.playback.volume.get(), 10)
def test_get_position_returns_time_position_in_microseconds(self): def test_get_position_returns_time_position_in_microseconds(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
self.core.playback.seek(10000) self.core.playback.seek(10000)
result_in_microseconds = self.mpris.Get( result_in_microseconds = self.mpris.Get(
@ -270,7 +270,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_can_go_next_is_true_if_can_control_and_other_next_track(self): def test_can_go_next_is_true_if_can_control_and_other_next_track(self):
self.mpris.get_CanControl = lambda *_: True self.mpris.get_CanControl = lambda *_: True
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'CanGoNext') result = self.mpris.Get(objects.PLAYER_IFACE, 'CanGoNext')
@ -278,7 +278,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_can_go_next_is_false_if_next_track_is_the_same(self): def test_can_go_next_is_false_if_next_track_is_the_same(self):
self.mpris.get_CanControl = lambda *_: True self.mpris.get_CanControl = lambda *_: True
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.core.playback.repeat = True self.core.playback.repeat = True
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'CanGoNext') result = self.mpris.Get(objects.PLAYER_IFACE, 'CanGoNext')
@ -286,7 +286,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_can_go_next_is_false_if_can_control_is_false(self): def test_can_go_next_is_false_if_can_control_is_false(self):
self.mpris.get_CanControl = lambda *_: False self.mpris.get_CanControl = lambda *_: False
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'CanGoNext') result = self.mpris.Get(objects.PLAYER_IFACE, 'CanGoNext')
@ -294,7 +294,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_can_go_previous_is_true_if_can_control_and_previous_track(self): def test_can_go_previous_is_true_if_can_control_and_previous_track(self):
self.mpris.get_CanControl = lambda *_: True self.mpris.get_CanControl = lambda *_: True
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.next() self.core.playback.next()
@ -303,7 +303,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_can_go_previous_is_false_if_previous_track_is_the_same(self): def test_can_go_previous_is_false_if_previous_track_is_the_same(self):
self.mpris.get_CanControl = lambda *_: True self.mpris.get_CanControl = lambda *_: True
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.core.playback.repeat = True self.core.playback.repeat = True
self.core.playback.play() self.core.playback.play()
result = self.mpris.Get(objects.PLAYER_IFACE, 'CanGoPrevious') result = self.mpris.Get(objects.PLAYER_IFACE, 'CanGoPrevious')
@ -311,7 +311,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_can_go_previous_is_false_if_can_control_is_false(self): def test_can_go_previous_is_false_if_can_control_is_false(self):
self.mpris.get_CanControl = lambda *_: False self.mpris.get_CanControl = lambda *_: False
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.next() self.core.playback.next()
@ -320,7 +320,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_can_play_is_true_if_can_control_and_current_track(self): def test_can_play_is_true_if_can_control_and_current_track(self):
self.mpris.get_CanControl = lambda *_: True self.mpris.get_CanControl = lambda *_: True
self.core.current_playlist.append([Track(uri='dummy:a')]) self.core.tracklist.append([Track(uri='dummy:a')])
self.core.playback.play() self.core.playback.play()
self.assertTrue(self.core.playback.current_track.get()) self.assertTrue(self.core.playback.current_track.get())
result = self.mpris.Get(objects.PLAYER_IFACE, 'CanPlay') result = self.mpris.Get(objects.PLAYER_IFACE, 'CanPlay')
@ -363,7 +363,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_next_is_ignored_if_can_go_next_is_false(self): def test_next_is_ignored_if_can_go_next_is_false(self):
self.mpris.get_CanGoNext = lambda *_: False self.mpris.get_CanGoNext = lambda *_: False
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a') self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a')
@ -371,7 +371,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a') self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a')
def test_next_when_playing_skips_to_next_track_and_keep_playing(self): def test_next_when_playing_skips_to_next_track_and_keep_playing(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a') self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a')
@ -381,7 +381,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
def test_next_when_at_end_of_list_should_stop_playback(self): def test_next_when_at_end_of_list_should_stop_playback(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.next() self.core.playback.next()
@ -391,7 +391,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), STOPPED) self.assertEqual(self.core.playback.state.get(), STOPPED)
def test_next_when_paused_should_skip_to_next_track_and_stay_paused(self): def test_next_when_paused_should_skip_to_next_track_and_stay_paused(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.pause() self.core.playback.pause()
@ -402,7 +402,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), PAUSED) self.assertEqual(self.core.playback.state.get(), PAUSED)
def test_next_when_stopped_skips_to_next_track_and_stay_stopped(self): def test_next_when_stopped_skips_to_next_track_and_stay_stopped(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.stop() self.core.playback.stop()
@ -414,7 +414,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_previous_is_ignored_if_can_go_previous_is_false(self): def test_previous_is_ignored_if_can_go_previous_is_false(self):
self.mpris.get_CanGoPrevious = lambda *_: False self.mpris.get_CanGoPrevious = lambda *_: False
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.next() self.core.playback.next()
@ -423,7 +423,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:b') self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:b')
def test_previous_when_playing_skips_to_prev_track_and_keep_playing(self): def test_previous_when_playing_skips_to_prev_track_and_keep_playing(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.next() self.core.playback.next()
@ -434,7 +434,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
def test_previous_when_at_start_of_list_should_stop_playback(self): def test_previous_when_at_start_of_list_should_stop_playback(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a') self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a')
@ -443,7 +443,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), STOPPED) self.assertEqual(self.core.playback.state.get(), STOPPED)
def test_previous_when_paused_skips_to_previous_track_and_pause(self): def test_previous_when_paused_skips_to_previous_track_and_pause(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.next() self.core.playback.next()
@ -455,7 +455,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), PAUSED) self.assertEqual(self.core.playback.state.get(), PAUSED)
def test_previous_when_stopped_skips_to_previous_track_and_stops(self): def test_previous_when_stopped_skips_to_previous_track_and_stops(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.next() self.core.playback.next()
@ -468,7 +468,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_pause_is_ignored_if_can_pause_is_false(self): def test_pause_is_ignored_if_can_pause_is_false(self):
self.mpris.get_CanPause = lambda *_: False self.mpris.get_CanPause = lambda *_: False
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
@ -476,7 +476,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
def test_pause_when_playing_should_pause_playback(self): def test_pause_when_playing_should_pause_playback(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
@ -484,7 +484,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), PAUSED) self.assertEqual(self.core.playback.state.get(), PAUSED)
def test_pause_when_paused_has_no_effect(self): def test_pause_when_paused_has_no_effect(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.pause() self.core.playback.pause()
@ -494,7 +494,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_playpause_is_ignored_if_can_pause_is_false(self): def test_playpause_is_ignored_if_can_pause_is_false(self):
self.mpris.get_CanPause = lambda *_: False self.mpris.get_CanPause = lambda *_: False
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
@ -502,7 +502,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
def test_playpause_when_playing_should_pause_playback(self): def test_playpause_when_playing_should_pause_playback(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
@ -510,7 +510,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), PAUSED) self.assertEqual(self.core.playback.state.get(), PAUSED)
def test_playpause_when_paused_should_resume_playback(self): def test_playpause_when_paused_should_resume_playback(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.pause() self.core.playback.pause()
@ -526,7 +526,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertGreaterEqual(after_pause, at_pause) self.assertGreaterEqual(after_pause, at_pause)
def test_playpause_when_stopped_should_start_playback(self): def test_playpause_when_stopped_should_start_playback(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.assertEqual(self.core.playback.state.get(), STOPPED) self.assertEqual(self.core.playback.state.get(), STOPPED)
self.mpris.PlayPause() self.mpris.PlayPause()
@ -534,7 +534,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_stop_is_ignored_if_can_control_is_false(self): def test_stop_is_ignored_if_can_control_is_false(self):
self.mpris.get_CanControl = lambda *_: False self.mpris.get_CanControl = lambda *_: False
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
@ -542,7 +542,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
def test_stop_when_playing_should_stop_playback(self): def test_stop_when_playing_should_stop_playback(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
@ -550,7 +550,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.state.get(), STOPPED) self.assertEqual(self.core.playback.state.get(), STOPPED)
def test_stop_when_paused_should_stop_playback(self): def test_stop_when_paused_should_stop_playback(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.pause() self.core.playback.pause()
@ -560,21 +560,21 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_play_is_ignored_if_can_play_is_false(self): def test_play_is_ignored_if_can_play_is_false(self):
self.mpris.get_CanPlay = lambda *_: False self.mpris.get_CanPlay = lambda *_: False
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.assertEqual(self.core.playback.state.get(), STOPPED) self.assertEqual(self.core.playback.state.get(), STOPPED)
self.mpris.Play() self.mpris.Play()
self.assertEqual(self.core.playback.state.get(), STOPPED) self.assertEqual(self.core.playback.state.get(), STOPPED)
def test_play_when_stopped_starts_playback(self): def test_play_when_stopped_starts_playback(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.assertEqual(self.core.playback.state.get(), STOPPED) self.assertEqual(self.core.playback.state.get(), STOPPED)
self.mpris.Play() self.mpris.Play()
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)
def test_play_after_pause_resumes_from_same_position(self): def test_play_after_pause_resumes_from_same_position(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
before_pause = self.core.playback.time_position.get() before_pause = self.core.playback.time_position.get()
@ -591,14 +591,14 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertGreaterEqual(after_pause, at_pause) self.assertGreaterEqual(after_pause, at_pause)
def test_play_when_there_is_no_track_has_no_effect(self): def test_play_when_there_is_no_track_has_no_effect(self):
self.core.current_playlist.clear() self.core.tracklist.clear()
self.assertEqual(self.core.playback.state.get(), STOPPED) self.assertEqual(self.core.playback.state.get(), STOPPED)
self.mpris.Play() self.mpris.Play()
self.assertEqual(self.core.playback.state.get(), STOPPED) self.assertEqual(self.core.playback.state.get(), STOPPED)
def test_seek_is_ignored_if_can_seek_is_false(self): def test_seek_is_ignored_if_can_seek_is_false(self):
self.mpris.get_CanSeek = lambda *_: False self.mpris.get_CanSeek = lambda *_: False
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
before_seek = self.core.playback.time_position.get() before_seek = self.core.playback.time_position.get()
@ -614,7 +614,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertLess(after_seek, before_seek + milliseconds_to_seek) self.assertLess(after_seek, before_seek + milliseconds_to_seek)
def test_seek_seeks_given_microseconds_forward_in_the_current_track(self): def test_seek_seeks_given_microseconds_forward_in_the_current_track(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
before_seek = self.core.playback.time_position.get() before_seek = self.core.playback.time_position.get()
@ -631,7 +631,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertGreaterEqual(after_seek, before_seek + milliseconds_to_seek) self.assertGreaterEqual(after_seek, before_seek + milliseconds_to_seek)
def test_seek_seeks_given_microseconds_backward_if_negative(self): def test_seek_seeks_given_microseconds_backward_if_negative(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
self.core.playback.seek(20000) self.core.playback.seek(20000)
@ -650,7 +650,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertLess(after_seek, before_seek) self.assertLess(after_seek, before_seek)
def test_seek_seeks_to_start_of_track_if_new_position_is_negative(self): def test_seek_seeks_to_start_of_track_if_new_position_is_negative(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
self.core.playback.seek(20000) self.core.playback.seek(20000)
@ -670,7 +670,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertGreaterEqual(after_seek, 0) self.assertGreaterEqual(after_seek, 0)
def test_seek_skips_to_next_track_if_new_position_gt_track_length(self): def test_seek_skips_to_next_track_if_new_position_gt_track_length(self):
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a', length=40000), Track(uri='dummy:a', length=40000),
Track(uri='dummy:b')]) Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
@ -695,7 +695,7 @@ class PlayerInterfaceTest(unittest.TestCase):
def test_set_position_is_ignored_if_can_seek_is_false(self): def test_set_position_is_ignored_if_can_seek_is_false(self):
self.mpris.get_CanSeek = lambda *_: False self.mpris.get_CanSeek = lambda *_: False
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
before_set_position = self.core.playback.time_position.get() before_set_position = self.core.playback.time_position.get()
@ -713,7 +713,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertLess(after_set_position, position_to_set_in_millisec) self.assertLess(after_set_position, position_to_set_in_millisec)
def test_set_position_sets_the_current_track_position_in_microsecs(self): def test_set_position_sets_the_current_track_position_in_microsecs(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
before_set_position = self.core.playback.time_position.get() before_set_position = self.core.playback.time_position.get()
@ -734,7 +734,7 @@ class PlayerInterfaceTest(unittest.TestCase):
after_set_position, position_to_set_in_millisec) after_set_position, position_to_set_in_millisec)
def test_set_position_does_nothing_if_the_position_is_negative(self): def test_set_position_does_nothing_if_the_position_is_negative(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
self.core.playback.seek(20000) self.core.playback.seek(20000)
@ -757,7 +757,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a') self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a')
def test_set_position_does_nothing_if_position_is_gt_track_length(self): def test_set_position_does_nothing_if_position_is_gt_track_length(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
self.core.playback.seek(20000) self.core.playback.seek(20000)
@ -780,7 +780,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a') self.assertEqual(self.core.playback.current_track.get().uri, 'dummy:a')
def test_set_position_is_noop_if_track_id_isnt_current_track(self): def test_set_position_is_noop_if_track_id_isnt_current_track(self):
self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) self.core.tracklist.append([Track(uri='dummy:a', length=40000)])
self.core.playback.play() self.core.playback.play()
self.core.playback.seek(20000) self.core.playback.seek(20000)
@ -807,7 +807,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.backend.library.dummy_library = [ self.backend.library.dummy_library = [
Track(uri='dummy:/test/uri')] Track(uri='dummy:/test/uri')]
self.mpris.OpenUri('dummy:/test/uri') self.mpris.OpenUri('dummy:/test/uri')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 0) self.assertEqual(len(self.core.tracklist.tracks.get()), 0)
def test_open_uri_ignores_uris_with_unknown_uri_scheme(self): def test_open_uri_ignores_uris_with_unknown_uri_scheme(self):
self.assertListEqual(self.core.uri_schemes.get(), ['dummy']) self.assertListEqual(self.core.uri_schemes.get(), ['dummy'])
@ -815,21 +815,21 @@ class PlayerInterfaceTest(unittest.TestCase):
self.backend.library.dummy_library = [ self.backend.library.dummy_library = [
Track(uri='notdummy:/test/uri')] Track(uri='notdummy:/test/uri')]
self.mpris.OpenUri('notdummy:/test/uri') self.mpris.OpenUri('notdummy:/test/uri')
self.assertEqual(len(self.core.current_playlist.tracks.get()), 0) self.assertEqual(len(self.core.tracklist.tracks.get()), 0)
def test_open_uri_adds_uri_to_current_playlist(self): def test_open_uri_adds_uri_to_tracklist(self):
self.mpris.get_CanPlay = lambda *_: True self.mpris.get_CanPlay = lambda *_: True
self.backend.library.dummy_library = [ self.backend.library.dummy_library = [
Track(uri='dummy:/test/uri')] Track(uri='dummy:/test/uri')]
self.mpris.OpenUri('dummy:/test/uri') self.mpris.OpenUri('dummy:/test/uri')
self.assertEqual( self.assertEqual(
self.core.current_playlist.tracks.get()[0].uri, 'dummy:/test/uri') self.core.tracklist.tracks.get()[0].uri, 'dummy:/test/uri')
def test_open_uri_starts_playback_of_new_track_if_stopped(self): def test_open_uri_starts_playback_of_new_track_if_stopped(self):
self.mpris.get_CanPlay = lambda *_: True self.mpris.get_CanPlay = lambda *_: True
self.backend.library.dummy_library = [ self.backend.library.dummy_library = [
Track(uri='dummy:/test/uri')] Track(uri='dummy:/test/uri')]
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.assertEqual(self.core.playback.state.get(), STOPPED) self.assertEqual(self.core.playback.state.get(), STOPPED)
@ -843,7 +843,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.mpris.get_CanPlay = lambda *_: True self.mpris.get_CanPlay = lambda *_: True
self.backend.library.dummy_library = [ self.backend.library.dummy_library = [
Track(uri='dummy:/test/uri')] Track(uri='dummy:/test/uri')]
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.core.playback.pause() self.core.playback.pause()
@ -860,7 +860,7 @@ class PlayerInterfaceTest(unittest.TestCase):
self.mpris.get_CanPlay = lambda *_: True self.mpris.get_CanPlay = lambda *_: True
self.backend.library.dummy_library = [ self.backend.library.dummy_library = [
Track(uri='dummy:/test/uri')] Track(uri='dummy:/test/uri')]
self.core.current_playlist.append([ self.core.tracklist.append([
Track(uri='dummy:a'), Track(uri='dummy:b')]) Track(uri='dummy:a'), Track(uri='dummy:b')])
self.core.playback.play() self.core.playback.play()
self.assertEqual(self.core.playback.state.get(), PLAYING) self.assertEqual(self.core.playback.state.get(), PLAYING)

View File

@ -2,7 +2,7 @@ from __future__ import unicode_literals
import datetime import datetime
from mopidy.models import Artist, Album, CpTrack, Track, Playlist from mopidy.models import Artist, Album, TlTrack, Track, Playlist
from tests import unittest from tests import unittest
@ -314,19 +314,19 @@ class AlbumTest(unittest.TestCase):
self.assertNotEqual(hash(album1), hash(album2)) self.assertNotEqual(hash(album1), hash(album2))
class CpTrackTest(unittest.TestCase): class TlTrackTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.cpid = 123 self.tlid = 123
self.track = Track() self.track = Track()
self.cp_track = CpTrack(self.cpid, self.track) self.tl_track = TlTrack(self.tlid, self.track)
def test_cp_track_can_be_accessed_as_a_tuple(self): def test_tl_track_can_be_accessed_as_a_tuple(self):
self.assertEqual(self.cpid, self.cp_track[0]) self.assertEqual(self.tlid, self.tl_track[0])
self.assertEqual(self.track, self.cp_track[1]) self.assertEqual(self.track, self.tl_track[1])
def test_cp_track_can_be_accessed_by_attribute_names(self): def test_tl_track_can_be_accessed_by_attribute_names(self):
self.assertEqual(self.cpid, self.cp_track.cpid) self.assertEqual(self.tlid, self.tl_track.tlid)
self.assertEqual(self.track, self.cp_track.track) self.assertEqual(self.track, self.tl_track.track)
class TrackTest(unittest.TestCase): class TrackTest(unittest.TestCase):