From da67213a5f998e8013e7db5f15374de75088f1f6 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Mon, 9 Aug 2010 09:53:46 +0200 Subject: [PATCH 001/138] initial prototype to have libspotify backend to use gstreamer --- mopidy/backends/libspotify.py | 38 ++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/mopidy/backends/libspotify.py b/mopidy/backends/libspotify.py index 4f1b2049..32444612 100644 --- a/mopidy/backends/libspotify.py +++ b/mopidy/backends/libspotify.py @@ -14,8 +14,7 @@ from mopidy.backends import (BaseBackend, BaseCurrentPlaylistController, BaseStoredPlaylistsController) from mopidy.models import Artist, Album, Track, Playlist -import alsaaudio - +import gst logger = logging.getLogger('mopidy.backends.libspotify') ENCODING = 'utf-8' @@ -200,9 +199,29 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): threading.Thread.__init__(self) self.core_queue = core_queue self.connected = threading.Event() - self.audio = audio_controller_class(alsaaudio.PCM_NORMAL) self.session = None + cap_string = """audio/x-raw-int, + endianness=(int)1234, + channels=(int)2, + width=(int)16, + depth=(int)16, + signed=True, + rate=(int)44100""" + caps = gst.caps_from_string(cap_string) + + self.gsrc = gst.element_factory_make("appsrc", "app-source") + self.gsrc.set_property('caps', caps) + + self.gsink = gst.element_factory_make("autoaudiosink", "autosink") + + self.pipeline = gst.Pipeline("spotify_pipeline") + self.pipeline.add(self.gsrc, self.gsink) + + gst.element_link_many(self.gsrc, self.gsink) + + self.pipeline.set_state(gst.STATE_PLAYING) + def run(self): self.connect() @@ -243,8 +262,17 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): def music_delivery(self, session, frames, frame_size, num_frames, sample_type, sample_rate, channels): """Callback used by pyspotify""" - self.audio.music_delivery(session, frames, frame_size, num_frames, - sample_type, sample_rate, channels) + cap_string = """audio/x-raw-int, + endianness=(int)1234, + channels=(int)2, + width=(int)16, + depth=(int)16, + signed=True, + rate=(int)44100""" + caps = gst.caps_from_string(cap_string) + b = gst.Buffer(frames) + b.set_caps(caps) + self.gsrc.emit('push-buffer', b) def play_token_lost(self, session): """Callback used by pyspotify""" From 659b879e9c18892dfd7b9c96e319011fb4da9dde Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Mon, 9 Aug 2010 18:23:46 +0200 Subject: [PATCH 002/138] moved gstreamer pipeline initialization to backend class to flush the buffer on stop/play and removed audiocontroller arguments --- mopidy/backends/libspotify.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mopidy/backends/libspotify.py b/mopidy/backends/libspotify.py index 047f1328..8e193949 100644 --- a/mopidy/backends/libspotify.py +++ b/mopidy/backends/libspotify.py @@ -43,8 +43,7 @@ class LibspotifyBackend(BaseBackend): self.stored_playlists = LibspotifyStoredPlaylistsController( backend=self) self.uri_handlers = [u'spotify:', u'http://open.spotify.com/'] - self.audio_controller_class = kwargs.get( - 'audio_controller_class', AlsaController) + self.gstreamer_pipeline = gst.Pipeline("spotify_pipeline") self.spotify = self._connect() def _connect(self): @@ -52,7 +51,7 @@ class LibspotifyBackend(BaseBackend): spotify = LibspotifySessionManager( settings.SPOTIFY_USERNAME, settings.SPOTIFY_PASSWORD, core_queue=self.core_queue, - audio_controller_class=self.audio_controller_class) + gstreamer_pipeline=self.gstreamer_pipeline) spotify.start() return spotify @@ -99,6 +98,7 @@ class LibspotifyPlaybackController(BasePlaybackController): return False def _play(self, track): + self.backend.gstreamer_pipeline.set_state(gst.STATE_READY) if self.state == self.PLAYING: self.stop() if track.uri is None: @@ -107,6 +107,7 @@ class LibspotifyPlaybackController(BasePlaybackController): self.backend.spotify.session.load( Link.from_string(track.uri).as_track()) self.backend.spotify.session.play(1) + self.backend.gstreamer_pipeline.set_state(gst.STATE_PLAYING) return True except SpotifyError as e: logger.warning('Play %s failed: %s', track.uri, e) @@ -120,6 +121,7 @@ class LibspotifyPlaybackController(BasePlaybackController): pass # TODO def _stop(self): + self.backend.gstreamer_pipeline.set_state(gst.STATE_READY) self.backend.spotify.session.play(0) return True @@ -201,12 +203,13 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): appkey_file = os.path.expanduser(settings.SPOTIFY_LIB_APPKEY) user_agent = 'Mopidy %s' % get_version() - def __init__(self, username, password, core_queue, audio_controller_class): + def __init__(self, username, password, core_queue, gstreamer_pipeline): SpotifySessionManager.__init__(self, username, password) threading.Thread.__init__(self) self.core_queue = core_queue self.connected = threading.Event() self.session = None + self.gstreamer_pipeline = gstreamer_pipeline cap_string = """audio/x-raw-int, endianness=(int)1234, @@ -222,13 +225,10 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): self.gsink = gst.element_factory_make("autoaudiosink", "autosink") - self.pipeline = gst.Pipeline("spotify_pipeline") - self.pipeline.add(self.gsrc, self.gsink) + self.gstreamer_pipeline.add(self.gsrc, self.gsink) gst.element_link_many(self.gsrc, self.gsink) - self.pipeline.set_state(gst.STATE_PLAYING) - def run(self): self.connect() From d509c12c1e02e79c247c162ca7f28b15532301d5 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Tue, 10 Aug 2010 13:24:58 +0200 Subject: [PATCH 003/138] emit end-of-stream in end of track callback, pull for gstreamer end-of-stream messages and send end of track mpd command --- mopidy/backends/libspotify.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/mopidy/backends/libspotify.py b/mopidy/backends/libspotify.py index 8e193949..159cbf75 100644 --- a/mopidy/backends/libspotify.py +++ b/mopidy/backends/libspotify.py @@ -196,6 +196,21 @@ class LibspotifyTranslator(object): tracks=[cls.to_mopidy_track(t) for t in spotify_playlist], ) +class GstreamerMessageBusProcess(threading.Thread): + def __init__(self, core_queue, pipeline): + super(GstreamerMessageBusProcess, self).__init__() + self.core_queue = core_queue + self.bus = pipeline.get_bus() + + def run(self): + while True: + message = self.bus.pop() + if message is not None: + logger.debug('Got Gstreamer message of type: %s' % message.type) + if message is not None and ( + message.type == gst.MESSAGE_EOS + or message.type == gst.MESSAGE_ERROR): + self.core_queue.put({'command': 'end_of_track'}) class LibspotifySessionManager(SpotifySessionManager, threading.Thread): cache_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) @@ -229,6 +244,9 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): gst.element_link_many(self.gsrc, self.gsink) + message_process = GstreamerMessageBusProcess(self.core_queue, self.gstreamer_pipeline) + message_process.start() + def run(self): self.connect() @@ -292,8 +310,9 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): def end_of_track(self, session): """Callback used by pyspotify""" - logger.debug('End of track') - self.core_queue.put({'command': 'end_of_track'}) + logger.debug('End of track.') + self.gsrc.emit('end-of-stream') + logger.debug('End of stream sent to gstreamer.') def search(self, query, connection): """Search method used by Mopidy backend""" From ae46832e62a1270146c506faaca46acf254d58d6 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Tue, 10 Aug 2010 14:52:16 +0200 Subject: [PATCH 004/138] block gstreamer loop to avoid 100% cpu and avoid C-threads to freeze --- mopidy/backends/libspotify.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mopidy/backends/libspotify.py b/mopidy/backends/libspotify.py index 159cbf75..63cb62e4 100644 --- a/mopidy/backends/libspotify.py +++ b/mopidy/backends/libspotify.py @@ -1,4 +1,5 @@ import datetime as dt +import gobject import logging import os import multiprocessing @@ -203,14 +204,15 @@ class GstreamerMessageBusProcess(threading.Thread): self.bus = pipeline.get_bus() def run(self): + loop = gobject.MainLoop() + gobject.threads_init() + context = loop.get_context() while True: - message = self.bus.pop() + message = self.bus.pop_filtered(gst.MESSAGE_EOS) if message is not None: - logger.debug('Got Gstreamer message of type: %s' % message.type) - if message is not None and ( - message.type == gst.MESSAGE_EOS - or message.type == gst.MESSAGE_ERROR): self.core_queue.put({'command': 'end_of_track'}) + logger.debug('Got and handled Gstreamer message of type: %s' % message.type) + context.iteration(True) class LibspotifySessionManager(SpotifySessionManager, threading.Thread): cache_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) From ada20b7af100e9067056c6f76fe643e601d55969 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Tue, 10 Aug 2010 16:46:46 +0200 Subject: [PATCH 005/138] simple libspotify pause/resume implementation --- mopidy/backends/libspotify/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index 5afaa293..0b1f2483 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -95,8 +95,9 @@ class LibspotifyLibraryController(BaseLibraryController): class LibspotifyPlaybackController(BasePlaybackController): def _pause(self): - # TODO - return False + result = self.backend.gstreamer_pipeline.set_state(gst.STATE_PAUSED) + logger.debug('Changed gstreamer state to paused. Result was: %s' % result) + return result == gst.STATE_CHANGE_SUCCESS def _play(self, track): self.backend.gstreamer_pipeline.set_state(gst.STATE_READY) @@ -115,8 +116,9 @@ class LibspotifyPlaybackController(BasePlaybackController): return False def _resume(self): - # TODO - return False + result = self.backend.gstreamer_pipeline.set_state(gst.STATE_PLAYING) + logger.debug('Changed gstreamer state to playing. Result was: %s' % result) + return result == gst.STATE_CHANGE_SUCCESS def _seek(self, time_position): pass # TODO From 6e5e5a8930feecf74f808e3eecab75b3bf999037 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 00:29:44 +0200 Subject: [PATCH 006/138] [WIP] Add GStreamerOutput --- mopidy/outputs/__init__.py | 0 mopidy/outputs/gstreamer.py | 130 ++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 mopidy/outputs/__init__.py create mode 100644 mopidy/outputs/gstreamer.py diff --git a/mopidy/outputs/__init__.py b/mopidy/outputs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py new file mode 100644 index 00000000..16844adf --- /dev/null +++ b/mopidy/outputs/gstreamer.py @@ -0,0 +1,130 @@ +import gobject + +import pygst +pygst.require('0.10') + +import gst +import logging + +from mopidy.process import BaseProcess + +logger = logging.getLogger('mopidy.outputs.gstreamer') + +class GStreamerOutput(object): + """ + Audio output through GStreamer. + + Starts the :class:`GStreamerProcess`. + """ + + def __init__(self, core_queue): + process = GStreamerProcess(core_queue) + process.start() + +class GStreamerProcess(BaseProcess): + """ + A process for all work related to GStreamer. + + The main loop polls for events from both Mopidy and GStreamer. + """ + + def __init__(self, core_queue): + self.core_queue = core_queue + + # See http://www.jejik.com/articles/2007/01/ + # python-gstreamer_threading_and_the_main_loop/ for details. + gobject.threads_init() + self.gobject_context = gobject.MainLoop().get_context() + + # A pipeline consisting of many elements + self.gst_pipeline = gst.Pipeline("pipeline") + + # Setup bus and message processor + self.gst_bus = self.gst_pipeline.get_bus() + self.gst_bus.add_signal_watch() + self.gst_bus_id = self.gst_bus.connect('message', self.process_message) + + # Bin for playing audio URIs + self.gst_uri_src = gst.element_factory_make('uridecodebin', 'uri_src') + self.gst_pipeline.add(self.gst_uri_src) + + # Bin for playing audio data + self.gst_data_src = gst.element_factory_make('appsrc', 'data_src') + self.gst_pipeline.add(self.gst_data_src) + + # Volume filter + self.gst_volume = gst.element_factory_make('volume', 'volume') + self.gst_pipeline.add(self.gst_volume) + + # Audio output sink + self.gst_sink = gst.element_factory_make('autoaudiosink', 'sink') + self.gst_pipeline.add(self.gst_sink) + + # The audio URI chain + gst.element_link_many(self.gst_uri_src, self.gst_volume, self.gst_sink) + + # The audio data chain + gst.element_link_many(self.gst_data_src, self.gst_volume, + self.gst_sink) + + def _run(self): + while True: + # TODO Handle commands + self.gobject_context.iteration(True) + + def process_message(self, bus, message): + if message.type == gst.MESSAGE_EOS: + pass # TODO Handle end of track/stream + elif message.type == gst.MESSAGE_ERROR: + self.gst_bin.set_state(gst.STATE_NULL) + error, debug = message.parse_error() + logger.error(u'%s %s', error, debug) + + def deliver_data(self, caps_string, data): + """Deliver audio data to be played""" + caps = gst.caps_from_string(caps_string) + buffer_ = gst.Buffer(data) + buffer_.set_caps(caps) + self.gst_data_src.emit('push-buffer', buffer_) + + def play_uri(self, uri): + """Play audio at URI""" + self.gst_uri_src.set_state(gst.STATE_READY) + self.gst_uri_src.set_property('uri', uri) + self.gst_uri_src.set_state(gst.STATE_PLAYING) + # TODO Return status + + def state_playing(self): + """ + Set the state to PLAYING. + + Previous state should be READY or PAUSED. + """ + result = self.gst_uri_src.set_state(gst.STATE_PLAYING) + return result == gst.STATE_CHANGE_SUCCESS + + def state_paused(self): + """ + Set the state to PAUSED. + + Previous state should be PLAYING. + """ + result = self.gst_uri_src.set_state(gst.STATE_PAUSED) + return result == gst.STATE_CHANGE_SUCCESS + + def state_ready(self): + """ + Set the state to READY. + """ + result = self.gst_uri_src.set_state(gst.STATE_READY) + return result == gst.STATE_CHANGE_SUCCESS + + def get_volume(self): + """Get volume in range [0..100]""" + gst_volume = self.gst_volume.get_property('volume') + return int(gst_volume * 100) + + def set_volume(self, volume): + """Set volume in range [0..100]""" + gst_volume = volume / 100.0 + self.gst_volume.set_property('volume', gst_volume) From 93e6aa13cf7eff38a0cce394db9439e84839725b Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 00:29:51 +0200 Subject: [PATCH 007/138] [WIP] Add GStreamerMixer --- mopidy/mixers/gstreamer.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 mopidy/mixers/gstreamer.py diff --git a/mopidy/mixers/gstreamer.py b/mopidy/mixers/gstreamer.py new file mode 100644 index 00000000..83394bd0 --- /dev/null +++ b/mopidy/mixers/gstreamer.py @@ -0,0 +1,14 @@ +from mopidy.mixers import BaseMixer + +class GStreamerMixer(BaseMixer): + """Mixer which uses GStreamer to control volume.""" + + def __init__(self, *args, **kwargs): + super(GStreamerMixer, self).__init__(*args, **kwargs) + + def _get_volume(self): + # TODO Get volume from GStreamerProcess + + def _set_volume(self, volume): + # TODO Send volume to GStreamerProcess + From 420bdee1a0e10a43e62c264caeadbdd254bbf6b3 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 19:01:46 +0200 Subject: [PATCH 008/138] GstreamerProcess: Add method for processing msgs from core --- mopidy/outputs/gstreamer.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 16844adf..824eb877 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -42,7 +42,8 @@ class GStreamerProcess(BaseProcess): # Setup bus and message processor self.gst_bus = self.gst_pipeline.get_bus() self.gst_bus.add_signal_watch() - self.gst_bus_id = self.gst_bus.connect('message', self.process_message) + self.gst_bus_id = self.gst_bus.connect('message', + self.process_gst_message) # Bin for playing audio URIs self.gst_uri_src = gst.element_factory_make('uridecodebin', 'uri_src') @@ -72,7 +73,12 @@ class GStreamerProcess(BaseProcess): # TODO Handle commands self.gobject_context.iteration(True) - def process_message(self, bus, message): + def process_core_message(self, message): + """Processes messages from the rest of Mopidy.""" + pass # TODO + + def process_gst_message(self, bus, message): + """Processes message from GStreamer.""" if message.type == gst.MESSAGE_EOS: pass # TODO Handle end of track/stream elif message.type == gst.MESSAGE_ERROR: From dcdc22702eaf6e79416e23ff08f3c955ab6de384 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 19:04:07 +0200 Subject: [PATCH 009/138] GStreamerProcess: Log if state changes succeeds or fails --- mopidy/outputs/gstreamer.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 824eb877..2a282d95 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -95,9 +95,9 @@ class GStreamerProcess(BaseProcess): def play_uri(self, uri): """Play audio at URI""" - self.gst_uri_src.set_state(gst.STATE_READY) + self.state_ready() self.gst_uri_src.set_property('uri', uri) - self.gst_uri_src.set_state(gst.STATE_PLAYING) + self.state_playing() # TODO Return status def state_playing(self): @@ -107,7 +107,12 @@ class GStreamerProcess(BaseProcess): Previous state should be READY or PAUSED. """ result = self.gst_uri_src.set_state(gst.STATE_PLAYING) - return result == gst.STATE_CHANGE_SUCCESS + if result == gst.STATE_CHANGE_SUCCESS: + logger.debug('Setting GStreamer state to PLAYING: OK') + return True + else: + logger.warning('Setting GStreamer state to PLAYING: failed') + return False def state_paused(self): """ @@ -116,14 +121,24 @@ class GStreamerProcess(BaseProcess): Previous state should be PLAYING. """ result = self.gst_uri_src.set_state(gst.STATE_PAUSED) - return result == gst.STATE_CHANGE_SUCCESS + if result == gst.STATE_CHANGE_SUCCESS: + logger.debug('Setting GStreamer state to PAUSED: OK') + return True + else: + logger.warning('Setting GStreamer state to PAUSED: failed') + return False def state_ready(self): """ Set the state to READY. """ result = self.gst_uri_src.set_state(gst.STATE_READY) - return result == gst.STATE_CHANGE_SUCCESS + if result == gst.STATE_CHANGE_SUCCESS: + logger.debug('Setting GStreamer state to READY: OK') + return True + else: + logger.warning('Setting GStreamer state to READY: failed') + return False def get_volume(self): """Get volume in range [0..100]""" From 7721ae3db8b2c0a7dc4f6041358b1d9e50c91719 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 19:04:36 +0200 Subject: [PATCH 010/138] GStreamerProcess: Move all gst init till after the process has started --- mopidy/outputs/gstreamer.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 2a282d95..d3746729 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -29,8 +29,25 @@ class GStreamerProcess(BaseProcess): """ def __init__(self, core_queue): + super(GStreamerProcess, self).__init__() self.core_queue = core_queue + self.gobject_context = None + self.gst_pipeline = None + self.gst_bus = None + self.gst_bus_id = None + self.gst_uri_src = None + self.gst_data_src = None + self.gst_volume = None + self.gst_sink = None + def _run(self): + self.setup() + while True: + message = self.core_queue.get() + self.process_core_message(message) + self.gobject_context.iteration(True) + + def setup(self): # See http://www.jejik.com/articles/2007/01/ # python-gstreamer_threading_and_the_main_loop/ for details. gobject.threads_init() @@ -68,11 +85,6 @@ class GStreamerProcess(BaseProcess): gst.element_link_many(self.gst_data_src, self.gst_volume, self.gst_sink) - def _run(self): - while True: - # TODO Handle commands - self.gobject_context.iteration(True) - def process_core_message(self, message): """Processes messages from the rest of Mopidy.""" pass # TODO From 3bc1d751a34c01f15f0941281895e01c374eec5e Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 19:07:12 +0200 Subject: [PATCH 011/138] Unbreak tests by requiring a GStreamer version before importing 'gst' --- mopidy/backends/libspotify/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index 0b1f2483..b098d0ac 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -5,6 +5,10 @@ import os import multiprocessing import threading +import pygst +pygst.require('0.10') +import gst + from spotify import Link, SpotifyError from spotify.manager import SpotifySessionManager from spotify.alsahelper import AlsaController @@ -15,7 +19,6 @@ from mopidy.backends.base import (BaseBackend, BaseCurrentPlaylistController, BaseStoredPlaylistsController) from mopidy.models import Artist, Album, Track, Playlist -import gst logger = logging.getLogger('mopidy.backends.libspotify') ENCODING = 'utf-8' From 55b5645ba8caef2098fbb706197c459760c646cb Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 19:19:03 +0200 Subject: [PATCH 012/138] GStreamerMixer: Fix syntax error --- mopidy/mixers/gstreamer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mopidy/mixers/gstreamer.py b/mopidy/mixers/gstreamer.py index 83394bd0..3be94db0 100644 --- a/mopidy/mixers/gstreamer.py +++ b/mopidy/mixers/gstreamer.py @@ -7,8 +7,8 @@ class GStreamerMixer(BaseMixer): super(GStreamerMixer, self).__init__(*args, **kwargs) def _get_volume(self): - # TODO Get volume from GStreamerProcess + pass # TODO Get volume from GStreamerProcess def _set_volume(self, volume): - # TODO Send volume to GStreamerProcess + pass # TODO Send volume to GStreamerProcess From 5f16538f7e7f83864daf8c5b3937c012ca5a3991 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 19:19:55 +0200 Subject: [PATCH 013/138] Move (un)pickle_connection from mopidy.{utils => process}. Utils should be as small as possible. --- mopidy/frontends/mpd/server.py | 3 ++- mopidy/process.py | 13 ++++++++++++- mopidy/utils.py | 10 ---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/mopidy/frontends/mpd/server.py b/mopidy/frontends/mpd/server.py index 57b6211f..5bdbb85a 100644 --- a/mopidy/frontends/mpd/server.py +++ b/mopidy/frontends/mpd/server.py @@ -8,7 +8,8 @@ import sys from mopidy import get_mpd_protocol_version, settings from mopidy.frontends.mpd.protocol import ENCODING, LINE_TERMINATOR -from mopidy.utils import indent, pickle_connection +from mopidy.process import pickle_connection +from mopidy.utils import indent logger = logging.getLogger('mopidy.frontends.mpd.server') diff --git a/mopidy/process.py b/mopidy/process.py index d3c1d03e..4a4fa1ae 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -1,12 +1,23 @@ import logging import multiprocessing +from multiprocessing.reduction import reduce_connection +import pickle import sys from mopidy import settings, SettingsError -from mopidy.utils import get_class, unpickle_connection +from mopidy.utils import get_class logger = logging.getLogger('mopidy.process') +def pickle_connection(connection): + return pickle.dumps(reduce_connection(connection)) + +def unpickle_connection(pickled_connection): + # From http://stackoverflow.com/questions/1446004 + (func, args) = pickle.loads(pickled_connection) + return func(*args) + + class BaseProcess(multiprocessing.Process): def run(self): try: diff --git a/mopidy/utils.py b/mopidy/utils.py index 7eac9239..ff032b4e 100644 --- a/mopidy/utils.py +++ b/mopidy/utils.py @@ -1,7 +1,5 @@ import logging -from multiprocessing.reduction import reduce_connection import os -import pickle import sys import urllib @@ -54,14 +52,6 @@ def indent(string, places=4, linebreak='\n'): result += linebreak + ' ' * places + line return result -def pickle_connection(connection): - return pickle.dumps(reduce_connection(connection)) - -def unpickle_connection(pickled_connection): - # From http://stackoverflow.com/questions/1446004 - (func, args) = pickle.loads(pickled_connection) - return func(*args) - def parse_m3u(file_path): """ Convert M3U file list of uris From 1bc62c50468a3b360b6ca5568ee426b60b99fcea Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 19:44:13 +0200 Subject: [PATCH 014/138] GStreamerProcess: One method is better than three --- mopidy/outputs/gstreamer.py | 44 +++++++++---------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index d3746729..3accaaf1 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -107,49 +107,25 @@ class GStreamerProcess(BaseProcess): def play_uri(self, uri): """Play audio at URI""" - self.state_ready() + self.set_state('READY') self.gst_uri_src.set_property('uri', uri) - self.state_playing() + self.set_state('PLAYING') # TODO Return status - def state_playing(self): + def set_state(self, state_name): """ - Set the state to PLAYING. + Set the GStreamer state. Returns :class:`True` if successful. - Previous state should be READY or PAUSED. + :param state_name: READY, PLAYING, or PAUSED + :type state_name: string + :rtype: :class:`True` or :class:`False` """ - result = self.gst_uri_src.set_state(gst.STATE_PLAYING) + result = self.gst_uri_src.set_state(getattr(gst, 'STATE_' + state_name) if result == gst.STATE_CHANGE_SUCCESS: - logger.debug('Setting GStreamer state to PLAYING: OK') + logger.debug('Setting GStreamer state to %s: OK', state_name) return True else: - logger.warning('Setting GStreamer state to PLAYING: failed') - return False - - def state_paused(self): - """ - Set the state to PAUSED. - - Previous state should be PLAYING. - """ - result = self.gst_uri_src.set_state(gst.STATE_PAUSED) - if result == gst.STATE_CHANGE_SUCCESS: - logger.debug('Setting GStreamer state to PAUSED: OK') - return True - else: - logger.warning('Setting GStreamer state to PAUSED: failed') - return False - - def state_ready(self): - """ - Set the state to READY. - """ - result = self.gst_uri_src.set_state(gst.STATE_READY) - if result == gst.STATE_CHANGE_SUCCESS: - logger.debug('Setting GStreamer state to READY: OK') - return True - else: - logger.warning('Setting GStreamer state to READY: failed') + logger.warning('Setting GStreamer state to %s: failed', state_name) return False def get_volume(self): From 5dfc41e3eb2bc032a4e12ea72da8a802fd501580 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 19:44:44 +0200 Subject: [PATCH 015/138] GStreamerProcess: Add initial core_queue message processing --- mopidy/outputs/gstreamer.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 3accaaf1..16dd2f16 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -6,7 +6,7 @@ pygst.require('0.10') import gst import logging -from mopidy.process import BaseProcess +from mopidy.process import BaseProcess, unpickle_connection logger = logging.getLogger('mopidy.outputs.gstreamer') @@ -25,7 +25,7 @@ class GStreamerProcess(BaseProcess): """ A process for all work related to GStreamer. - The main loop polls for events from both Mopidy and GStreamer. + The main loop processes events from both Mopidy and GStreamer. """ def __init__(self, core_queue): @@ -86,11 +86,24 @@ class GStreamerProcess(BaseProcess): self.gst_sink) def process_core_message(self, message): - """Processes messages from the rest of Mopidy.""" - pass # TODO + """Process messages from the rest of Mopidy.""" + assert message['to'] == 'gstreamer', 'Message must be addressed to us' + if message['command'] == 'play_uri': + response = self.play_uri(message['uri']) + connection = unpickle_connection(message['reply_to']) + connection.send(response) + elif message['command'] == 'deliver_data': + # TODO Do we care about sending responses for every data delivery? + self.deliver_data(message['caps'], message['data']) + elif message['command'] == 'set_state': + response = self.set_state(message['state']) + connection = unpickle_connection(message['reply_to']) + connection.send(response) + else: + logger.warning(u'Cannot handle message: %s', message) def process_gst_message(self, bus, message): - """Processes message from GStreamer.""" + """Process messages from GStreamer.""" if message.type == gst.MESSAGE_EOS: pass # TODO Handle end of track/stream elif message.type == gst.MESSAGE_ERROR: From 485e1eb1e53039a6fb8818ad965fb7ec26aac582 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 19:52:32 +0200 Subject: [PATCH 016/138] Rename mopidy.process.BaseProcess.{_run => run_inside_try} --- mopidy/mixers/nad.py | 2 +- mopidy/outputs/gstreamer.py | 5 +++-- mopidy/process.py | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mopidy/mixers/nad.py b/mopidy/mixers/nad.py index 1f7f4710..56958005 100644 --- a/mopidy/mixers/nad.py +++ b/mopidy/mixers/nad.py @@ -83,7 +83,7 @@ class NadTalker(BaseProcess): self.pipe = pipe self._device = None - def _run(self): + def run_inside_try(self): self._open_connection() self._set_device_to_known_state() while self.pipe.poll(None): diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 16dd2f16..49c9d5af 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -40,7 +40,7 @@ class GStreamerProcess(BaseProcess): self.gst_volume = None self.gst_sink = None - def _run(self): + def run_inside_try(self): self.setup() while True: message = self.core_queue.get() @@ -133,7 +133,8 @@ class GStreamerProcess(BaseProcess): :type state_name: string :rtype: :class:`True` or :class:`False` """ - result = self.gst_uri_src.set_state(getattr(gst, 'STATE_' + state_name) + result = self.gst_uri_src.set_state( + getattr(gst, 'STATE_' + state_name)) if result == gst.STATE_CHANGE_SUCCESS: logger.debug('Setting GStreamer state to %s: OK', state_name) return True diff --git a/mopidy/process.py b/mopidy/process.py index 4a4fa1ae..8f11f3a8 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -21,7 +21,7 @@ def unpickle_connection(pickled_connection): class BaseProcess(multiprocessing.Process): def run(self): try: - self._run() + self.run_inside_try() except KeyboardInterrupt: logger.info(u'Interrupted by user') sys.exit(0) @@ -29,7 +29,7 @@ class BaseProcess(multiprocessing.Process): logger.error(e.message) sys.exit(1) - def _run(self): + def run_inside_try(self): raise NotImplementedError @@ -40,7 +40,7 @@ class CoreProcess(BaseProcess): self._backend = None self._frontend = None - def _run(self): + def run_inside_try(self): self._setup() while True: message = self.core_queue.get() From fa4c710007c2fe6779b974013d05a033a2e69eac Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 19:54:04 +0200 Subject: [PATCH 017/138] Get rid of all the _-prefixes in mopidy.process.CoreProcess. This is not Java --- mopidy/process.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mopidy/process.py b/mopidy/process.py index 8f11f3a8..f23ba6fc 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -37,30 +37,30 @@ class CoreProcess(BaseProcess): def __init__(self, core_queue): super(CoreProcess, self).__init__() self.core_queue = core_queue - self._backend = None - self._frontend = None + self.backend = None + self.frontend = None def run_inside_try(self): - self._setup() + self.setup() while True: message = self.core_queue.get() - self._process_message(message) + self.process_message(message) - def _setup(self): - self._backend = get_class(settings.BACKENDS[0])( + def setup(self): + self.backend = get_class(settings.BACKENDS[0])( core_queue=self.core_queue) - self._frontend = get_class(settings.FRONTEND)(backend=self._backend) + self.frontend = get_class(settings.FRONTEND)(backend=self.backend) - def _process_message(self, message): + def process_message(self, message): if message['command'] == 'mpd_request': - response = self._frontend.handle_request(message['request']) + response = self.frontend.handle_request(message['request']) connection = unpickle_connection(message['reply_to']) connection.send(response) elif message['command'] == 'end_of_track': - self._backend.playback.end_of_track_callback() + self.backend.playback.end_of_track_callback() elif message['command'] == 'stop_playback': - self._backend.playback.stop() + self.backend.playback.stop() elif message['command'] == 'set_stored_playlists': - self._backend.stored_playlists.playlists = message['playlists'] + self.backend.stored_playlists.playlists = message['playlists'] else: logger.warning(u'Cannot handle message: %s', message) From 296af3c2af470577aa7f49d7ecaab80a1e8e5d13 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 22:54:46 +0200 Subject: [PATCH 018/138] GStreamerProcess: Now partly tested for the first time. Bunch of fixes. --- mopidy/outputs/gstreamer.py | 58 +++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 49c9d5af..acae6493 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -17,8 +17,8 @@ class GStreamerOutput(object): Starts the :class:`GStreamerProcess`. """ - def __init__(self, core_queue): - process = GStreamerProcess(core_queue) + def __init__(self, core_queue, input_connection): + process = GStreamerProcess(core_queue, input_connection) process.start() class GStreamerProcess(BaseProcess): @@ -28,9 +28,10 @@ class GStreamerProcess(BaseProcess): The main loop processes events from both Mopidy and GStreamer. """ - def __init__(self, core_queue): + def __init__(self, core_queue, input_connection): super(GStreamerProcess, self).__init__() self.core_queue = core_queue + self.input_connection = input_connection self.gobject_context = None self.gst_pipeline = None self.gst_bus = None @@ -43,8 +44,11 @@ class GStreamerProcess(BaseProcess): def run_inside_try(self): self.setup() while True: - message = self.core_queue.get() - self.process_core_message(message) + # FIXME Should we block on poll() or not? Need to see iteration() + # behaviour first. + if self.input_connection.poll(): + message = self.input_connection.recv() + self.process_core_message(message) self.gobject_context.iteration(True) def setup(self): @@ -78,12 +82,25 @@ class GStreamerProcess(BaseProcess): self.gst_sink = gst.element_factory_make('autoaudiosink', 'sink') self.gst_pipeline.add(self.gst_sink) - # The audio URI chain - gst.element_link_many(self.gst_uri_src, self.gst_volume, self.gst_sink) + # Add callback that will link uri_src output with volume filter input + # when the output pad is ready. + # See http://stackoverflow.com/questions/2993777 for details. + def on_new_decoded_pad(dbin, pad, is_last): + uri_src = pad.get_parent() + pipeline = uri_src.get_parent() + volume = pipeline.get_by_name('volume') + uri_src.link(volume) + logger.debug("Linked uri_src's new decoded pad to volume filter") + # FIXME uridecodebin got no new-decoded-pad signal, but it's + # subcomponent decodebin2 got that signal. Fixing this is postponed + # till after data_src is up and running perfectly + #self.gst_uri_src.connect('new-decoded-pad', on_new_decoded_pad) - # The audio data chain - gst.element_link_many(self.gst_data_src, self.gst_volume, - self.gst_sink) + # Link data source output with volume filter input + self.gst_data_src.link(self.gst_volume) + + # Link volume filter output to audio sink input + self.gst_volume.link(self.gst_sink) def process_core_message(self, message): """Process messages from the rest of Mopidy.""" @@ -93,7 +110,7 @@ class GStreamerProcess(BaseProcess): connection = unpickle_connection(message['reply_to']) connection.send(response) elif message['command'] == 'deliver_data': - # TODO Do we care about sending responses for every data delivery? + # FIXME Do we care about sending responses for every data delivery? self.deliver_data(message['caps'], message['data']) elif message['command'] == 'set_state': response = self.set_state(message['state']) @@ -105,11 +122,13 @@ class GStreamerProcess(BaseProcess): def process_gst_message(self, bus, message): """Process messages from GStreamer.""" if message.type == gst.MESSAGE_EOS: - pass # TODO Handle end of track/stream + self.core_queue.put({'message': 'end_of_track'}) elif message.type == gst.MESSAGE_ERROR: - self.gst_bin.set_state(gst.STATE_NULL) + self.set_state('NULL') error, debug = message.parse_error() logger.error(u'%s %s', error, debug) + # FIXME Should we send 'stop_playback' to core here? Can we + # differentiate on how serious the error is? def deliver_data(self, caps_string, data): """Deliver audio data to be played""" @@ -129,11 +148,20 @@ class GStreamerProcess(BaseProcess): """ Set the GStreamer state. Returns :class:`True` if successful. - :param state_name: READY, PLAYING, or PAUSED + .. digraph:: gst_state_transitions + + "NULL" -> "READY" + "PAUSED" -> "PLAYING" + "PAUSED" -> "READY" + "PLAYING" -> "PAUSED" + "READY" -> "NULL" + "READY" -> "PAUSED" + + :param state_name: NULL, READY, PAUSED, or PLAYING :type state_name: string :rtype: :class:`True` or :class:`False` """ - result = self.gst_uri_src.set_state( + result = self.gst_pipeline.set_state( getattr(gst, 'STATE_' + state_name)) if result == gst.STATE_CHANGE_SUCCESS: logger.debug('Setting GStreamer state to %s: OK', state_name) From 6a88f62211faf21ccf015dec26f219f2dffc9f14 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 22:55:54 +0200 Subject: [PATCH 019/138] Add new setting 'OUTPUT' for selecting output handler --- mopidy/settings.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mopidy/settings.py b/mopidy/settings.py index 1192c28d..8fdc3535 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -105,6 +105,11 @@ MIXER_EXT_SPEAKERS_A = None #: Default: :class:`None`. MIXER_EXT_SPEAKERS_B = None +#: Audio output handler to use. Default:: +#: +#: OUTPUT = u'mopidy.outputs.gstreamer.GStreamerOutput' +OUTPUT = u'mopidy.outputs.gstreamer.GStreamerOutput' + #: Server to use. Default:: #: #: SERVER = u'mopidy.frontends.mpd.server.MpdServer' From 1e2dd6f46c6f5b455acd66034de47db2e501a3f1 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 22:57:12 +0200 Subject: [PATCH 020/138] Backend API: Add optional argument 'output_connection' to BaseBackend constructor --- docs/changes.rst | 3 +++ mopidy/backends/base/__init__.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/changes.rst b/docs/changes.rst index c8e4c912..811eb482 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -35,6 +35,9 @@ Another great release. - :meth:`mopidy.backends.base.BaseLibraryController.search()` now accepts keyword arguments of the form ``search(artist=['foo', 'fighters'], album=['bar', 'grooves'])``. + - :meth:`mopidy.backends.base.BaseBackend()` now accepts an + ``output_connection`` which it can use to send messages (i.e. audio data) + to the output process. diff --git a/mopidy/backends/base/__init__.py b/mopidy/backends/base/__init__.py index e79aceae..942b190e 100644 --- a/mopidy/backends/base/__init__.py +++ b/mopidy/backends/base/__init__.py @@ -23,13 +23,17 @@ class BaseBackend(object): :param core_queue: a queue for sending messages to :class:`mopidy.process.CoreProcess` :type core_queue: :class:`multiprocessing.Queue` + :param output_connection: a connection for sending messages to the + output process + :type output_connection: :class:`multiprocessing.Connection` :param mixer: either a mixer instance, or :class:`None` to use the mixer defined in settings :type mixer: :class:`mopidy.mixers.BaseMixer` or :class:`None` """ - def __init__(self, core_queue=None, mixer=None): + def __init__(self, core_queue=None, output_connection=None, mixer=None): self.core_queue = core_queue + self.output_connection = output_connection if mixer is not None: self.mixer = mixer else: From c81a1162a8e8e5964b989033ae2bba98881292d5 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 22:58:42 +0200 Subject: [PATCH 021/138] Instantiate GStreamerOutput. Create a pipe from CoreProcess and Backend to GStreamerOutput. --- mopidy/process.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mopidy/process.py b/mopidy/process.py index f23ba6fc..94da3a58 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -37,6 +37,8 @@ class CoreProcess(BaseProcess): def __init__(self, core_queue): super(CoreProcess, self).__init__() self.core_queue = core_queue + self.output_connection = None + self.output = None self.backend = None self.frontend = None @@ -47,12 +49,15 @@ class CoreProcess(BaseProcess): self.process_message(message) def setup(self): - self.backend = get_class(settings.BACKENDS[0])( - core_queue=self.core_queue) - self.frontend = get_class(settings.FRONTEND)(backend=self.backend) + (recv_end, self.output_connection) = multiprocessing.Pipe(False) + self.output = get_class(settings.OUTPUT)(self.core_queue, recv_end) + self.backend = get_class(settings.BACKENDS[0])(self.core_queue) + self.frontend = get_class(settings.FRONTEND)(self.backend) def process_message(self, message): - if message['command'] == 'mpd_request': + if message.get('to') == 'output': + self.output_connection.send(message) + elif message['command'] == 'mpd_request': response = self.frontend.handle_request(message['request']) connection = unpickle_connection(message['reply_to']) connection.send(response) From 6d799a2bfacfa8d84397dd6f71c576849f3ab53f Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 11 Aug 2010 23:02:50 +0200 Subject: [PATCH 022/138] GStreamerProcess: Do not assert on a to-field in the message as the pipe is only used for sending messages to 'output' anyway --- mopidy/outputs/gstreamer.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index acae6493..5415a5ee 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -48,7 +48,7 @@ class GStreamerProcess(BaseProcess): # behaviour first. if self.input_connection.poll(): message = self.input_connection.recv() - self.process_core_message(message) + self.process_mopidy_message(message) self.gobject_context.iteration(True) def setup(self): @@ -102,9 +102,8 @@ class GStreamerProcess(BaseProcess): # Link volume filter output to audio sink input self.gst_volume.link(self.gst_sink) - def process_core_message(self, message): + def process_mopidy_message(self, message): """Process messages from the rest of Mopidy.""" - assert message['to'] == 'gstreamer', 'Message must be addressed to us' if message['command'] == 'play_uri': response = self.play_uri(message['uri']) connection = unpickle_connection(message['reply_to']) From e55e560827452fd87708f41280babf52d7664d2e Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 12 Aug 2010 01:28:06 +0200 Subject: [PATCH 023/138] Helps to remember to send the output_connection to the backend --- mopidy/process.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mopidy/process.py b/mopidy/process.py index 94da3a58..ff30160c 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -51,7 +51,8 @@ class CoreProcess(BaseProcess): def setup(self): (recv_end, self.output_connection) = multiprocessing.Pipe(False) self.output = get_class(settings.OUTPUT)(self.core_queue, recv_end) - self.backend = get_class(settings.BACKENDS[0])(self.core_queue) + self.backend = get_class(settings.BACKENDS[0])(self.core_queue, + self.output_connection) self.frontend = get_class(settings.FRONTEND)(self.backend) def process_message(self, message): From f488b0fe2d49db0d93118839924dadf59136032b Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 12 Aug 2010 01:29:07 +0200 Subject: [PATCH 024/138] GStreamerOutput: Now working for data deliveries from e.g. LibspotifyBackend --- mopidy/outputs/gstreamer.py | 64 +++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 5415a5ee..bda04b25 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -1,10 +1,12 @@ import gobject +gobject.threads_init() import pygst pygst.require('0.10') - import gst + import logging +import threading from mopidy.process import BaseProcess, unpickle_connection @@ -21,18 +23,26 @@ class GStreamerOutput(object): process = GStreamerProcess(core_queue, input_connection) process.start() +class GStreamerMessagesThread(threading.Thread): + def run(self): + gobject.MainLoop().run() + class GStreamerProcess(BaseProcess): """ A process for all work related to GStreamer. The main loop processes events from both Mopidy and GStreamer. + + Make sure this subprocess is started by the MainThread in the top-most + parent process, and not some other thread. If not, we can get into the + problems described at + http://jameswestby.net/weblog/tech/14-caution-python-multiprocessing-and-glib-dont-mix.html. """ def __init__(self, core_queue, input_connection): super(GStreamerProcess, self).__init__() self.core_queue = core_queue self.input_connection = input_connection - self.gobject_context = None self.gst_pipeline = None self.gst_bus = None self.gst_bus_id = None @@ -44,18 +54,17 @@ class GStreamerProcess(BaseProcess): def run_inside_try(self): self.setup() while True: - # FIXME Should we block on poll() or not? Need to see iteration() - # behaviour first. - if self.input_connection.poll(): + if self.input_connection.poll(None): message = self.input_connection.recv() self.process_mopidy_message(message) - self.gobject_context.iteration(True) def setup(self): - # See http://www.jejik.com/articles/2007/01/ - # python-gstreamer_threading_and_the_main_loop/ for details. - gobject.threads_init() - self.gobject_context = gobject.MainLoop().get_context() + logger.debug(u'Setting up GStreamer pipeline') + + # Start a helper thread that can run the gobject.MainLoop + messages_thread = GStreamerMessagesThread() + messages_thread.daemon = True + messages_thread.start() # A pipeline consisting of many elements self.gst_pipeline = gst.Pipeline("pipeline") @@ -67,8 +76,8 @@ class GStreamerProcess(BaseProcess): self.process_gst_message) # Bin for playing audio URIs - self.gst_uri_src = gst.element_factory_make('uridecodebin', 'uri_src') - self.gst_pipeline.add(self.gst_uri_src) + #self.gst_uri_src = gst.element_factory_make('uridecodebin', 'uri_src') + #self.gst_pipeline.add(self.gst_uri_src) # Bin for playing audio data self.gst_data_src = gst.element_factory_make('appsrc', 'data_src') @@ -109,8 +118,9 @@ class GStreamerProcess(BaseProcess): connection = unpickle_connection(message['reply_to']) connection.send(response) elif message['command'] == 'deliver_data': - # FIXME Do we care about sending responses for every data delivery? self.deliver_data(message['caps'], message['data']) + elif message['command'] == 'end_of_data_stream': + self.end_of_data_stream() elif message['command'] == 'set_state': response = self.set_state(message['state']) connection = unpickle_connection(message['reply_to']) @@ -121,7 +131,9 @@ class GStreamerProcess(BaseProcess): def process_gst_message(self, bus, message): """Process messages from GStreamer.""" if message.type == gst.MESSAGE_EOS: - self.core_queue.put({'message': 'end_of_track'}) + logger.debug(u'GStreamer signalled end-of-stream. ' + 'Sending end_of_track to core_queue ...') + self.core_queue.put({'command': 'end_of_track'}) elif message.type == gst.MESSAGE_ERROR: self.set_state('NULL') error, debug = message.parse_error() @@ -129,13 +141,6 @@ class GStreamerProcess(BaseProcess): # FIXME Should we send 'stop_playback' to core here? Can we # differentiate on how serious the error is? - def deliver_data(self, caps_string, data): - """Deliver audio data to be played""" - caps = gst.caps_from_string(caps_string) - buffer_ = gst.Buffer(data) - buffer_.set_caps(caps) - self.gst_data_src.emit('push-buffer', buffer_) - def play_uri(self, uri): """Play audio at URI""" self.set_state('READY') @@ -143,6 +148,23 @@ class GStreamerProcess(BaseProcess): self.set_state('PLAYING') # TODO Return status + def deliver_data(self, caps_string, data): + """Deliver audio data to be played""" + caps = gst.caps_from_string(caps_string) + buffer_ = gst.Buffer(buffer(data)) + buffer_.set_caps(caps) + self.gst_data_src.set_property('caps', caps) + self.gst_data_src.emit('push-buffer', buffer_) + + def end_of_data_stream(self): + """ + Add end-of-stream token to source. + + We will get a GStreamer message when the stream playback reaches the + token, and can then do any end-of-stream related tasks. + """ + self.gst_data_src.emit('end-of-stream') + def set_state(self, state_name): """ Set the GStreamer state. Returns :class:`True` if successful. From 816f877c4b2749990e5438a139ef12665035a282 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 12 Aug 2010 01:30:20 +0200 Subject: [PATCH 025/138] Change LibspotifyBackend from using GStreamer directly to just sending it's data to GStreamerOutput --- mopidy/backends/libspotify/__init__.py | 109 +++++++++---------------- 1 file changed, 38 insertions(+), 71 deletions(-) diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index b098d0ac..1fa07836 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -1,14 +1,9 @@ import datetime as dt -import gobject import logging import os import multiprocessing import threading -import pygst -pygst.require('0.10') -import gst - from spotify import Link, SpotifyError from spotify.manager import SpotifySessionManager from spotify.alsahelper import AlsaController @@ -18,6 +13,7 @@ from mopidy.backends.base import (BaseBackend, BaseCurrentPlaylistController, BaseLibraryController, BasePlaybackController, BaseStoredPlaylistsController) from mopidy.models import Artist, Album, Track, Playlist +from mopidy.process import pickle_connection logger = logging.getLogger('mopidy.backends.libspotify') @@ -47,7 +43,6 @@ class LibspotifyBackend(BaseBackend): self.stored_playlists = LibspotifyStoredPlaylistsController( backend=self) self.uri_handlers = [u'spotify:', u'http://open.spotify.com/'] - self.gstreamer_pipeline = gst.Pipeline("spotify_pipeline") self.spotify = self._connect() def _connect(self): @@ -55,7 +50,7 @@ class LibspotifyBackend(BaseBackend): spotify = LibspotifySessionManager( settings.SPOTIFY_USERNAME, settings.SPOTIFY_PASSWORD, core_queue=self.core_queue, - gstreamer_pipeline=self.gstreamer_pipeline) + output_connection=self.output_connection) spotify.start() return spotify @@ -97,13 +92,22 @@ class LibspotifyLibraryController(BaseLibraryController): class LibspotifyPlaybackController(BasePlaybackController): + def _set_output_state(self, state_name): + logger.debug(u'Setting output state to %s ...', state_name) + (my_end, other_end) = multiprocessing.Pipe() + self.backend.output_connection.send({ + 'command': 'set_state', + 'state': state_name, + 'reply_to': pickle_connection(other_end), + }) + my_end.poll(None) + return my_end.recv() + def _pause(self): - result = self.backend.gstreamer_pipeline.set_state(gst.STATE_PAUSED) - logger.debug('Changed gstreamer state to paused. Result was: %s' % result) - return result == gst.STATE_CHANGE_SUCCESS + return self._set_output_state('PAUSED') def _play(self, track): - self.backend.gstreamer_pipeline.set_state(gst.STATE_READY) + self._set_output_state('READY') if self.state == self.PLAYING: self.stop() if track.uri is None: @@ -112,24 +116,22 @@ class LibspotifyPlaybackController(BasePlaybackController): self.backend.spotify.session.load( Link.from_string(track.uri).as_track()) self.backend.spotify.session.play(1) - self.backend.gstreamer_pipeline.set_state(gst.STATE_PLAYING) + self._set_output_state('PLAYING') return True except SpotifyError as e: logger.warning('Play %s failed: %s', track.uri, e) return False def _resume(self): - result = self.backend.gstreamer_pipeline.set_state(gst.STATE_PLAYING) - logger.debug('Changed gstreamer state to playing. Result was: %s' % result) - return result == gst.STATE_CHANGE_SUCCESS + return self._set_output_state('PLAYING') def _seek(self, time_position): pass # TODO def _stop(self): - self.backend.gstreamer_pipeline.set_state(gst.STATE_READY) + result = self._set_output_state('READY') self.backend.spotify.session.play(0) - return True + return result class LibspotifyStoredPlaylistsController(BaseStoredPlaylistsController): @@ -202,57 +204,19 @@ class LibspotifyTranslator(object): tracks=[cls.to_mopidy_track(t) for t in spotify_playlist], ) -class GstreamerMessageBusProcess(threading.Thread): - def __init__(self, core_queue, pipeline): - super(GstreamerMessageBusProcess, self).__init__() - self.core_queue = core_queue - self.bus = pipeline.get_bus() - - def run(self): - loop = gobject.MainLoop() - gobject.threads_init() - context = loop.get_context() - while True: - message = self.bus.pop_filtered(gst.MESSAGE_EOS) - if message is not None: - self.core_queue.put({'command': 'end_of_track'}) - logger.debug('Got and handled Gstreamer message of type: %s' % message.type) - context.iteration(True) - class LibspotifySessionManager(SpotifySessionManager, threading.Thread): cache_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) settings_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) appkey_file = os.path.expanduser(settings.SPOTIFY_LIB_APPKEY) user_agent = 'Mopidy %s' % get_version() - def __init__(self, username, password, core_queue, gstreamer_pipeline): + def __init__(self, username, password, core_queue, output_connection): SpotifySessionManager.__init__(self, username, password) threading.Thread.__init__(self) self.core_queue = core_queue + self.output_connection = output_connection self.connected = threading.Event() self.session = None - self.gstreamer_pipeline = gstreamer_pipeline - - cap_string = """audio/x-raw-int, - endianness=(int)1234, - channels=(int)2, - width=(int)16, - depth=(int)16, - signed=True, - rate=(int)44100""" - caps = gst.caps_from_string(cap_string) - - self.gsrc = gst.element_factory_make("appsrc", "app-source") - self.gsrc.set_property('caps', caps) - - self.gsink = gst.element_factory_make("autoaudiosink", "autosink") - - self.gstreamer_pipeline.add(self.gsrc, self.gsink) - - gst.element_link_many(self.gsrc, self.gsink) - - message_process = GstreamerMessageBusProcess(self.core_queue, self.gstreamer_pipeline) - message_process.start() def run(self): self.connect() @@ -294,17 +258,21 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): def music_delivery(self, session, frames, frame_size, num_frames, sample_type, sample_rate, channels): """Callback used by pyspotify""" - cap_string = """audio/x-raw-int, - endianness=(int)1234, - channels=(int)2, - width=(int)16, - depth=(int)16, - signed=True, - rate=(int)44100""" - caps = gst.caps_from_string(cap_string) - b = gst.Buffer(frames) - b.set_caps(caps) - self.gsrc.emit('push-buffer', b) + # TODO Base caps_string on arguments + caps_string = """ + audio/x-raw-int, + endianness=(int)1234, + channels=(int)2, + width=(int)16, + depth=(int)16, + signed=True, + rate=(int)44100 + """ + self.output_connection.send({ + 'command': 'deliver_data', + 'caps': caps_string, + 'data': bytes(frames), + }) def play_token_lost(self, session): """Callback used by pyspotify""" @@ -317,9 +285,8 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): def end_of_track(self, session): """Callback used by pyspotify""" - logger.debug('End of track.') - self.gsrc.emit('end-of-stream') - logger.debug('End of stream sent to gstreamer.') + logger.debug('End of data stream.') + self.output_connection.send({'command': 'end_of_data_stream'}) def search(self, query, connection): """Search method used by Mopidy backend""" From 5b0faa196d67866658bcee32de1df12b24263130 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 12 Aug 2010 01:38:11 +0200 Subject: [PATCH 026/138] Switch from output_connection to output_queue, as we are going to have multiple producers with time --- docs/changes.rst | 2 +- mopidy/backends/base/__init__.py | 9 ++++----- mopidy/backends/libspotify/__init__.py | 12 ++++++------ mopidy/outputs/gstreamer.py | 13 ++++++------- mopidy/process.py | 11 ++++++----- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 811eb482..d38a135a 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -36,7 +36,7 @@ Another great release. keyword arguments of the form ``search(artist=['foo', 'fighters'], album=['bar', 'grooves'])``. - :meth:`mopidy.backends.base.BaseBackend()` now accepts an - ``output_connection`` which it can use to send messages (i.e. audio data) + ``output_queue`` which it can use to send messages (i.e. audio data) to the output process. diff --git a/mopidy/backends/base/__init__.py b/mopidy/backends/base/__init__.py index 942b190e..3a484865 100644 --- a/mopidy/backends/base/__init__.py +++ b/mopidy/backends/base/__init__.py @@ -23,17 +23,16 @@ class BaseBackend(object): :param core_queue: a queue for sending messages to :class:`mopidy.process.CoreProcess` :type core_queue: :class:`multiprocessing.Queue` - :param output_connection: a connection for sending messages to the - output process - :type output_connection: :class:`multiprocessing.Connection` + :param output_queue: a queue for sending messages to the output process + :type output_queue: :class:`multiprocessing.Queue` :param mixer: either a mixer instance, or :class:`None` to use the mixer defined in settings :type mixer: :class:`mopidy.mixers.BaseMixer` or :class:`None` """ - def __init__(self, core_queue=None, output_connection=None, mixer=None): + def __init__(self, core_queue=None, output_queue=None, mixer=None): self.core_queue = core_queue - self.output_connection = output_connection + self.output_queue = output_queue if mixer is not None: self.mixer = mixer else: diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index 1fa07836..cc853314 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -50,7 +50,7 @@ class LibspotifyBackend(BaseBackend): spotify = LibspotifySessionManager( settings.SPOTIFY_USERNAME, settings.SPOTIFY_PASSWORD, core_queue=self.core_queue, - output_connection=self.output_connection) + output_queue=self.output_queue) spotify.start() return spotify @@ -95,7 +95,7 @@ class LibspotifyPlaybackController(BasePlaybackController): def _set_output_state(self, state_name): logger.debug(u'Setting output state to %s ...', state_name) (my_end, other_end) = multiprocessing.Pipe() - self.backend.output_connection.send({ + self.backend.output_queue.put({ 'command': 'set_state', 'state': state_name, 'reply_to': pickle_connection(other_end), @@ -210,11 +210,11 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): appkey_file = os.path.expanduser(settings.SPOTIFY_LIB_APPKEY) user_agent = 'Mopidy %s' % get_version() - def __init__(self, username, password, core_queue, output_connection): + def __init__(self, username, password, core_queue, output_queue): SpotifySessionManager.__init__(self, username, password) threading.Thread.__init__(self) self.core_queue = core_queue - self.output_connection = output_connection + self.output_queue = output_queue self.connected = threading.Event() self.session = None @@ -268,7 +268,7 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): signed=True, rate=(int)44100 """ - self.output_connection.send({ + self.output_queue.put({ 'command': 'deliver_data', 'caps': caps_string, 'data': bytes(frames), @@ -286,7 +286,7 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): def end_of_track(self, session): """Callback used by pyspotify""" logger.debug('End of data stream.') - self.output_connection.send({'command': 'end_of_data_stream'}) + self.output_queue.put({'command': 'end_of_data_stream'}) def search(self, query, connection): """Search method used by Mopidy backend""" diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index bda04b25..65b65504 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -19,8 +19,8 @@ class GStreamerOutput(object): Starts the :class:`GStreamerProcess`. """ - def __init__(self, core_queue, input_connection): - process = GStreamerProcess(core_queue, input_connection) + def __init__(self, core_queue, output_queue): + process = GStreamerProcess(core_queue, output_queue) process.start() class GStreamerMessagesThread(threading.Thread): @@ -39,10 +39,10 @@ class GStreamerProcess(BaseProcess): http://jameswestby.net/weblog/tech/14-caution-python-multiprocessing-and-glib-dont-mix.html. """ - def __init__(self, core_queue, input_connection): + def __init__(self, core_queue, output_queue): super(GStreamerProcess, self).__init__() self.core_queue = core_queue - self.input_connection = input_connection + self.output_queue = output_queue self.gst_pipeline = None self.gst_bus = None self.gst_bus_id = None @@ -54,9 +54,8 @@ class GStreamerProcess(BaseProcess): def run_inside_try(self): self.setup() while True: - if self.input_connection.poll(None): - message = self.input_connection.recv() - self.process_mopidy_message(message) + message = self.output_queue.get() + self.process_mopidy_message(message) def setup(self): logger.debug(u'Setting up GStreamer pipeline') diff --git a/mopidy/process.py b/mopidy/process.py index ff30160c..9759c4e6 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -37,7 +37,7 @@ class CoreProcess(BaseProcess): def __init__(self, core_queue): super(CoreProcess, self).__init__() self.core_queue = core_queue - self.output_connection = None + self.output_queue = None self.output = None self.backend = None self.frontend = None @@ -49,15 +49,16 @@ class CoreProcess(BaseProcess): self.process_message(message) def setup(self): - (recv_end, self.output_connection) = multiprocessing.Pipe(False) - self.output = get_class(settings.OUTPUT)(self.core_queue, recv_end) + self.output_queue = multiprocessing.Queue() + self.output = get_class(settings.OUTPUT)(self.core_queue, + self.output_queue) self.backend = get_class(settings.BACKENDS[0])(self.core_queue, - self.output_connection) + self.output_queue) self.frontend = get_class(settings.FRONTEND)(self.backend) def process_message(self, message): if message.get('to') == 'output': - self.output_connection.send(message) + self.output_queue.put(message) elif message['command'] == 'mpd_request': response = self.frontend.handle_request(message['request']) connection = unpickle_connection(message['reply_to']) From 31ccf37dd82b7e7c0d9480fd1dc259ebd5a75398 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 12 Aug 2010 01:42:07 +0200 Subject: [PATCH 027/138] docs: python-alsaaudio is no longer needed for the LibspotifyBackend --- docs/installation/libspotify.rst | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/docs/installation/libspotify.rst b/docs/installation/libspotify.rst index 9dc9689f..3965162d 100644 --- a/docs/installation/libspotify.rst +++ b/docs/installation/libspotify.rst @@ -57,22 +57,10 @@ Installing pyspotify Install pyspotify's dependencies. At Debian/Ubuntu systems:: - sudo aptitude install python-dev python-alsaaudio + sudo aptitude install python-dev Check out the pyspotify code, and install it:: git clone git://github.com/jodal/pyspotify.git cd pyspotify/pyspotify/ sudo python setup.py install - - -Testing the installation -======================== - -Apply for an application key at -https://developer.spotify.com/en/libspotify/application-key, download the -binary version, and place the file at ``pyspotify/spotify_appkey.key``. - -Test your libspotify setup:: - - examples/example1.py -u USERNAME -p PASSWORD From f9e0cb5d1a47aca4ca05a16f6f634089eb21186a Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 12 Aug 2010 01:42:34 +0200 Subject: [PATCH 028/138] docs: Require GStreamer >= 0.10, as we have no idea if it will work with lesser versions --- docs/installation/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installation/index.rst b/docs/installation/index.rst index 73ae62cb..227ae8b9 100644 --- a/docs/installation/index.rst +++ b/docs/installation/index.rst @@ -23,7 +23,7 @@ Install dependencies Make sure you got the required dependencies installed. - Python >= 2.6, < 3 -- :doc:`GStreamer ` (>= 0.10 ?) with Python bindings +- :doc:`GStreamer ` >= 0.10, with Python bindings - Dependencies for at least one Mopidy mixer: - :mod:`mopidy.mixers.alsa` (Linux only) From 8fd988e49fe87e4c771bef4946e9448ab4b586ff Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 13 Aug 2010 16:56:42 +0200 Subject: [PATCH 029/138] Remove search debug output from libspotify backend --- mopidy/backends/libspotify/__init__.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index c256b55d..974e52df 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -79,15 +79,11 @@ class LibspotifyLibraryController(BaseLibraryController): else: spotify_query.append(u'%s:"%s"' % (field, value)) spotify_query = u' '.join(spotify_query) - logger.debug(u'In search method, search for: %s' % spotify_query) + logger.debug(u'Spotify search query: %s' % spotify_query) my_end, other_end = multiprocessing.Pipe() self.backend.spotify.search(spotify_query.encode(ENCODING), other_end) - logger.debug(u'In Library.search(), waiting for search results') my_end.poll(None) - logger.debug(u'In Library.search(), receiving search results') playlist = my_end.recv() - logger.debug(u'In Library.search(), done receiving search results') - logger.debug(['%s' % t.name for t in playlist.tracks]) return playlist @@ -288,24 +284,10 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): def search(self, query, connection): """Search method used by Mopidy backend""" def callback(results, userdata): - logger.debug(u'In SessionManager.search().callback(), ' - 'translating search results') - logger.debug(results.tracks()) # TODO Include results from results.albums(), etc. too playlist = Playlist(tracks=[ LibspotifyTranslator.to_mopidy_track(t) for t in results.tracks()]) - logger.debug(u'In SessionManager.search().callback(), ' - 'sending search results') - logger.debug(['%s' % t.name for t in playlist.tracks]) connection.send(playlist) - logger.debug(u'In SessionManager.search().callback(), ' - 'done sending search results') - logger.debug(u'In SessionManager.search(), ' - 'waiting for Spotify connection') self.connected.wait() - logger.debug(u'In SessionManager.search(), ' - 'sending search query') self.session.search(query, callback) - logger.debug(u'In SessionManager.search(), ' - 'done sending search query') From acd043719342f507ca92e9fb6d31605302cdad29 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Fri, 13 Aug 2010 20:44:24 +0200 Subject: [PATCH 030/138] Remove despotify backend as library is no longer maintained --- docs/api/backends.rst | 8 - docs/changes.rst | 2 + docs/development/roadmap.rst | 3 +- docs/installation/despotify.rst | 73 ------- docs/installation/index.rst | 7 +- docs/installation/libspotify.rst | 2 +- mopidy/backends/despotify/__init__.py | 209 -------------------- mopidy/settings.py | 5 +- tests/backends/despotify_integrationtest.py | 35 ---- 9 files changed, 7 insertions(+), 337 deletions(-) delete mode 100644 docs/installation/despotify.rst delete mode 100644 mopidy/backends/despotify/__init__.py delete mode 100644 tests/backends/despotify_integrationtest.py diff --git a/docs/api/backends.rst b/docs/api/backends.rst index adb87e56..f675541a 100644 --- a/docs/api/backends.rst +++ b/docs/api/backends.rst @@ -82,14 +82,6 @@ Manages the music library, e.g. searching for tracks to be added to a playlist. :undoc-members: -:mod:`mopidy.backends.despotify` -- Despotify backend -===================================================== - -.. automodule:: mopidy.backends.despotify - :synopsis: Spotify backend using the Despotify library - :members: - - :mod:`mopidy.backends.dummy` -- Dummy backend for testing ========================================================= diff --git a/docs/changes.rst b/docs/changes.rst index 460b7538..4e33125d 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -47,6 +47,8 @@ Another great release. - :meth:`mopidy.backends.base.BaseBackend()` now accepts an ``output_queue`` which it can use to send messages (i.e. audio data) to the output process. + - Remove Depsotify backend. + - Libspotify is now the default backend. diff --git a/docs/development/roadmap.rst b/docs/development/roadmap.rst index 7dc284df..5544a005 100644 --- a/docs/development/roadmap.rst +++ b/docs/development/roadmap.rst @@ -11,8 +11,7 @@ Version 0.1 - Core MPD server functionality working. Gracefully handle clients' use of non-supported functionality. -- Read-only support for Spotify through :mod:`mopidy.backends.despotify` and/or - :mod:`mopidy.backends.libspotify`. +- Read-only support for Spotify through :mod:`mopidy.backends.libspotify`. - Initial support for local file playback through :mod:`mopidy.backends.local`. The state of local file playback will not block the release of 0.1. diff --git a/docs/installation/despotify.rst b/docs/installation/despotify.rst deleted file mode 100644 index 6787070d..00000000 --- a/docs/installation/despotify.rst +++ /dev/null @@ -1,73 +0,0 @@ -********************** -Despotify installation -********************** - -To use the `Despotify `_ backend, you first need to -install Despotify and spytify. - -.. warning:: - - This backend requires a Spotify premium account. - - -Installing Despotify on Linux -============================= - -Install Despotify's dependencies. At Debian/Ubuntu systems:: - - sudo aptitude install libssl-dev zlib1g-dev libvorbis-dev \ - libtool libncursesw5-dev libao-dev python-dev - -Check out revision 508 of the Despotify source code:: - - svn checkout https://despotify.svn.sourceforge.net/svnroot/despotify@508 - -Build and install Despotify:: - - cd despotify/src/ - sudo make install - -When Despotify has been installed, continue with :ref:`spytify_installation`. - - -Installing Despotify on OS X -============================ - -In OS X you need to have `XCode `_ and -`Homebrew `_ installed. Then, to install -Despotify:: - - brew install despotify - -When Despotify has been installed, continue with :ref:`spytify_installation`. - - -.. _spytify_installation: - -Installing spytify -================== - -spytify's source comes bundled with despotify. If you haven't already checkout -out the despotify source, do it now:: - - svn checkout https://despotify.svn.sourceforge.net/svnroot/despotify@508 - -Build and install spytify:: - - cd despotify/src/bindings/python/ - export PKG_CONFIG_PATH=../../lib # Needed on OS X - sudo make install - - -Testing the installation -======================== - -To validate that everything is working, run the ``test.py`` script which is -distributed with spytify:: - - python test.py - -The test script should ask for your username and password (which must be for a -Spotify Premium account), ask for a search query, list all your playlists with -tracks, play 10s from a random song from the search result, pause for two -seconds, play for five more seconds, and quit. diff --git a/docs/installation/index.rst b/docs/installation/index.rst index 227ae8b9..044f2155 100644 --- a/docs/installation/index.rst +++ b/docs/installation/index.rst @@ -18,7 +18,6 @@ Install dependencies gstreamer libspotify - despotify Make sure you got the required dependencies installed. @@ -44,10 +43,6 @@ Make sure you got the required dependencies installed. - Dependencies for at least one Mopidy backend: - - :mod:`mopidy.backends.despotify` (Linux and OS X) - - - :doc:`Despotify and spytify ` - - :mod:`mopidy.backends.libspotify` (Linux, OS X, and Windows) - :doc:`libspotify and pyspotify ` @@ -106,7 +101,7 @@ username and password into the file, like this:: SPOTIFY_USERNAME = u'myusername' SPOTIFY_PASSWORD = u'mysecret' -Currently :mod:`mopidy.backends.despotify` is the default +Currently :mod:`mopidy.backends.libspotify` is the default backend. If you want to use :mod:`mopidy.backends.libspotify`, copy the Spotify diff --git a/docs/installation/libspotify.rst b/docs/installation/libspotify.rst index 3965162d..635c0495 100644 --- a/docs/installation/libspotify.rst +++ b/docs/installation/libspotify.rst @@ -2,7 +2,7 @@ libspotify installation *********************** -As an alternative to the despotify backend, we are working on a +We are working on a `libspotify `_ backend. To use the libspotify backend you must install libspotify and `pyspotify `_. diff --git a/mopidy/backends/despotify/__init__.py b/mopidy/backends/despotify/__init__.py deleted file mode 100644 index 78c7f774..00000000 --- a/mopidy/backends/despotify/__init__.py +++ /dev/null @@ -1,209 +0,0 @@ -import datetime as dt -import logging -import sys - -import spytify - -from mopidy import settings -from mopidy.backends.base import (BaseBackend, BaseCurrentPlaylistController, - BaseLibraryController, BasePlaybackController, - BaseStoredPlaylistsController) -from mopidy.models import Artist, Album, Track, Playlist - -logger = logging.getLogger('mopidy.backends.despotify') - -ENCODING = 'utf-8' - -class DespotifyBackend(BaseBackend): - """ - A Spotify backend which uses the open source `despotify library - `_. - - `spytify `_ - is the Python bindings for the despotify library. It got litle - documentation, but a couple of examples are available. - - **Issues:** http://github.com/jodal/mopidy/issues/labels/backend-despotify - """ - - def __init__(self, *args, **kwargs): - super(DespotifyBackend, self).__init__(*args, **kwargs) - self.current_playlist = DespotifyCurrentPlaylistController(backend=self) - self.library = DespotifyLibraryController(backend=self) - self.playback = DespotifyPlaybackController(backend=self) - self.stored_playlists = DespotifyStoredPlaylistsController(backend=self) - self.uri_handlers = [u'spotify:', u'http://open.spotify.com/'] - self.spotify = self._connect() - self.stored_playlists.refresh() - - def _connect(self): - logger.info(u'Connecting to Spotify') - try: - return DespotifySessionManager( - settings.SPOTIFY_USERNAME.encode(ENCODING), - settings.SPOTIFY_PASSWORD.encode(ENCODING), - core_queue=self.core_queue) - except spytify.SpytifyError as e: - logger.exception(e) - sys.exit(1) - - -class DespotifyCurrentPlaylistController(BaseCurrentPlaylistController): - pass - - -class DespotifyLibraryController(BaseLibraryController): - def find_exact(self, **query): - return self.search(**query) - - def lookup(self, uri): - track = self.backend.spotify.lookup(uri.encode(ENCODING)) - return DespotifyTranslator.to_mopidy_track(track) - - def refresh(self, uri=None): - pass # TODO - - def search(self, **query): - spotify_query = [] - for (field, values) in query.iteritems(): - if not hasattr(values, '__iter__'): - values = [values] - for value in values: - if field == u'track': - field = u'title' - if field == u'any': - spotify_query.append(value) - else: - spotify_query.append(u'%s:"%s"' % (field, value)) - spotify_query = u' '.join(spotify_query) - logger.debug(u'Spotify search query: %s', spotify_query) - result = self.backend.spotify.search(spotify_query.encode(ENCODING)) - if (result is None or result.playlist.tracks[0].get_uri() == - 'spotify:track:0000000000000000000000'): - return Playlist() - return DespotifyTranslator.to_mopidy_playlist(result.playlist) - - -class DespotifyPlaybackController(BasePlaybackController): - def _pause(self): - try: - self.backend.spotify.pause() - return True - except spytify.SpytifyError as e: - logger.error(e) - return False - - def _play(self, track): - try: - self.backend.spotify.play(self.backend.spotify.lookup(track.uri)) - return True - except spytify.SpytifyError as e: - logger.error(e) - return False - - def _resume(self): - try: - self.backend.spotify.resume() - return True - except spytify.SpytifyError as e: - logger.error(e) - return False - - def _seek(self, time_position): - pass # TODO - - def _stop(self): - try: - self.backend.spotify.stop() - return True - except spytify.SpytifyError as e: - logger.error(e) - return False - - -class DespotifyStoredPlaylistsController(BaseStoredPlaylistsController): - def create(self, name): - pass # TODO - - def delete(self, playlist): - pass # TODO - - def lookup(self, uri): - pass # TODO - - def refresh(self): - logger.info(u'Caching stored playlists') - playlists = [] - for spotify_playlist in self.backend.spotify.stored_playlists: - playlists.append( - DespotifyTranslator.to_mopidy_playlist(spotify_playlist)) - self._playlists = playlists - logger.debug(u'Available playlists: %s', - u', '.join([u'<%s>' % p.name for p in self.playlists])) - logger.info(u'Done caching stored playlists') - - def rename(self, playlist, new_name): - pass # TODO - - def save(self, playlist): - pass # TODO - - -class DespotifyTranslator(object): - @classmethod - def to_mopidy_artist(cls, spotify_artist): - return Artist( - uri=spotify_artist.get_uri(), - name=spotify_artist.name.decode(ENCODING) - ) - - @classmethod - def to_mopidy_album(cls, spotify_album_name): - return Album(name=spotify_album_name.decode(ENCODING)) - - @classmethod - def to_mopidy_track(cls, spotify_track): - if spotify_track is None or not spotify_track.has_meta_data(): - return None - if dt.MINYEAR <= int(spotify_track.year) <= dt.MAXYEAR: - date = dt.date(spotify_track.year, 1, 1) - else: - date = None - return Track( - uri=spotify_track.get_uri(), - name=spotify_track.title.decode(ENCODING), - artists=[cls.to_mopidy_artist(a) for a in spotify_track.artists], - album=cls.to_mopidy_album(spotify_track.album), - track_no=spotify_track.tracknumber, - date=date, - length=spotify_track.length, - bitrate=320, - ) - - @classmethod - def to_mopidy_playlist(cls, spotify_playlist): - return Playlist( - uri=spotify_playlist.get_uri(), - name=spotify_playlist.name.decode(ENCODING), - tracks=filter(None, - [cls.to_mopidy_track(t) for t in spotify_playlist.tracks]), - ) - - -class DespotifySessionManager(spytify.Spytify): - DESPOTIFY_NEW_TRACK = 1 - DESPOTIFY_TIME_TELL = 2 - DESPOTIFY_END_OF_PLAYLIST = 3 - DESPOTIFY_TRACK_PLAY_ERROR = 4 - - def __init__(self, *args, **kwargs): - kwargs['callback'] = self.callback - self.core_queue = kwargs.pop('core_queue') - super(DespotifySessionManager, self).__init__(*args, **kwargs) - - def callback(self, signal, data): - if signal == self.DESPOTIFY_END_OF_PLAYLIST: - logger.debug('Despotify signalled end of playlist') - self.core_queue.put({'command': 'end_of_track'}) - elif signal == self.DESPOTIFY_TRACK_PLAY_ERROR: - logger.error('Despotify signalled track play error') diff --git a/mopidy/settings.py b/mopidy/settings.py index 1be09511..d4321685 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -14,13 +14,12 @@ import sys #: List of playback backends to use. See :mod:`mopidy.backends` for all #: available backends. Default:: #: -#: BACKENDS = (u'mopidy.backends.despotify.DespotifyBackend',) +#: BACKENDS = (u'mopidy.backends.libspotify.LibspotifyBackend',) #: #: .. note:: #: Currently only the first backend in the list is used. BACKENDS = ( - u'mopidy.backends.despotify.DespotifyBackend', - #u'mopidy.backends.libspotify.LibspotifyBackend', + u'mopidy.backends.libspotify.LibspotifyBackend', ) #: The log format used on the console. See diff --git a/tests/backends/despotify_integrationtest.py b/tests/backends/despotify_integrationtest.py deleted file mode 100644 index 4192bf7b..00000000 --- a/tests/backends/despotify_integrationtest.py +++ /dev/null @@ -1,35 +0,0 @@ -# TODO This integration test is work in progress. - -import unittest - -from mopidy.backends.despotify import DespotifyBackend -from mopidy.models import Track - -from tests.backends.base import * - -uris = [ - 'spotify:track:6vqcpVcbI3Zu6sH3ieLDNt', - 'spotify:track:111sulhaZqgsnypz3MkiaW', - 'spotify:track:7t8oznvbeiAPMDRuK0R5ZT', -] - -class DespotifyCurrentPlaylistControllerTest( - BaseCurrentPlaylistControllerTest, unittest.TestCase): - tracks = [Track(uri=uri, length=4464) for i, uri in enumerate(uris)] - backend_class = DespotifyBackend - - -class DespotifyPlaybackControllerTest( - BasePlaybackControllerTest, unittest.TestCase): - tracks = [Track(uri=uri, length=4464) for i, uri in enumerate(uris)] - backend_class = DespotifyBackend - - -class DespotifyStoredPlaylistsControllerTest( - BaseStoredPlaylistsControllerTest, unittest.TestCase): - backend_class = DespotifyBackend - - -class DespotifyLibraryControllerTest( - BaseLibraryControllerTest, unittest.TestCase): - backend_class = DespotifyBackend From 48478968378d93aed68a50452c8b3b0c0eb25eb9 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 13 Aug 2010 21:01:31 +0200 Subject: [PATCH 031/138] docs: Cleanup changelog a bit --- docs/changes.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 4e33125d..7b154915 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -19,7 +19,10 @@ Another great release. the packages created by ``setup.py`` for i.e. PyPI. - Rename :mod:`mopidy.backends.gstreamer` to :mod:`mopidy.backends.local`. - Changed ``SERVER_HOSTNAME`` and ``SERVER_PORT`` settings to - ``MPD_SERVER_HOSTNAME`` and ``MPD_SERVER_PORT`` + ``MPD_SERVER_HOSTNAME`` and ``MPD_SERVER_PORT``. +- Remove :mod:`mopidy.backends.despotify`, as Despotify is little maintained + and the Libspotify backend is working much better. +- :mod:`mopidy.backends.libspotify` is now the default backend. - MPD frontend: - Relocate from :mod:`mopidy.mpd` to :mod:`mopidy.frontends.mpd`. @@ -47,8 +50,6 @@ Another great release. - :meth:`mopidy.backends.base.BaseBackend()` now accepts an ``output_queue`` which it can use to send messages (i.e. audio data) to the output process. - - Remove Depsotify backend. - - Libspotify is now the default backend. From 5fce38a7fad9c5285a3b749094d99eaa0fb6e232 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 13 Aug 2010 21:41:47 +0200 Subject: [PATCH 032/138] docs: Update install docs --- docs/installation/index.rst | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/docs/installation/index.rst b/docs/installation/index.rst index 044f2155..d5e76cce 100644 --- a/docs/installation/index.rst +++ b/docs/installation/index.rst @@ -2,12 +2,10 @@ Installation ************ -Mopidy itself is a breeze to install, as it just requires a standard Python -installation and the GStreamer library. The libraries we depend on to connect -to the Spotify service is far more tricky to get working for the time being. -Until installation of these libraries are either well documented by their -developers, or the libraries are packaged for various Linux distributions, we -will supply our own installation guides, as linked to below. +To get a basic version of Mopidy running, you need Python and the GStreamer +library. To use Spotify with Mopidy, you also need :doc:`libspotify and +pyspotify `. Mopidy itself can either be installed from the Python +package index, PyPI, or from git. Install dependencies @@ -102,13 +100,8 @@ username and password into the file, like this:: SPOTIFY_PASSWORD = u'mysecret' Currently :mod:`mopidy.backends.libspotify` is the default -backend. - -If you want to use :mod:`mopidy.backends.libspotify`, copy the Spotify -application key to ``~/.mopidy/spotify_appkey.key``, and add the following -setting:: - - BACKENDS = (u'mopidy.backends.libspotify.LibspotifyBackend',) +backend. Before you can use :mod:`mopidy.backends.libspotify`, you must copy +the Spotify application key to ``~/.mopidy/spotify_appkey.key``. If you want to use :mod:`mopidy.backends.local`, add the following setting:: From 581d694cb1a660a0ce6dd4399ec37394858e0edd Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Fri, 13 Aug 2010 21:51:02 +0200 Subject: [PATCH 033/138] Split libspotify backend into one file per class, and thus ensure that spotify depenedices don't fail tests --- mopidy/backends/libspotify/__init__.py | 263 +----------------- mopidy/backends/libspotify/library.py | 41 +++ mopidy/backends/libspotify/playback.py | 51 ++++ mopidy/backends/libspotify/session_manager.py | 106 +++++++ .../backends/libspotify/stored_playlists.py | 20 ++ mopidy/backends/libspotify/translator.py | 53 ++++ 6 files changed, 282 insertions(+), 252 deletions(-) create mode 100644 mopidy/backends/libspotify/library.py create mode 100644 mopidy/backends/libspotify/playback.py create mode 100644 mopidy/backends/libspotify/session_manager.py create mode 100644 mopidy/backends/libspotify/stored_playlists.py create mode 100644 mopidy/backends/libspotify/translator.py diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index 974e52df..ead08c44 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -1,19 +1,7 @@ -import datetime as dt import logging -import os -import multiprocessing -import threading -from spotify import Link, SpotifyError -from spotify.manager import SpotifySessionManager -from spotify.alsahelper import AlsaController - -from mopidy import get_version, settings -from mopidy.backends.base import (BaseBackend, BaseCurrentPlaylistController, - BaseLibraryController, BasePlaybackController, - BaseStoredPlaylistsController) -from mopidy.models import Artist, Album, Track, Playlist -from mopidy.process import pickle_connection +from mopidy import settings +from mopidy.backends.base import BaseBackend, BaseCurrentPlaylistController logger = logging.getLogger('mopidy.backends.libspotify') @@ -35,8 +23,15 @@ class LibspotifyBackend(BaseBackend): **Issues:** http://github.com/jodal/mopidy/issues/labels/backend-libspotify """ + # Imports inside methods are to prevent loading of __init__ to fail on + # missing spotify dependencies. def __init__(self, *args, **kwargs): + from .library import LibspotifyLibraryController + from .playback import LibspotifyPlaybackController + from .stored_playlists import LibspotifyStoredPlaylistsController + super(LibspotifyBackend, self).__init__(*args, **kwargs) + self.current_playlist = BaseCurrentPlaylistController(backend=self) self.library = LibspotifyLibraryController(backend=self) self.playback = LibspotifyPlaybackController(backend=self) @@ -46,6 +41,8 @@ class LibspotifyBackend(BaseBackend): self.spotify = self._connect() def _connect(self): + from .session_manager import LibspotifySessionManager + logger.info(u'Connecting to Spotify') spotify = LibspotifySessionManager( settings.SPOTIFY_USERNAME, settings.SPOTIFY_PASSWORD, @@ -53,241 +50,3 @@ class LibspotifyBackend(BaseBackend): output_queue=self.output_queue) spotify.start() return spotify - - -class LibspotifyLibraryController(BaseLibraryController): - def find_exact(self, **query): - return self.search(**query) - - def lookup(self, uri): - spotify_track = Link.from_string(uri).as_track() - return LibspotifyTranslator.to_mopidy_track(spotify_track) - - def refresh(self, uri=None): - pass # TODO - - def search(self, **query): - spotify_query = [] - for (field, values) in query.iteritems(): - if not hasattr(values, '__iter__'): - values = [values] - for value in values: - if field == u'track': - field = u'title' - if field == u'any': - spotify_query.append(value) - else: - spotify_query.append(u'%s:"%s"' % (field, value)) - spotify_query = u' '.join(spotify_query) - logger.debug(u'Spotify search query: %s' % spotify_query) - my_end, other_end = multiprocessing.Pipe() - self.backend.spotify.search(spotify_query.encode(ENCODING), other_end) - my_end.poll(None) - playlist = my_end.recv() - return playlist - - -class LibspotifyPlaybackController(BasePlaybackController): - def _set_output_state(self, state_name): - logger.debug(u'Setting output state to %s ...', state_name) - (my_end, other_end) = multiprocessing.Pipe() - self.backend.output_queue.put({ - 'command': 'set_state', - 'state': state_name, - 'reply_to': pickle_connection(other_end), - }) - my_end.poll(None) - return my_end.recv() - - def _pause(self): - return self._set_output_state('PAUSED') - - def _play(self, track): - self._set_output_state('READY') - if self.state == self.PLAYING: - self.stop() - if track.uri is None: - return False - try: - self.backend.spotify.session.load( - Link.from_string(track.uri).as_track()) - self.backend.spotify.session.play(1) - self._set_output_state('PLAYING') - return True - except SpotifyError as e: - logger.warning('Play %s failed: %s', track.uri, e) - return False - - def _resume(self): - return self._set_output_state('PLAYING') - - def _seek(self, time_position): - pass # TODO - - def _stop(self): - result = self._set_output_state('READY') - self.backend.spotify.session.play(0) - return result - - -class LibspotifyStoredPlaylistsController(BaseStoredPlaylistsController): - def create(self, name): - pass # TODO - - def delete(self, playlist): - pass # TODO - - def lookup(self, uri): - pass # TODO - - def refresh(self): - pass # TODO - - def rename(self, playlist, new_name): - pass # TODO - - def save(self, playlist): - pass # TODO - - -class LibspotifyTranslator(object): - @classmethod - def to_mopidy_artist(cls, spotify_artist): - if not spotify_artist.is_loaded(): - return Artist(name=u'[loading...]') - return Artist( - uri=str(Link.from_artist(spotify_artist)), - name=spotify_artist.name().decode(ENCODING), - ) - - @classmethod - def to_mopidy_album(cls, spotify_album): - if not spotify_album.is_loaded(): - return Album(name=u'[loading...]') - # TODO pyspotify got much more data on albums than this - return Album(name=spotify_album.name().decode(ENCODING)) - - @classmethod - def to_mopidy_track(cls, spotify_track): - if not spotify_track.is_loaded(): - return Track(name=u'[loading...]') - uri = str(Link.from_track(spotify_track, 0)) - if dt.MINYEAR <= int(spotify_track.album().year()) <= dt.MAXYEAR: - date = dt.date(spotify_track.album().year(), 1, 1) - else: - date = None - return Track( - uri=uri, - name=spotify_track.name().decode(ENCODING), - artists=[cls.to_mopidy_artist(a) for a in spotify_track.artists()], - album=cls.to_mopidy_album(spotify_track.album()), - track_no=spotify_track.index(), - date=date, - length=spotify_track.duration(), - bitrate=320, - ) - - @classmethod - def to_mopidy_playlist(cls, spotify_playlist): - if not spotify_playlist.is_loaded(): - return Playlist(name=u'[loading...]') - return Playlist( - uri=str(Link.from_playlist(spotify_playlist)), - name=spotify_playlist.name().decode(ENCODING), - tracks=[cls.to_mopidy_track(t) for t in spotify_playlist], - ) - -class LibspotifySessionManager(SpotifySessionManager, threading.Thread): - cache_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) - settings_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) - appkey_file = os.path.expanduser(settings.SPOTIFY_LIB_APPKEY) - user_agent = 'Mopidy %s' % get_version() - - def __init__(self, username, password, core_queue, output_queue): - SpotifySessionManager.__init__(self, username, password) - threading.Thread.__init__(self) - self.core_queue = core_queue - self.output_queue = output_queue - self.connected = threading.Event() - self.session = None - - def run(self): - self.connect() - - def logged_in(self, session, error): - """Callback used by pyspotify""" - logger.info('Logged in') - self.session = session - self.connected.set() - - def logged_out(self, session): - """Callback used by pyspotify""" - logger.info('Logged out') - - def metadata_updated(self, session): - """Callback used by pyspotify""" - logger.debug('Metadata updated, refreshing stored playlists') - playlists = [] - for spotify_playlist in session.playlist_container(): - playlists.append( - LibspotifyTranslator.to_mopidy_playlist(spotify_playlist)) - self.core_queue.put({ - 'command': 'set_stored_playlists', - 'playlists': playlists, - }) - - def connection_error(self, session, error): - """Callback used by pyspotify""" - logger.error('Connection error: %s', error) - - def message_to_user(self, session, message): - """Callback used by pyspotify""" - logger.info(message) - - def notify_main_thread(self, session): - """Callback used by pyspotify""" - logger.debug('Notify main thread') - - def music_delivery(self, session, frames, frame_size, num_frames, - sample_type, sample_rate, channels): - """Callback used by pyspotify""" - # TODO Base caps_string on arguments - caps_string = """ - audio/x-raw-int, - endianness=(int)1234, - channels=(int)2, - width=(int)16, - depth=(int)16, - signed=True, - rate=(int)44100 - """ - self.output_queue.put({ - 'command': 'deliver_data', - 'caps': caps_string, - 'data': bytes(frames), - }) - - def play_token_lost(self, session): - """Callback used by pyspotify""" - logger.debug('Play token lost') - self.core_queue.put({'command': 'stop_playback'}) - - def log_message(self, session, data): - """Callback used by pyspotify""" - logger.debug(data) - - def end_of_track(self, session): - """Callback used by pyspotify""" - logger.debug('End of data stream.') - self.output_queue.put({'command': 'end_of_data_stream'}) - - def search(self, query, connection): - """Search method used by Mopidy backend""" - def callback(results, userdata): - # TODO Include results from results.albums(), etc. too - playlist = Playlist(tracks=[ - LibspotifyTranslator.to_mopidy_track(t) - for t in results.tracks()]) - connection.send(playlist) - self.connected.wait() - self.session.search(query, callback) diff --git a/mopidy/backends/libspotify/library.py b/mopidy/backends/libspotify/library.py new file mode 100644 index 00000000..c2b70dca --- /dev/null +++ b/mopidy/backends/libspotify/library.py @@ -0,0 +1,41 @@ +import logging +import multiprocessing + +from spotify import Link + +from mopidy.backends.base import BaseLibraryController +from mopidy.backends.libspotify import ENCODING +from mopidy.backends.libspotify.translator import LibspotifyTranslator + +logger = logging.getLogger('mopidy.backends.libspotify.library') + +class LibspotifyLibraryController(BaseLibraryController): + def find_exact(self, **query): + return self.search(**query) + + def lookup(self, uri): + spotify_track = Link.from_string(uri).as_track() + return LibspotifyTranslator.to_mopidy_track(spotify_track) + + def refresh(self, uri=None): + pass # TODO + + def search(self, **query): + spotify_query = [] + for (field, values) in query.iteritems(): + if not hasattr(values, '__iter__'): + values = [values] + for value in values: + if field == u'track': + field = u'title' + if field == u'any': + spotify_query.append(value) + else: + spotify_query.append(u'%s:"%s"' % (field, value)) + spotify_query = u' '.join(spotify_query) + logger.debug(u'Spotify search query: %s' % spotify_query) + my_end, other_end = multiprocessing.Pipe() + self.backend.spotify.search(spotify_query.encode(ENCODING), other_end) + my_end.poll(None) + playlist = my_end.recv() + return playlist diff --git a/mopidy/backends/libspotify/playback.py b/mopidy/backends/libspotify/playback.py new file mode 100644 index 00000000..3ba91d5f --- /dev/null +++ b/mopidy/backends/libspotify/playback.py @@ -0,0 +1,51 @@ +import logging +import multiprocessing + +from spotify import Link, SpotifyError + +from mopidy.backends.base import BasePlaybackController +from mopidy.process import pickle_connection + +logger = logging.getLogger('mopidy.backends.libspotify.playback') + +class LibspotifyPlaybackController(BasePlaybackController): + def _set_output_state(self, state_name): + logger.debug(u'Setting output state to %s ...', state_name) + (my_end, other_end) = multiprocessing.Pipe() + self.backend.output_queue.put({ + 'command': 'set_state', + 'state': state_name, + 'reply_to': pickle_connection(other_end), + }) + my_end.poll(None) + return my_end.recv() + + def _pause(self): + return self._set_output_state('PAUSED') + + def _play(self, track): + self._set_output_state('READY') + if self.state == self.PLAYING: + self.stop() + if track.uri is None: + return False + try: + self.backend.spotify.session.load( + Link.from_string(track.uri).as_track()) + self.backend.spotify.session.play(1) + self._set_output_state('PLAYING') + return True + except SpotifyError as e: + logger.warning('Play %s failed: %s', track.uri, e) + return False + + def _resume(self): + return self._set_output_state('PLAYING') + + def _seek(self, time_position): + pass # TODO + + def _stop(self): + result = self._set_output_state('READY') + self.backend.spotify.session.play(0) + return result diff --git a/mopidy/backends/libspotify/session_manager.py b/mopidy/backends/libspotify/session_manager.py new file mode 100644 index 00000000..e286b059 --- /dev/null +++ b/mopidy/backends/libspotify/session_manager.py @@ -0,0 +1,106 @@ +import logging +import os +import threading + +from spotify.manager import SpotifySessionManager + +from mopidy import get_version, settings +from mopidy.models import Playlist +from mopidy.backends.libspotify.translator import LibspotifyTranslator + +logger = logging.getLogger('mopidy.backends.libspotify.session_manager') + +class LibspotifySessionManager(SpotifySessionManager, threading.Thread): + cache_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) + settings_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) + appkey_file = os.path.expanduser(settings.SPOTIFY_LIB_APPKEY) + user_agent = 'Mopidy %s' % get_version() + + def __init__(self, username, password, core_queue, output_queue): + SpotifySessionManager.__init__(self, username, password) + threading.Thread.__init__(self) + self.core_queue = core_queue + self.output_queue = output_queue + self.connected = threading.Event() + self.session = None + + def run(self): + self.connect() + + def logged_in(self, session, error): + """Callback used by pyspotify""" + logger.info('Logged in') + self.session = session + self.connected.set() + + def logged_out(self, session): + """Callback used by pyspotify""" + logger.info('Logged out') + + def metadata_updated(self, session): + """Callback used by pyspotify""" + logger.debug('Metadata updated, refreshing stored playlists') + playlists = [] + for spotify_playlist in session.playlist_container(): + playlists.append( + LibspotifyTranslator.to_mopidy_playlist(spotify_playlist)) + self.core_queue.put({ + 'command': 'set_stored_playlists', + 'playlists': playlists, + }) + + def connection_error(self, session, error): + """Callback used by pyspotify""" + logger.error('Connection error: %s', error) + + def message_to_user(self, session, message): + """Callback used by pyspotify""" + logger.info(message) + + def notify_main_thread(self, session): + """Callback used by pyspotify""" + logger.debug('Notify main thread') + + def music_delivery(self, session, frames, frame_size, num_frames, + sample_type, sample_rate, channels): + """Callback used by pyspotify""" + # TODO Base caps_string on arguments + caps_string = """ + audio/x-raw-int, + endianness=(int)1234, + channels=(int)2, + width=(int)16, + depth=(int)16, + signed=True, + rate=(int)44100 + """ + self.output_queue.put({ + 'command': 'deliver_data', + 'caps': caps_string, + 'data': bytes(frames), + }) + + def play_token_lost(self, session): + """Callback used by pyspotify""" + logger.debug('Play token lost') + self.core_queue.put({'command': 'stop_playback'}) + + def log_message(self, session, data): + """Callback used by pyspotify""" + logger.debug(data) + + def end_of_track(self, session): + """Callback used by pyspotify""" + logger.debug('End of data stream.') + self.output_queue.put({'command': 'end_of_data_stream'}) + + def search(self, query, connection): + """Search method used by Mopidy backend""" + def callback(results, userdata): + # TODO Include results from results.albums(), etc. too + playlist = Playlist(tracks=[ + LibspotifyTranslator.to_mopidy_track(t) + for t in results.tracks()]) + connection.send(playlist) + self.connected.wait() + self.session.search(query, callback) diff --git a/mopidy/backends/libspotify/stored_playlists.py b/mopidy/backends/libspotify/stored_playlists.py new file mode 100644 index 00000000..3339578c --- /dev/null +++ b/mopidy/backends/libspotify/stored_playlists.py @@ -0,0 +1,20 @@ +from mopidy.backends.base import BaseStoredPlaylistsController + +class LibspotifyStoredPlaylistsController(BaseStoredPlaylistsController): + def create(self, name): + pass # TODO + + def delete(self, playlist): + pass # TODO + + def lookup(self, uri): + pass # TODO + + def refresh(self): + pass # TODO + + def rename(self, playlist, new_name): + pass # TODO + + def save(self, playlist): + pass # TODO diff --git a/mopidy/backends/libspotify/translator.py b/mopidy/backends/libspotify/translator.py new file mode 100644 index 00000000..3a39aad5 --- /dev/null +++ b/mopidy/backends/libspotify/translator.py @@ -0,0 +1,53 @@ +import datetime as dt + +from spotify import Link + +from mopidy.models import Artist, Album, Track, Playlist +from mopidy.backends.libspotify import ENCODING + +class LibspotifyTranslator(object): + @classmethod + def to_mopidy_artist(cls, spotify_artist): + if not spotify_artist.is_loaded(): + return Artist(name=u'[loading...]') + return Artist( + uri=str(Link.from_artist(spotify_artist)), + name=spotify_artist.name().decode(ENCODING), + ) + + @classmethod + def to_mopidy_album(cls, spotify_album): + if not spotify_album.is_loaded(): + return Album(name=u'[loading...]') + # TODO pyspotify got much more data on albums than this + return Album(name=spotify_album.name().decode(ENCODING)) + + @classmethod + def to_mopidy_track(cls, spotify_track): + if not spotify_track.is_loaded(): + return Track(name=u'[loading...]') + uri = str(Link.from_track(spotify_track, 0)) + if dt.MINYEAR <= int(spotify_track.album().year()) <= dt.MAXYEAR: + date = dt.date(spotify_track.album().year(), 1, 1) + else: + date = None + return Track( + uri=uri, + name=spotify_track.name().decode(ENCODING), + artists=[cls.to_mopidy_artist(a) for a in spotify_track.artists()], + album=cls.to_mopidy_album(spotify_track.album()), + track_no=spotify_track.index(), + date=date, + length=spotify_track.duration(), + bitrate=320, + ) + + @classmethod + def to_mopidy_playlist(cls, spotify_playlist): + if not spotify_playlist.is_loaded(): + return Playlist(name=u'[loading...]') + return Playlist( + uri=str(Link.from_playlist(spotify_playlist)), + name=spotify_playlist.name().decode(ENCODING), + tracks=[cls.to_mopidy_track(t) for t in spotify_playlist], + ) From 059f96814d80fc1a3c14e7e9f40428865ceb233a Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Fri, 13 Aug 2010 22:16:11 +0200 Subject: [PATCH 034/138] Add basic tests for get_class util --- tests/utils_test.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/utils_test.py b/tests/utils_test.py index d5c98d86..9a8f1129 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -11,6 +11,15 @@ from mopidy.models import Track, Artist, Album from tests import SkipTest, data_folder +class GetClassTest(unittest.TestCase): + def test_loading_class_that_does_not_exist(self): + test = lambda: get_class('foo.bar.Baz') + self.assertRaises(ImportError, test) + + def test_loading_existing_class(self): + cls = get_class('unittest.TestCase') + self.assertEqual(cls.__name__, 'TestCase') + class GetOrCreateFolderTest(unittest.TestCase): def setUp(self): self.parent = tempfile.mkdtemp() From db26a7198da4cf222abd399241700fbfc9554316 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 13 Aug 2010 22:26:13 +0200 Subject: [PATCH 035/138] Remove notes on openspotify, as development has been inactive for six months --- docs/development/roadmap.rst | 4 ---- mopidy/backends/libspotify/__init__.py | 7 ++----- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/docs/development/roadmap.rst b/docs/development/roadmap.rst index 5544a005..7d97d55b 100644 --- a/docs/development/roadmap.rst +++ b/docs/development/roadmap.rst @@ -31,10 +31,6 @@ released when we reach the other goal. Stuff we really want to do, but just not right now ================================================== -- Replace libspotify with `openspotify - `_ for - :mod:`mopidy.backends.libspotify`. *Update:* Seems like openspotify - development has stalled. - Create `Debian packages `_ of all our dependencies and Mopidy itself (hosted in our own Debian repo until we get stuff into the various distros) to make Debian/Ubuntu installation a breeze. diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index ead08c44..7a971bc5 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -16,15 +16,12 @@ class LibspotifyBackend(BaseBackend): for libspotify. It got no documentation, but multiple examples are available. Like libspotify, pyspotify's calls are mostly asynchronous. - This backend should also work with `openspotify - `_, but we haven't tested - that yet. - **Issues:** http://github.com/jodal/mopidy/issues/labels/backend-libspotify """ - # Imports inside methods are to prevent loading of __init__ to fail on + # Imports inside methods are to prevent loading of __init__.py to fail on # missing spotify dependencies. + def __init__(self, *args, **kwargs): from .library import LibspotifyLibraryController from .playback import LibspotifyPlaybackController From e4bdacbb61a6894a8515bd5bae100cb978514028 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Fri, 13 Aug 2010 22:28:02 +0200 Subject: [PATCH 036/138] Add test_import_error_message_contains_complete_class_path test for get_class --- mopidy/utils.py | 5 ++++- tests/utils_test.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mopidy/utils.py b/mopidy/utils.py index ff032b4e..b8aa574c 100644 --- a/mopidy/utils.py +++ b/mopidy/utils.py @@ -24,7 +24,10 @@ def get_class(name): module_name = name[:name.rindex('.')] class_name = name[name.rindex('.') + 1:] logger.debug('Loading: %s', name) - module = import_module(module_name) + try: + module = import_module(module_name) + except ImportError: + raise ImportError("Couldn't load: %s" % name) class_object = getattr(module, class_name) return class_object diff --git a/tests/utils_test.py b/tests/utils_test.py index 9a8f1129..d5beade2 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -16,6 +16,12 @@ class GetClassTest(unittest.TestCase): test = lambda: get_class('foo.bar.Baz') self.assertRaises(ImportError, test) + def test_import_error_message_contains_complete_class_path(self): + try: + get_class('foo.bar.Baz') + except ImportError as e: + self.assert_('foo.bar.Baz' in str(e)) + def test_loading_existing_class(self): cls = get_class('unittest.TestCase') self.assertEqual(cls.__name__, 'TestCase') From 710eb91892aeddc79d9e8e542d9e4350a3095989 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 13 Aug 2010 22:29:27 +0200 Subject: [PATCH 037/138] docs: Update Homebrew point on roadmap --- docs/development/roadmap.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/development/roadmap.rst b/docs/development/roadmap.rst index 7d97d55b..243243ab 100644 --- a/docs/development/roadmap.rst +++ b/docs/development/roadmap.rst @@ -31,11 +31,13 @@ released when we reach the other goal. Stuff we really want to do, but just not right now ================================================== +- **[PENDING]** Create `Homebrew `_ recipies + for all our dependencies and Mopidy itself to make OS X installation a + breeze. See `Homebrew's issue #1612 + `_. - Create `Debian packages `_ of all our dependencies and Mopidy itself (hosted in our own Debian repo until we get stuff into the various distros) to make Debian/Ubuntu installation a breeze. -- **[WIP]** Create `Homebrew `_ recipies for - all our dependencies and Mopidy itself to make OS X installation a breeze. - Run frontend tests against a real MPD server to ensure we are in sync. - Start working with MPD client maintainers to get rid of weird assumptions like only searching for first two letters and doing the rest of the filtering From ec67d43fc960d5537fef3fdf5e6fc46c6a354e0f Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Fri, 13 Aug 2010 22:29:41 +0200 Subject: [PATCH 038/138] Test both case where class and/or module does not exist for get_class --- mopidy/utils.py | 4 ++-- tests/utils_test.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mopidy/utils.py b/mopidy/utils.py index b8aa574c..bdc0b632 100644 --- a/mopidy/utils.py +++ b/mopidy/utils.py @@ -26,9 +26,9 @@ def get_class(name): logger.debug('Loading: %s', name) try: module = import_module(module_name) - except ImportError: + class_object = getattr(module, class_name) + except (ImportError, AttributeError): raise ImportError("Couldn't load: %s" % name) - class_object = getattr(module, class_name) return class_object def get_or_create_folder(folder): diff --git a/tests/utils_test.py b/tests/utils_test.py index d5beade2..ca44de45 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -12,10 +12,14 @@ from mopidy.models import Track, Artist, Album from tests import SkipTest, data_folder class GetClassTest(unittest.TestCase): - def test_loading_class_that_does_not_exist(self): + def test_loading_module_that_does_not_exist(self): test = lambda: get_class('foo.bar.Baz') self.assertRaises(ImportError, test) + def test_loading_class_that_does_not_exist(self): + test = lambda: get_class('unittest.FooBarBaz') + self.assertRaises(ImportError, test) + def test_import_error_message_contains_complete_class_path(self): try: get_class('foo.bar.Baz') From fa9edf23cf0d3a028095e83737cff4a69fc43dff Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 13 Aug 2010 22:29:56 +0200 Subject: [PATCH 039/138] Update MANIFEST.in to include LICENSE instead of COPYING --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index cb752f87..8a73b481 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include COPYING pylintrc *.rst *.txt +include LICENSE pylintrc *.rst *.txt recursive-include docs * prune docs/_build recursive-include tests *.py From 9c11c5ecb9ad5f57307a30d133ccdeb8f1a11f93 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Fri, 13 Aug 2010 22:40:38 +0200 Subject: [PATCH 040/138] Log when a process has a problem importing classes and try to exit --- mopidy/process.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mopidy/process.py b/mopidy/process.py index 9759c4e6..79638515 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -28,6 +28,9 @@ class BaseProcess(multiprocessing.Process): except SettingsError as e: logger.error(e.message) sys.exit(1) + except ImportError as e: + logger.error(e) + sys.exit(1) def run_inside_try(self): raise NotImplementedError From a05212251bec02740b651eaf9849e190ebd1546e Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Fri, 13 Aug 2010 22:48:51 +0200 Subject: [PATCH 041/138] Pass output, backend and frontend classes into coreprocess to so that import errors are handeled better --- mopidy/__main__.py | 5 ++++- mopidy/process.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mopidy/__main__.py b/mopidy/__main__.py index 7c62033b..c92ce1ed 100644 --- a/mopidy/__main__.py +++ b/mopidy/__main__.py @@ -22,7 +22,10 @@ def main(): get_or_create_folder('~/.mopidy/') core_queue = multiprocessing.Queue() get_class(settings.SERVER)(core_queue).start() - core = CoreProcess(core_queue) + output_class = get_class(settings.OUTPUT) + backend_class = get_class(settings.BACKENDS[0]) + frontend_class = get_class(settings.FRONTEND) + core = CoreProcess(core_queue, output_class, backend_class, frontend_class) core.start() asyncore.loop() diff --git a/mopidy/process.py b/mopidy/process.py index 79638515..b1cdc8af 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -37,10 +37,14 @@ class BaseProcess(multiprocessing.Process): class CoreProcess(BaseProcess): - def __init__(self, core_queue): + def __init__(self, core_queue, output_class, backend_class, + frontend_class): super(CoreProcess, self).__init__() self.core_queue = core_queue self.output_queue = None + self.output_class = output_class + self.backend_class = backend_class + self.frontend_class = frontend_class self.output = None self.backend = None self.frontend = None @@ -53,11 +57,9 @@ class CoreProcess(BaseProcess): def setup(self): self.output_queue = multiprocessing.Queue() - self.output = get_class(settings.OUTPUT)(self.core_queue, - self.output_queue) - self.backend = get_class(settings.BACKENDS[0])(self.core_queue, - self.output_queue) - self.frontend = get_class(settings.FRONTEND)(self.backend) + self.output = self.output_class(self.core_queue, self.output_queue) + self.backend = self.backend_class(self.core_queue, self.output_queue) + self.frontend = self.frontend_class(self.backend) def process_message(self, message): if message.get('to') == 'output': From 81928b831c354de0b79b4e203f235c8067b535fb Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 13 Aug 2010 23:20:17 +0200 Subject: [PATCH 042/138] Strip newline at end of libspotify log messages --- mopidy/backends/libspotify/session_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mopidy/backends/libspotify/session_manager.py b/mopidy/backends/libspotify/session_manager.py index e286b059..2de6ae63 100644 --- a/mopidy/backends/libspotify/session_manager.py +++ b/mopidy/backends/libspotify/session_manager.py @@ -55,7 +55,7 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): def message_to_user(self, session, message): """Callback used by pyspotify""" - logger.info(message) + logger.info(message.strip()) def notify_main_thread(self, session): """Callback used by pyspotify""" @@ -87,7 +87,7 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread): def log_message(self, session, data): """Callback used by pyspotify""" - logger.debug(data) + logger.debug(data.strip()) def end_of_track(self, session): """Callback used by pyspotify""" From 5a4d0bd7160ce8741ca876bf626ee0a93959259e Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 13 Aug 2010 23:41:31 +0200 Subject: [PATCH 043/138] Freshen up settings docs --- docs/api/settings.rst | 2 +- mopidy/settings.py | 81 ++++++++++++++++++++++++++++++++----------- 2 files changed, 61 insertions(+), 22 deletions(-) diff --git a/docs/api/settings.rst b/docs/api/settings.rst index 12d2833f..cfc270d6 100644 --- a/docs/api/settings.rst +++ b/docs/api/settings.rst @@ -13,7 +13,7 @@ there. A complete ``~/.mopidy/settings.py`` may look like this:: - MPD_SERVER_HOSTNAME = u'0.0.0.0' + MPD_SERVER_HOSTNAME = u'::' SPOTIFY_USERNAME = u'alice' SPOTIFY_PASSWORD = u'mysecret' diff --git a/mopidy/settings.py b/mopidy/settings.py index d4321685..949b2e06 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -3,16 +3,19 @@ Available settings and their default values. .. warning:: - Do *not* change settings in ``mopidy/settings.py``. Instead, add a file - called ``~/.mopidy/settings.py`` and redefine settings there. + Do *not* change settings directly in :mod:`mopidy.settings`. Instead, add a + file called ``~/.mopidy/settings.py`` and redefine settings there. """ +# Absolute import needed to import ~/.mopidy/settings.py and not ourselves from __future__ import absolute_import import os import sys #: List of playback backends to use. See :mod:`mopidy.backends` for all -#: available backends. Default:: +#: available backends. +#: +#: Default:: #: #: BACKENDS = (u'mopidy.backends.libspotify.LibspotifyBackend',) #: @@ -28,32 +31,51 @@ BACKENDS = ( CONSOLE_LOG_FORMAT = u'%(levelname)-8s %(asctime)s' + \ ' [%(process)d:%(threadName)s] %(name)s\n %(message)s' -#: The log format used for dump logs. Default:: +#: The log format used for dump logs. +#: +#: Default:: #: #: DUMP_LOG_FILENAME = CONSOLE_LOG_FORMAT DUMP_LOG_FORMAT = CONSOLE_LOG_FORMAT -#: The file to dump debug log data to. Default:: +#: The file to dump debug log data to when Mopidy is run with the +#: :option:`--dump` option. +#: +#: Default:: #: #: DUMP_LOG_FILENAME = u'dump.log' DUMP_LOG_FILENAME = u'dump.log' -#: Protocol frontend to use. Default:: +#: Protocol frontend to use. +#: +#: Default:: #: #: FRONTEND = u'mopidy.frontends.mpd.frontend.MpdFrontend' FRONTEND = u'mopidy.frontends.mpd.frontend.MpdFrontend' -#: Path to folder with local music. Default:: +#: Path to folder with local music. +#: +#: Used by :mod:`mopidy.backends.local`. +#: +#: Default:: #: #: LOCAL_MUSIC_FOLDER = u'~/music' LOCAL_MUSIC_FOLDER = u'~/music' -#: Path to playlist folder with m3u files for local music. Default:: +#: Path to playlist folder with m3u files for local music. +#: +#: Used by :mod:`mopidy.backends.local`. +#: +#: Default:: #: #: LOCAL_PLAYLIST_FOLDER = u'~/.mopidy/playlists' LOCAL_PLAYLIST_FOLDER = u'~/.mopidy/playlists' -#: Path to tag cache for local music. Default:: +#: Path to tag cache for local music. +#: +#: Used by :mod:`mopidy.backends.local`. +#: +#: Default:: #: #: LOCAL_TAG_CACHE = u'~/.mopidy/tag_cache' LOCAL_TAG_CACHE = u'~/.mopidy/tag_cache' @@ -86,6 +108,7 @@ MIXER_ALSA_CONTROL = False #: External mixers only. Which port the mixer is connected to. #: #: This must point to the device port like ``/dev/ttyUSB0``. +#: #: Default: :class:`None` MIXER_EXT_PORT = None @@ -104,17 +127,23 @@ MIXER_EXT_SPEAKERS_A = None #: Default: :class:`None`. MIXER_EXT_SPEAKERS_B = None -#: Audio output handler to use. Default:: +#: Audio output handler to use. +#: +#: Default:: #: #: OUTPUT = u'mopidy.outputs.gstreamer.GStreamerOutput' OUTPUT = u'mopidy.outputs.gstreamer.GStreamerOutput' -#: Server to use. Default:: +#: Server to use. +#: +#: Default:: #: #: SERVER = u'mopidy.frontends.mpd.server.MpdServer' SERVER = u'mopidy.frontends.mpd.server.MpdServer' -#: Which address Mopidy should bind to. Examples: +#: Which address Mopidy's MPD server should bind to. +#: +#:Examples: #: #: ``127.0.0.1`` #: Listens only on the IPv4 loopback interface. Default. @@ -126,21 +155,31 @@ SERVER = u'mopidy.frontends.mpd.server.MpdServer' #: Listens on all interfaces, both IPv4 and IPv6. MPD_SERVER_HOSTNAME = u'127.0.0.1' -#: Which TCP port Mopidy should listen to. Default: 6600 +#: Which TCP port Mopidy's MPD server should listen to. +#: +#: Default: 6600 MPD_SERVER_PORT = 6600 -#: Your Spotify Premium username. Used by all Spotify backends. -SPOTIFY_USERNAME = u'' - -#: Your Spotify Premium password. Used by all Spotify backends. -SPOTIFY_PASSWORD = u'' - -#: Path to your libspotify application key. Used by LibspotifyBackend. +#: Path to your libspotify application key. +#: +#: Used by :mod:`mopidy.backends.libspotify`. SPOTIFY_LIB_APPKEY = u'~/.mopidy/spotify_appkey.key' -#: Path to the libspotify cache. Used by LibspotifyBackend. +#: Path to the libspotify cache. +#: +#: Used by :mod:`mopidy.backends.libspotify`. SPOTIFY_LIB_CACHE = u'~/.mopidy/libspotify_cache' +#: Your Spotify Premium username. +#: +#: Used by :mod:`mopidy.backends.libspotify`. +SPOTIFY_USERNAME = u'' + +#: Your Spotify Premium password. +#: +#: Used by :mod:`mopidy.backends.libspotify`. +SPOTIFY_PASSWORD = u'' + # Import user specific settings dotdir = os.path.expanduser(u'~/.mopidy/') settings_file = os.path.join(dotdir, u'settings.py') From b777397cceb63bbccce302904e78b51c5991ab17 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Fri, 13 Aug 2010 23:52:46 +0200 Subject: [PATCH 044/138] Cleanup pipe creation for GStreamer output --- mopidy/outputs/gstreamer.py | 44 +++++-------------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 65b65504..b81fbd0f 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -39,6 +39,8 @@ class GStreamerProcess(BaseProcess): http://jameswestby.net/weblog/tech/14-caution-python-multiprocessing-and-glib-dont-mix.html. """ + pipeline_description = 'appsrc name=data ! volume name=volume ! autoaudiosink name=sink' + def __init__(self, core_queue, output_queue): super(GStreamerProcess, self).__init__() self.core_queue = core_queue @@ -65,8 +67,10 @@ class GStreamerProcess(BaseProcess): messages_thread.daemon = True messages_thread.start() - # A pipeline consisting of many elements - self.gst_pipeline = gst.Pipeline("pipeline") + self.gst_pipeline = gst.parse_launch(self.pipeline_description) + self.gst_data_src = self.gst_pipeline.get_by_name('data') + self.gst_volume = self.gst_pipeline.get_by_name('volume') + self.gst_sink = self.gst_pipeline.get_by_name('sink') # Setup bus and message processor self.gst_bus = self.gst_pipeline.get_bus() @@ -74,42 +78,6 @@ class GStreamerProcess(BaseProcess): self.gst_bus_id = self.gst_bus.connect('message', self.process_gst_message) - # Bin for playing audio URIs - #self.gst_uri_src = gst.element_factory_make('uridecodebin', 'uri_src') - #self.gst_pipeline.add(self.gst_uri_src) - - # Bin for playing audio data - self.gst_data_src = gst.element_factory_make('appsrc', 'data_src') - self.gst_pipeline.add(self.gst_data_src) - - # Volume filter - self.gst_volume = gst.element_factory_make('volume', 'volume') - self.gst_pipeline.add(self.gst_volume) - - # Audio output sink - self.gst_sink = gst.element_factory_make('autoaudiosink', 'sink') - self.gst_pipeline.add(self.gst_sink) - - # Add callback that will link uri_src output with volume filter input - # when the output pad is ready. - # See http://stackoverflow.com/questions/2993777 for details. - def on_new_decoded_pad(dbin, pad, is_last): - uri_src = pad.get_parent() - pipeline = uri_src.get_parent() - volume = pipeline.get_by_name('volume') - uri_src.link(volume) - logger.debug("Linked uri_src's new decoded pad to volume filter") - # FIXME uridecodebin got no new-decoded-pad signal, but it's - # subcomponent decodebin2 got that signal. Fixing this is postponed - # till after data_src is up and running perfectly - #self.gst_uri_src.connect('new-decoded-pad', on_new_decoded_pad) - - # Link data source output with volume filter input - self.gst_data_src.link(self.gst_volume) - - # Link volume filter output to audio sink input - self.gst_volume.link(self.gst_sink) - def process_mopidy_message(self, message): """Process messages from the rest of Mopidy.""" if message['command'] == 'play_uri': From 8d19301d41e8bc6f2e81c875671ea8e500a9e3c5 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 00:48:15 +0200 Subject: [PATCH 045/138] Update license i PyPI classifiers --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index bbf300f7..33113732 100644 --- a/setup.py +++ b/setup.py @@ -52,14 +52,14 @@ setup( data_files=data_files, scripts=['bin/mopidy'], url='http://www.mopidy.com/', - license='GPLv2', + license='Apache License, Version 2.0', description='MPD server with Spotify support', long_description=open('README.rst').read(), classifiers=[ 'Development Status :: 3 - Alpha', 'Environment :: No Input/Output (Daemon)', 'Intended Audience :: End Users/Desktop', - 'License :: OSI Approved :: GNU General Public License (GPL)', + 'License :: OSI Approved :: Apache Software License', 'Operating System :: MacOS :: MacOS X', 'Operating System :: POSIX :: Linux', 'Programming Language :: Python :: 2.6', From 4ceb86cad0882a6f0568a58ada154b1a5c9b66da Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 00:48:37 +0200 Subject: [PATCH 046/138] Switch to beta status in PyPI classifiers --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 33113732..5ac94c00 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,7 @@ setup( description='MPD server with Spotify support', long_description=open('README.rst').read(), classifiers=[ - 'Development Status :: 3 - Alpha', + 'Development Status :: 4 - Beta', 'Environment :: No Input/Output (Daemon)', 'Intended Audience :: End Users/Desktop', 'License :: OSI Approved :: Apache Software License', From 63d2e7710e6088cee4162c9987c4ba4179d32965 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 00:50:22 +0200 Subject: [PATCH 047/138] Copy distutils install_data fix from Django --- setup.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5ac94c00..76c38e4b 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,34 @@ +""" +Most of this file is taken from the Django project, which is BSD licensed. +""" + from distutils.core import setup +from distutils.command.install_data import install_data from distutils.command.install import INSTALL_SCHEMES import os +import sys from mopidy import get_version +class osx_install_data(install_data): + # On MacOS, the platform-specific lib dir is + # /System/Library/Framework/Python/.../ which is wrong. Python 2.5 supplied + # with MacOS 10.5 has an Apple-specific fix for this in + # distutils.command.install_data#306. It fixes install_lib but not + # install_data, which is why we roll our own install_data class. + + def finalize_options(self): + # By the time finalize_options is called, install.install_lib is set to + # the fixed directory, so we set the installdir to install_lib. The + # install_data class uses ('install_data', 'install_dir') instead. + self.set_undefined_options('install', ('install_lib', 'install_dir')) + install_data.finalize_options(self) + +if sys.platform == "darwin": + cmdclasses = {'install_data': osx_install_data} +else: + cmdclasses = {'install_data': install_data} + def fullsplit(path, result=None): """ Split a pathname into components (the opposite of os.path.join) in a @@ -20,7 +45,8 @@ def fullsplit(path, result=None): # Tell distutils to put the data_files in platform-specific installation # locations. See here for an explanation: -# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb +# http://groups.google.com/group/comp.lang.python/browse_thread/ +# thread/35ec7b2fed36eaec/2105ee4d9e8042cb for scheme in INSTALL_SCHEMES.values(): scheme['data'] = scheme['purelib'] @@ -49,6 +75,7 @@ setup( author='Stein Magnus Jodal', author_email='stein.magnus@jodal.no', packages=packages, + cmdclass=cmdclasses, data_files=data_files, scripts=['bin/mopidy'], url='http://www.mopidy.com/', From 8238e955b815794b5316a4d94f8a2087d9443d97 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 00:55:25 +0200 Subject: [PATCH 048/138] Bundle a Spotify appkey with the libspotify backend --- MANIFEST.in | 1 + docs/changes.rst | 2 ++ mopidy/backends/libspotify/session_manager.py | 2 +- mopidy/backends/libspotify/spotify_appkey.key | Bin 0 -> 321 bytes mopidy/settings.py | 5 ----- setup.py | 1 + 6 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 mopidy/backends/libspotify/spotify_appkey.key diff --git a/MANIFEST.in b/MANIFEST.in index 8a73b481..38819adb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ include LICENSE pylintrc *.rst *.txt +include mopidy/backends/libspotify/spotify_appkey.key recursive-include docs * prune docs/_build recursive-include tests *.py diff --git a/docs/changes.rst b/docs/changes.rst index 7b154915..c20b2ad1 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -23,6 +23,8 @@ Another great release. - Remove :mod:`mopidy.backends.despotify`, as Despotify is little maintained and the Libspotify backend is working much better. - :mod:`mopidy.backends.libspotify` is now the default backend. +- A Spotify application key is now bundled with the source. The + ``SPOTIFY_LIB_APPKEY`` setting is thus removed. - MPD frontend: - Relocate from :mod:`mopidy.mpd` to :mod:`mopidy.frontends.mpd`. diff --git a/mopidy/backends/libspotify/session_manager.py b/mopidy/backends/libspotify/session_manager.py index 2de6ae63..707423aa 100644 --- a/mopidy/backends/libspotify/session_manager.py +++ b/mopidy/backends/libspotify/session_manager.py @@ -13,7 +13,7 @@ logger = logging.getLogger('mopidy.backends.libspotify.session_manager') class LibspotifySessionManager(SpotifySessionManager, threading.Thread): cache_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) settings_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) - appkey_file = os.path.expanduser(settings.SPOTIFY_LIB_APPKEY) + appkey_file = os.path.join(os.path.dirname(__file__), 'spotify_appkey.key') user_agent = 'Mopidy %s' % get_version() def __init__(self, username, password, core_queue, output_queue): diff --git a/mopidy/backends/libspotify/spotify_appkey.key b/mopidy/backends/libspotify/spotify_appkey.key new file mode 100644 index 0000000000000000000000000000000000000000..1f840b962d9245820e73803ae5995650b4f84f62 GIT binary patch literal 321 zcmV-H0lxkL&xsG-pVlEz7LL?2e{+JtQpZk(M<9(;xguUY#VZNv&txxTh0nuFe(N{} zC?#&u)&58KeoT-KpSTN{8Wb)hzuj?jZNaN?^McImAMP|w&4GR8DyOK-#=V!cSw`&V5lyby`QwVzk}bWQ#Ui#m2fN)=wRSqK33~=D8OATMF|fdmT#G0B?yVov-+)u7w0gkTjyb{I{VGW`-;#R z$iCRsr@I8@9i#w7y@Y$>dnR3OOhWI%a!F~QeP*7Os+7-($V~m!LFZ(l=H!@+PtT&9 literal 0 HcmV?d00001 diff --git a/mopidy/settings.py b/mopidy/settings.py index 949b2e06..b17af913 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -160,11 +160,6 @@ MPD_SERVER_HOSTNAME = u'127.0.0.1' #: Default: 6600 MPD_SERVER_PORT = 6600 -#: Path to your libspotify application key. -#: -#: Used by :mod:`mopidy.backends.libspotify`. -SPOTIFY_LIB_APPKEY = u'~/.mopidy/spotify_appkey.key' - #: Path to the libspotify cache. #: #: Used by :mod:`mopidy.backends.libspotify`. diff --git a/setup.py b/setup.py index 76c38e4b..fabc8353 100644 --- a/setup.py +++ b/setup.py @@ -75,6 +75,7 @@ setup( author='Stein Magnus Jodal', author_email='stein.magnus@jodal.no', packages=packages, + package_data={'mopidy': ['backends/libspotify/spotify_appkey.key']}, cmdclass=cmdclasses, data_files=data_files, scripts=['bin/mopidy'], From f312d79261c12ab7fe7825bbcec97e4f308a67c1 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 01:21:16 +0200 Subject: [PATCH 049/138] implemented libspotify seek --- mopidy/backends/libspotify/__init__.py | 6 +++++- mopidy/frontends/mpd/protocol/playback.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index 974e52df..5e99385e 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -122,7 +122,11 @@ class LibspotifyPlaybackController(BasePlaybackController): return self._set_output_state('PLAYING') def _seek(self, time_position): - pass # TODO + self._set_output_state('READY') + seek_to_ms = int(time_position) * 1000 + result = self.backend.spotify.session.seek(seek_to_ms) + self._set_output_state('PLAYING') + return True def _stop(self): result = self._set_output_state('READY') diff --git a/mopidy/frontends/mpd/protocol/playback.py b/mopidy/frontends/mpd/protocol/playback.py index cf803c6d..7fe42ec8 100644 --- a/mopidy/frontends/mpd/protocol/playback.py +++ b/mopidy/frontends/mpd/protocol/playback.py @@ -293,7 +293,7 @@ def seek(frontend, songpos, seconds): Seeks to the position ``TIME`` (in seconds) of entry ``SONGPOS`` in the playlist. """ - raise MpdNotImplemented # TODO + return frontend.backend.playback._seek(seconds) @handle_pattern(r'^seekid "(?P\d+)" "(?P\d+)"$') def seekid(frontend, cpid, seconds): From 2d13485a213205840559c8c55f04bf382c6f97a6 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 01:45:05 +0200 Subject: [PATCH 050/138] update play time in base backend seek command --- mopidy/backends/base/playback.py | 4 +++- mopidy/backends/libspotify/__init__.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index 88617d83..2dafda14 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -373,7 +373,9 @@ class BasePlaybackController(object): self._seek(time_position) def _seek(self, time_position): - raise NotImplementedError + time_position_ms = int(time_position) * 1000 + self._play_time_started = (self._current_wall_time - time_position_ms) + self._play_time_accumulated = time_position_ms def stop(self): """Stop playing.""" diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index 5e99385e..2092b25b 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -126,7 +126,7 @@ class LibspotifyPlaybackController(BasePlaybackController): seek_to_ms = int(time_position) * 1000 result = self.backend.spotify.session.seek(seek_to_ms) self._set_output_state('PLAYING') - return True + super(LibspotifyPlaybackController, self)._seek(time_position) def _stop(self): result = self._set_output_state('READY') From 9c589352c8e4e626e7c33968abfeb3e1c5de4154 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 02:04:05 +0200 Subject: [PATCH 051/138] Call correct methods in seek and convert to milliseconds in frontend --- mopidy/backends/base/playback.py | 7 ++++--- mopidy/backends/libspotify/__init__.py | 4 +--- mopidy/frontends/mpd/protocol/playback.py | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index 2dafda14..2cf15629 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -370,12 +370,13 @@ class BasePlaybackController(object): self.next() return + self._play_time_started = self._current_wall_time + self._play_time_accumulated = time_position + self._seek(time_position) def _seek(self, time_position): - time_position_ms = int(time_position) * 1000 - self._play_time_started = (self._current_wall_time - time_position_ms) - self._play_time_accumulated = time_position_ms + raise NotImplementedError def stop(self): """Stop playing.""" diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index 2092b25b..04b5af66 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -123,10 +123,8 @@ class LibspotifyPlaybackController(BasePlaybackController): def _seek(self, time_position): self._set_output_state('READY') - seek_to_ms = int(time_position) * 1000 - result = self.backend.spotify.session.seek(seek_to_ms) + result = self.backend.spotify.session.seek(time_position) self._set_output_state('PLAYING') - super(LibspotifyPlaybackController, self)._seek(time_position) def _stop(self): result = self._set_output_state('READY') diff --git a/mopidy/frontends/mpd/protocol/playback.py b/mopidy/frontends/mpd/protocol/playback.py index 7fe42ec8..58cd02fd 100644 --- a/mopidy/frontends/mpd/protocol/playback.py +++ b/mopidy/frontends/mpd/protocol/playback.py @@ -293,7 +293,7 @@ def seek(frontend, songpos, seconds): Seeks to the position ``TIME`` (in seconds) of entry ``SONGPOS`` in the playlist. """ - return frontend.backend.playback._seek(seconds) + return frontend.backend.playback.seek(int(seconds) * 1000) @handle_pattern(r'^seekid "(?P\d+)" "(?P\d+)"$') def seekid(frontend, cpid, seconds): From ae48c2c4a500c31e6649e17472b07658b2199f0f Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 02:37:02 +0200 Subject: [PATCH 052/138] readded wrongly removed seek method --- mopidy/backends/libspotify/playback.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mopidy/backends/libspotify/playback.py b/mopidy/backends/libspotify/playback.py index 3ba91d5f..57c0134d 100644 --- a/mopidy/backends/libspotify/playback.py +++ b/mopidy/backends/libspotify/playback.py @@ -43,7 +43,9 @@ class LibspotifyPlaybackController(BasePlaybackController): return self._set_output_state('PLAYING') def _seek(self, time_position): - pass # TODO + self._set_output_state('READY') + result = self.backend.spotify.session.seek(time_position) + self._set_output_state('PLAYING') def _stop(self): result = self._set_output_state('READY') From dba0346a27eea072f23c031a6746329c45b5eaa7 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 02:41:13 +0200 Subject: [PATCH 053/138] docs: Remove mention of Spotify appkey, as it is bundled --- docs/installation/index.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/installation/index.rst b/docs/installation/index.rst index d5e76cce..abd185f1 100644 --- a/docs/installation/index.rst +++ b/docs/installation/index.rst @@ -99,11 +99,8 @@ username and password into the file, like this:: SPOTIFY_USERNAME = u'myusername' SPOTIFY_PASSWORD = u'mysecret' -Currently :mod:`mopidy.backends.libspotify` is the default -backend. Before you can use :mod:`mopidy.backends.libspotify`, you must copy -the Spotify application key to ``~/.mopidy/spotify_appkey.key``. - -If you want to use :mod:`mopidy.backends.local`, add the following setting:: +Currently :mod:`mopidy.backends.libspotify` is the default backend. If you want +to use :mod:`mopidy.backends.local`, add the following setting:: BACKENDS = (u'mopidy.backends.local.LocalBackend',) From d48dba0fe40220df9be3a2bfea90e8fc676ea539 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 02:41:34 +0200 Subject: [PATCH 054/138] Pass backend reference to the mixer constructor, just like for the other controllers --- mopidy/backends/base/__init__.py | 2 +- mopidy/mixers/__init__.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mopidy/backends/base/__init__.py b/mopidy/backends/base/__init__.py index 3a484865..abc14c4a 100644 --- a/mopidy/backends/base/__init__.py +++ b/mopidy/backends/base/__init__.py @@ -36,7 +36,7 @@ class BaseBackend(object): if mixer is not None: self.mixer = mixer else: - self.mixer = get_class(settings.MIXER)() + self.mixer = get_class(settings.MIXER)(self) #: A :class:`multiprocessing.Queue` which can be used by e.g. library #: callbacks executing in other threads to send messages to the core diff --git a/mopidy/mixers/__init__.py b/mopidy/mixers/__init__.py index 31e5ae8e..3ef1b645 100644 --- a/mopidy/mixers/__init__.py +++ b/mopidy/mixers/__init__.py @@ -1,6 +1,11 @@ class BaseMixer(object): - def __init__(self, *args, **kwargs): - pass + """ + :param backend: a backend instance + :type mixer: :class:`mopidy.backends.base.BaseBackend` + """ + + def __init__(self, backend, *args, **kwargs): + self.backend = backend @property def volume(self): From b87fced87e867653909b48faea6c6a06a50aa611 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 02:44:29 +0200 Subject: [PATCH 055/138] Fix Pylint warnings --- mopidy/outputs/gstreamer.py | 3 ++- mopidy/process.py | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index b81fbd0f..58d0bcf7 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -39,7 +39,8 @@ class GStreamerProcess(BaseProcess): http://jameswestby.net/weblog/tech/14-caution-python-multiprocessing-and-glib-dont-mix.html. """ - pipeline_description = 'appsrc name=data ! volume name=volume ! autoaudiosink name=sink' + pipeline_description = \ + 'appsrc name=data ! volume name=volume ! autoaudiosink name=sink' def __init__(self, core_queue, output_queue): super(GStreamerProcess, self).__init__() diff --git a/mopidy/process.py b/mopidy/process.py index b1cdc8af..53b6fbb5 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -4,8 +4,7 @@ from multiprocessing.reduction import reduce_connection import pickle import sys -from mopidy import settings, SettingsError -from mopidy.utils import get_class +from mopidy import SettingsError logger = logging.getLogger('mopidy.process') From a4d231709e700b15fe7f11aab22062dec6b85cd2 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 02:47:41 +0200 Subject: [PATCH 056/138] Add new GStreamer-based software mixer and make it the default on all platforms --- docs/api/mixers.rst | 10 ++++++++++ docs/changes.rst | 2 ++ mopidy/mixers/gstreamer.py | 14 -------------- mopidy/mixers/gstreamer_software.py | 25 +++++++++++++++++++++++++ mopidy/outputs/gstreamer.py | 6 ++++++ mopidy/settings.py | 18 +++--------------- 6 files changed, 46 insertions(+), 29 deletions(-) delete mode 100644 mopidy/mixers/gstreamer.py create mode 100644 mopidy/mixers/gstreamer_software.py diff --git a/docs/api/mixers.rst b/docs/api/mixers.rst index 70ac450a..91c2e7aa 100644 --- a/docs/api/mixers.rst +++ b/docs/api/mixers.rst @@ -67,6 +67,16 @@ methods as described below. .. inheritance-diagram:: mopidy.mixers.dummy +:mod:`mopidy.mixers.gstreamer_software` -- Software mixer for all platforms +=========================================================================== + +.. automodule:: mopidy.mixers.gstreamer_software + :synopsis: Software mixer for all platforms + :members: + +.. inheritance-diagram:: mopidy.mixers.gstreamer_software + + :mod:`mopidy.mixers.osa` -- Osa mixer for OS X ============================================== diff --git a/docs/changes.rst b/docs/changes.rst index c20b2ad1..5b08ae13 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -25,6 +25,8 @@ Another great release. - :mod:`mopidy.backends.libspotify` is now the default backend. - A Spotify application key is now bundled with the source. The ``SPOTIFY_LIB_APPKEY`` setting is thus removed. +- Added new :mod:`mopidy.mixers.GStreamerSoftwareMixer` which now is the + default mixer on all platforms. - MPD frontend: - Relocate from :mod:`mopidy.mpd` to :mod:`mopidy.frontends.mpd`. diff --git a/mopidy/mixers/gstreamer.py b/mopidy/mixers/gstreamer.py deleted file mode 100644 index 3be94db0..00000000 --- a/mopidy/mixers/gstreamer.py +++ /dev/null @@ -1,14 +0,0 @@ -from mopidy.mixers import BaseMixer - -class GStreamerMixer(BaseMixer): - """Mixer which uses GStreamer to control volume.""" - - def __init__(self, *args, **kwargs): - super(GStreamerMixer, self).__init__(*args, **kwargs) - - def _get_volume(self): - pass # TODO Get volume from GStreamerProcess - - def _set_volume(self, volume): - pass # TODO Send volume to GStreamerProcess - diff --git a/mopidy/mixers/gstreamer_software.py b/mopidy/mixers/gstreamer_software.py new file mode 100644 index 00000000..2910ef72 --- /dev/null +++ b/mopidy/mixers/gstreamer_software.py @@ -0,0 +1,25 @@ +import multiprocessing + +from mopidy.mixers import BaseMixer +from mopidy.process import pickle_connection + +class GStreamerSoftwareMixer(BaseMixer): + """Mixer which uses GStreamer to control volume in software.""" + + def __init__(self, *args, **kwargs): + super(GStreamerSoftwareMixer, self).__init__(*args, **kwargs) + + def _get_volume(self): + my_end, other_end = multiprocessing.Pipe() + self.backend.output_queue.put({ + 'command': 'get_volume', + 'reply_to': pickle_connection(other_end), + }) + my_end.poll(None) + return my_end.recv() + + def _set_volume(self, volume): + self.backend.output_queue.put({ + 'command': 'set_volume', + 'volume': volume, + }) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 58d0bcf7..4ea1af3a 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -93,6 +93,12 @@ class GStreamerProcess(BaseProcess): response = self.set_state(message['state']) connection = unpickle_connection(message['reply_to']) connection.send(response) + elif message['command'] == 'get_volume': + volume = self.get_volume() + connection = unpickle_connection(message['reply_to']) + connection.send(volume) + elif message['command'] == 'set_volume': + self.set_volume(message['volume']) else: logger.warning(u'Cannot handle message: %s', message) diff --git a/mopidy/settings.py b/mopidy/settings.py index b17af913..232adda8 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -82,22 +82,10 @@ LOCAL_TAG_CACHE = u'~/.mopidy/tag_cache' #: Sound mixer to use. See :mod:`mopidy.mixers` for all available mixers. #: -#: Default on Linux:: +#: Default:: #: -#: MIXER = u'mopidy.mixers.alsa.AlsaMixer' -#: -#: Default on OS X:: -#: -#: MIXER = u'mopidy.mixers.osa.OsaMixer' -#: -#: Default on other operating systems:: -#: -#: MIXER = u'mopidy.mixers.dummy.DummyMixer' -MIXER = u'mopidy.mixers.dummy.DummyMixer' -if sys.platform == 'linux2': - MIXER = u'mopidy.mixers.alsa.AlsaMixer' -elif sys.platform == 'darwin': - MIXER = u'mopidy.mixers.osa.OsaMixer' +#: MIXER = u'mopidy.mixers.gstreamer_software.GStreamerSoftwareMixer' +MIXER = u'mopidy.mixers.gstreamer_software.GStreamerSoftwareMixer' #: ALSA mixer only. What mixer control to use. If set to :class:`False`, first #: ``Master`` and then ``PCM`` will be tried. From 1db7b84fe6ab0996e961173acd92b1391660effe Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 03:16:14 +0200 Subject: [PATCH 057/138] Some cleanup of the changelog for the upcoming release --- docs/changes.rst | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 5b08ae13..411d2547 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -8,21 +8,28 @@ This change log is used to track all major changes to Mopidy. 0.1.0a4 (in development) ======================== -Another great release. +The greatest release ever! We present to you important improvements in search +functionality, working track position seeking, no known stability issues, and +greatly improved MPD client support. -**Changes** +**Important changes** - License changed from GPLv2 to Apache License, version 2.0. - GStreamer is now a required dependency. +- :mod:`mopidy.backends.libspotify` is now the default backend. + :mod:`mopidy.backends.despotify` is no longer available. This means that you + need to install the :doc:`dependencies for libspotify + `. +- If you used :mod:`mopidy.backends.libspotify` previously, pyspotify must be + updated when updating to this release, to get working seek functionality. +- The settings ``SERVER_HOSTNAME`` and ``SERVER_PORT`` has been renamed to + ``MPD_SERVER_HOSTNAME`` and ``MPD_SERVER_PORT``. + +**Changes** + - Exit early if not Python >= 2.6, < 3. - Include Sphinx scripts for building docs, pylintrc, tests and test data in the packages created by ``setup.py`` for i.e. PyPI. -- Rename :mod:`mopidy.backends.gstreamer` to :mod:`mopidy.backends.local`. -- Changed ``SERVER_HOSTNAME`` and ``SERVER_PORT`` settings to - ``MPD_SERVER_HOSTNAME`` and ``MPD_SERVER_PORT``. -- Remove :mod:`mopidy.backends.despotify`, as Despotify is little maintained - and the Libspotify backend is working much better. -- :mod:`mopidy.backends.libspotify` is now the default backend. - A Spotify application key is now bundled with the source. The ``SPOTIFY_LIB_APPKEY`` setting is thus removed. - Added new :mod:`mopidy.mixers.GStreamerSoftwareMixer` which now is the @@ -40,6 +47,12 @@ Another great release. - Fixed delete current playing track from playlist, which crashed several clients. +- Backends: + + - Rename :mod:`mopidy.backends.gstreamer` to :mod:`mopidy.backends.local`. + - Remove :mod:`mopidy.backends.despotify`, as Despotify is little maintained + and the Libspotify backend is working much better. + - Backend API: - Relocate from :mod:`mopidy.backends` to :mod:`mopidy.backends.base`. From 250168ebba0bab0f8ef9fe8158058da328485592 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 03:29:34 +0200 Subject: [PATCH 058/138] Implement pause on the libspotify backend by seeking to the resume position --- mopidy/backends/libspotify/playback.py | 5 +++-- mopidy/outputs/gstreamer.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mopidy/backends/libspotify/playback.py b/mopidy/backends/libspotify/playback.py index 57c0134d..60a5d355 100644 --- a/mopidy/backends/libspotify/playback.py +++ b/mopidy/backends/libspotify/playback.py @@ -40,12 +40,13 @@ class LibspotifyPlaybackController(BasePlaybackController): return False def _resume(self): - return self._set_output_state('PLAYING') + return self._seek(self.time_position) def _seek(self, time_position): self._set_output_state('READY') - result = self.backend.spotify.session.seek(time_position) + self.backend.spotify.session.seek(time_position) self._set_output_state('PLAYING') + return True def _stop(self): result = self._set_output_state('READY') diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 4ea1af3a..d2c0af94 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -156,6 +156,7 @@ class GStreamerProcess(BaseProcess): :type state_name: string :rtype: :class:`True` or :class:`False` """ + # XXX Setting state to PLAYING often returns False even if it works result = self.gst_pipeline.set_state( getattr(gst, 'STATE_' + state_name)) if result == gst.STATE_CHANGE_SUCCESS: From da2a44fd177f47984708f1cb3673cd318f0a5612 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 04:05:43 +0200 Subject: [PATCH 059/138] Fix 400 or so tests broken by changing the mixer constructor --- mopidy/backends/base/__init__.py | 14 +++++++------- tests/backends/base.py | 8 ++++---- tests/backends/local_test.py | 2 +- tests/frontends/mpd/audio_output_test.py | 3 +-- tests/frontends/mpd/command_list_test.py | 3 +-- tests/frontends/mpd/connection_test.py | 3 +-- tests/frontends/mpd/current_playlist_test.py | 3 +-- tests/frontends/mpd/music_db_test.py | 3 +-- tests/frontends/mpd/playback_test.py | 6 ++---- tests/frontends/mpd/reflection_test.py | 3 +-- tests/frontends/mpd/request_handler_test.py | 3 +-- tests/frontends/mpd/status_test.py | 3 +-- tests/frontends/mpd/stickers_test.py | 3 +-- tests/frontends/mpd/stored_playlists_test.py | 3 +-- tests/mixers/base_test.py | 2 +- tests/mixers/denon_test.py | 2 +- 16 files changed, 26 insertions(+), 38 deletions(-) diff --git a/mopidy/backends/base/__init__.py b/mopidy/backends/base/__init__.py index abc14c4a..7a178160 100644 --- a/mopidy/backends/base/__init__.py +++ b/mopidy/backends/base/__init__.py @@ -25,18 +25,18 @@ class BaseBackend(object): :type core_queue: :class:`multiprocessing.Queue` :param output_queue: a queue for sending messages to the output process :type output_queue: :class:`multiprocessing.Queue` - :param mixer: either a mixer instance, or :class:`None` to use the mixer + :param mixer_class: either a mixer class, or :class:`None` to use the mixer defined in settings - :type mixer: :class:`mopidy.mixers.BaseMixer` or :class:`None` + :type mixer_class: a subclass of :class:`mopidy.mixers.BaseMixer` or + :class:`None` """ - def __init__(self, core_queue=None, output_queue=None, mixer=None): + def __init__(self, core_queue=None, output_queue=None, mixer_class=None): self.core_queue = core_queue self.output_queue = output_queue - if mixer is not None: - self.mixer = mixer - else: - self.mixer = get_class(settings.MIXER)(self) + if mixer_class is None: + mixer_class = get_class(settings.MIXER) + self.mixer = mixer_class(self) #: A :class:`multiprocessing.Queue` which can be used by e.g. library #: callbacks executing in other threads to send messages to the core diff --git a/tests/backends/base.py b/tests/backends/base.py index 416c1799..64ca7797 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -32,7 +32,7 @@ class BaseCurrentPlaylistControllerTest(object): backend_class = None def setUp(self): - self.backend = self.backend_class(mixer=DummyMixer()) + self.backend = self.backend_class(mixer_class=DummyMixer) self.controller = self.backend.current_playlist self.playback = self.backend.playback @@ -281,7 +281,7 @@ class BasePlaybackControllerTest(object): backend_class = None def setUp(self): - self.backend = self.backend_class(mixer=DummyMixer()) + self.backend = self.backend_class(mixer_class=DummyMixer) self.playback = self.backend.playback self.current_playlist = self.backend.current_playlist @@ -933,7 +933,7 @@ class BaseStoredPlaylistsControllerTest(object): settings.LOCAL_TAG_CACHE = data_folder('library_tag_cache') settings.LOCAL_MUSIC_FOLDER = data_folder('') - self.backend = self.backend_class(mixer=DummyMixer()) + self.backend = self.backend_class(mixer_class=DummyMixer) self.stored = self.backend.stored_playlists def tearDown(self): @@ -1055,7 +1055,7 @@ class BaseLibraryControllerTest(object): Track()] def setUp(self): - self.backend = self.backend_class(mixer=DummyMixer()) + self.backend = self.backend_class(mixer_class=DummyMixer) self.library = self.backend.library def tearDown(self): diff --git a/tests/backends/local_test.py b/tests/backends/local_test.py index 63282bde..23a12bca 100644 --- a/tests/backends/local_test.py +++ b/tests/backends/local_test.py @@ -116,7 +116,7 @@ class LocalStoredPlaylistsControllerTest(BaseStoredPlaylistsControllerTest, self.stored.save(playlist) self.backend.destroy() - self.backend = self.backend_class(mixer=DummyMixer()) + self.backend = self.backend_class(mixer_class=DummyMixer) self.stored = self.backend.stored_playlists self.assert_(self.stored.playlists) diff --git a/tests/frontends/mpd/audio_output_test.py b/tests/frontends/mpd/audio_output_test.py index c752f40e..24201341 100644 --- a/tests/frontends/mpd/audio_output_test.py +++ b/tests/frontends/mpd/audio_output_test.py @@ -6,8 +6,7 @@ from mopidy.mixers.dummy import DummyMixer class AudioOutputHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_enableoutput(self): diff --git a/tests/frontends/mpd/command_list_test.py b/tests/frontends/mpd/command_list_test.py index eed92a24..683a1013 100644 --- a/tests/frontends/mpd/command_list_test.py +++ b/tests/frontends/mpd/command_list_test.py @@ -6,8 +6,7 @@ from mopidy.mixers.dummy import DummyMixer class CommandListsTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_command_list_begin(self): diff --git a/tests/frontends/mpd/connection_test.py b/tests/frontends/mpd/connection_test.py index 83133050..341e630c 100644 --- a/tests/frontends/mpd/connection_test.py +++ b/tests/frontends/mpd/connection_test.py @@ -6,8 +6,7 @@ from mopidy.mixers.dummy import DummyMixer class ConnectionHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_close(self): diff --git a/tests/frontends/mpd/current_playlist_test.py b/tests/frontends/mpd/current_playlist_test.py index 0d639f89..e42077df 100644 --- a/tests/frontends/mpd/current_playlist_test.py +++ b/tests/frontends/mpd/current_playlist_test.py @@ -7,8 +7,7 @@ from mopidy.models import Track class CurrentPlaylistHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_add(self): diff --git a/tests/frontends/mpd/music_db_test.py b/tests/frontends/mpd/music_db_test.py index 62915a58..fc8f980a 100644 --- a/tests/frontends/mpd/music_db_test.py +++ b/tests/frontends/mpd/music_db_test.py @@ -6,8 +6,7 @@ from mopidy.mixers.dummy import DummyMixer class MusicDatabaseHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_count(self): diff --git a/tests/frontends/mpd/playback_test.py b/tests/frontends/mpd/playback_test.py index 3cf0a11f..1cc3bc00 100644 --- a/tests/frontends/mpd/playback_test.py +++ b/tests/frontends/mpd/playback_test.py @@ -7,8 +7,7 @@ from mopidy.models import Track class PlaybackOptionsHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_consume_off(self): @@ -167,8 +166,7 @@ class PlaybackOptionsHandlerTest(unittest.TestCase): class PlaybackControlHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_next(self): diff --git a/tests/frontends/mpd/reflection_test.py b/tests/frontends/mpd/reflection_test.py index 11bd5ba9..5491946c 100644 --- a/tests/frontends/mpd/reflection_test.py +++ b/tests/frontends/mpd/reflection_test.py @@ -6,8 +6,7 @@ from mopidy.mixers.dummy import DummyMixer class ReflectionHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_commands_returns_list_of_all_commands(self): diff --git a/tests/frontends/mpd/request_handler_test.py b/tests/frontends/mpd/request_handler_test.py index beea4bc3..ac8bd7e9 100644 --- a/tests/frontends/mpd/request_handler_test.py +++ b/tests/frontends/mpd/request_handler_test.py @@ -6,8 +6,7 @@ from mopidy.mixers.dummy import DummyMixer class RequestHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_register_same_pattern_twice_fails(self): diff --git a/tests/frontends/mpd/status_test.py b/tests/frontends/mpd/status_test.py index 8be549d6..907788f5 100644 --- a/tests/frontends/mpd/status_test.py +++ b/tests/frontends/mpd/status_test.py @@ -7,8 +7,7 @@ from mopidy.models import Track class StatusHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_clearerror(self): diff --git a/tests/frontends/mpd/stickers_test.py b/tests/frontends/mpd/stickers_test.py index 83bbdd04..401eaf57 100644 --- a/tests/frontends/mpd/stickers_test.py +++ b/tests/frontends/mpd/stickers_test.py @@ -6,8 +6,7 @@ from mopidy.mixers.dummy import DummyMixer class StickersHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_sticker_get(self): diff --git a/tests/frontends/mpd/stored_playlists_test.py b/tests/frontends/mpd/stored_playlists_test.py index 179e0802..9babc670 100644 --- a/tests/frontends/mpd/stored_playlists_test.py +++ b/tests/frontends/mpd/stored_playlists_test.py @@ -10,8 +10,7 @@ from tests import SkipTest class StoredPlaylistsHandlerTest(unittest.TestCase): def setUp(self): - self.m = DummyMixer() - self.b = DummyBackend(mixer=self.m) + self.b = DummyBackend(mixer_class=DummyMixer) self.h = frontend.MpdFrontend(backend=self.b) def test_listplaylist(self): diff --git a/tests/mixers/base_test.py b/tests/mixers/base_test.py index 0659a12e..292edcda 100644 --- a/tests/mixers/base_test.py +++ b/tests/mixers/base_test.py @@ -12,7 +12,7 @@ class BaseMixerTest(unittest.TestCase): INITIAL = None def setUp(self): - self.mixer = DummyMixer() + self.mixer = DummyMixer(None) def test_initial_volume(self): self.assertEqual(self.mixer.volume, self.INITIAL) diff --git a/tests/mixers/denon_test.py b/tests/mixers/denon_test.py index bf387418..e0f59705 100644 --- a/tests/mixers/denon_test.py +++ b/tests/mixers/denon_test.py @@ -29,7 +29,7 @@ class DenonMixerTest(BaseMixerTest): def setUp(self): self.device = DenonMixerDeviceMock() - self.mixer = DenonMixer(device=self.device) + self.mixer = DenonMixer(None, device=self.device) def test_reopen_device(self): self.device._open = False From abcc9c1007ae3110264d94c7f82e540bdfd907b0 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 14:10:44 +0200 Subject: [PATCH 060/138] MPD: Improve seek impl and add seekid impl. Add tests which fails. --- docs/changes.rst | 1 + mopidy/frontends/mpd/protocol/playback.py | 6 +++++- tests/frontends/mpd/playback_test.py | 10 ++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 411d2547..a0a02ce7 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -46,6 +46,7 @@ greatly improved MPD client support. ``single`` without quotes to work better with BitMPC. - Fixed delete current playing track from playlist, which crashed several clients. + - Implement ``seek`` and ``seekid``. - Backends: diff --git a/mopidy/frontends/mpd/protocol/playback.py b/mopidy/frontends/mpd/protocol/playback.py index 58cd02fd..bfff275e 100644 --- a/mopidy/frontends/mpd/protocol/playback.py +++ b/mopidy/frontends/mpd/protocol/playback.py @@ -293,6 +293,8 @@ def seek(frontend, songpos, seconds): Seeks to the position ``TIME`` (in seconds) of entry ``SONGPOS`` in the playlist. """ + if frontend.backend.playback.current_playlist_position != songpos: + playpos(frontend, songpos) return frontend.backend.playback.seek(int(seconds) * 1000) @handle_pattern(r'^seekid "(?P\d+)" "(?P\d+)"$') @@ -304,7 +306,9 @@ def seekid(frontend, cpid, seconds): Seeks to the position ``TIME`` (in seconds) of song ``SONGID``. """ - raise MpdNotImplemented # TODO + if frontend.backend.playback.current_cpid != cpid: + playid(frontend, cpid) + return frontend.backend.playback.seek(int(seconds) * 1000) @handle_pattern(r'^setvol "(?P[-+]*\d+)"$') def setvol(frontend, volume): diff --git a/tests/frontends/mpd/playback_test.py b/tests/frontends/mpd/playback_test.py index 1cc3bc00..42525d90 100644 --- a/tests/frontends/mpd/playback_test.py +++ b/tests/frontends/mpd/playback_test.py @@ -271,12 +271,18 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_seek(self): + self.b.current_playlist.load([Track()]) + self.h.handle_request(u'seek "0"') result = self.h.handle_request(u'seek "0" "30"') - self.assert_(u'ACK [0@0] {} Not implemented' in result) + self.assert_(u'OK' in result) + self.assert_(self.b.playback.time_position > 30000) def test_seekid(self): + self.b.current_playlist.load([Track()]) result = self.h.handle_request(u'seekid "0" "30"') - self.assert_(u'ACK [0@0] {} Not implemented' in result) + self.assert_(u'OK' in result) + self.assert_(self.b.playback.time_position > 30000) + def test_stop(self): result = self.h.handle_request(u'stop') From 5d9fd5b625b7e5a616adfb22ebea51e126e11e08 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 14:42:44 +0200 Subject: [PATCH 061/138] MPD: Update tests and fix 'playlistfind' --- docs/changes.rst | 2 ++ mopidy/frontends/mpd/protocol/current_playlist.py | 5 ++++- tests/frontends/mpd/current_playlist_test.py | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 4ee8cf7f..d3ed3db2 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -47,6 +47,8 @@ greatly improved MPD client support. - Fixed delete current playing track from playlist, which crashed several clients. - Implement ``seek`` and ``seekid``. + - Fix ``playlistfind`` output so the correct song is played when playing + songs directly from search results in GMPC. - Backends: diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index 30acbe89..c10d1dad 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -173,7 +173,10 @@ def playlistfind(frontend, tag, needle): if tag == 'filename': try: cp_track = frontend.backend.current_playlist.get(uri=needle) - return cp_track[1].mpd_format() + (cpid, track) = cp_track + position = frontend.backend.current_playlist.cp_tracks.index( + cp_track) + return track.mpd_format(cpid=cpid, position=position) except LookupError: return None raise MpdNotImplemented # TODO diff --git a/tests/frontends/mpd/current_playlist_test.py b/tests/frontends/mpd/current_playlist_test.py index e42077df..6b5c822e 100644 --- a/tests/frontends/mpd/current_playlist_test.py +++ b/tests/frontends/mpd/current_playlist_test.py @@ -195,14 +195,16 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): result = self.h.handle_request(u'playlistfind "tag" "needle"') self.assert_(u'ACK [0@0] {} Not implemented' in result) - def test_playlistfind_by_filename(self): + def test_playlistfind_by_filename_not_in_current_playlist(self): result = self.h.handle_request( u'playlistfind "filename" "file:///dev/null"') + self.assertEqual(len(result), 1) self.assert_(u'OK' in result) def test_playlistfind_by_filename_without_quotes(self): result = self.h.handle_request( u'playlistfind filename "file:///dev/null"') + self.assertEqual(len(result), 1) self.assert_(u'OK' in result) def test_playlistfind_by_filename_in_current_playlist(self): @@ -211,6 +213,8 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): result = self.h.handle_request( u'playlistfind filename "file:///exists"') self.assert_(u'file: file:///exists' in result) + self.assert_(u'Id: 1' in result) + self.assert_(u'Pos: 0' in result) self.assert_(u'OK' in result) def test_playlistid_without_songid(self): From 210447debbcd88b728bf1c80f5acbd1434963ff2 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 14 Aug 2010 14:56:57 +0200 Subject: [PATCH 062/138] Add destroy method to GStreamerOutput --- mopidy/outputs/gstreamer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index d2c0af94..a28329f7 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -20,8 +20,11 @@ class GStreamerOutput(object): """ def __init__(self, core_queue, output_queue): - process = GStreamerProcess(core_queue, output_queue) - process.start() + self.process = GStreamerProcess(core_queue, output_queue) + self.process.start() + + def destroy(self): + self.process.terminate() class GStreamerMessagesThread(threading.Thread): def run(self): From dc27434df9e66e530247fd47270729618be65a8d Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 14 Aug 2010 15:21:01 +0200 Subject: [PATCH 063/138] Fix set_state method in GStreamerOutput --- mopidy/outputs/gstreamer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index a28329f7..5e64378f 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -159,10 +159,10 @@ class GStreamerProcess(BaseProcess): :type state_name: string :rtype: :class:`True` or :class:`False` """ - # XXX Setting state to PLAYING often returns False even if it works - result = self.gst_pipeline.set_state( - getattr(gst, 'STATE_' + state_name)) - if result == gst.STATE_CHANGE_SUCCESS: + state = getattr(gst, 'STATE_' + state_name) + self.gst_pipeline.set_state(state) + new_state = self.gst_pipeline.get_state()[1] + if new_state == state: logger.debug('Setting GStreamer state to %s: OK', state_name) return True else: From e2bdec5a4b3a83168355f51106264067f747eb11 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 14 Aug 2010 15:23:27 +0200 Subject: [PATCH 064/138] Start adding gstreamer output tests --- mopidy/outputs/gstreamer.py | 11 +++++------ tests/outputs/__init__.py | 0 tests/outputs/gstreamer_test.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 tests/outputs/__init__.py create mode 100644 tests/outputs/gstreamer_test.py diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 5e64378f..19f56c59 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -43,7 +43,7 @@ class GStreamerProcess(BaseProcess): """ pipeline_description = \ - 'appsrc name=data ! volume name=volume ! autoaudiosink name=sink' + 'uridecodebin name=uri ! volume name=volume ! autoaudiosink name=sink' def __init__(self, core_queue, output_queue): super(GStreamerProcess, self).__init__() @@ -52,7 +52,7 @@ class GStreamerProcess(BaseProcess): self.gst_pipeline = None self.gst_bus = None self.gst_bus_id = None - self.gst_uri_src = None + self.gst_uri_bin = None self.gst_data_src = None self.gst_volume = None self.gst_sink = None @@ -72,7 +72,7 @@ class GStreamerProcess(BaseProcess): messages_thread.start() self.gst_pipeline = gst.parse_launch(self.pipeline_description) - self.gst_data_src = self.gst_pipeline.get_by_name('data') + self.gst_uri_bin = self.gst_pipeline.get_by_name('uri') self.gst_volume = self.gst_pipeline.get_by_name('volume') self.gst_sink = self.gst_pipeline.get_by_name('sink') @@ -121,9 +121,8 @@ class GStreamerProcess(BaseProcess): def play_uri(self, uri): """Play audio at URI""" self.set_state('READY') - self.gst_uri_src.set_property('uri', uri) - self.set_state('PLAYING') - # TODO Return status + self.gst_uri_bin.set_property('uri', uri) + return self.set_state('PLAYING') def deliver_data(self, caps_string, data): """Deliver audio data to be played""" diff --git a/tests/outputs/__init__.py b/tests/outputs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/outputs/gstreamer_test.py b/tests/outputs/gstreamer_test.py new file mode 100644 index 00000000..a75eef0d --- /dev/null +++ b/tests/outputs/gstreamer_test.py @@ -0,0 +1,30 @@ +import multiprocessing +import unittest + +from mopidy.utils import path_to_uri +from mopidy.process import pickle_connection +from mopidy.outputs.gstreamer import GStreamerOutput + +from tests import data_folder + +class GStreamerOutputTest(unittest.TestCase): + def setUp(self): + self.song_uri = path_to_uri(data_folder('song1.wav')) + self.output_queue = multiprocessing.Queue() + self.core_queue = multiprocessing.Queue() + self.output = GStreamerOutput(self.core_queue, self.output_queue) + + def tearDown(self): + self.output.destroy() + + def send(self, message): + (my_end, other_end) = multiprocessing.Pipe() + message.update({'reply_to': pickle_connection(other_end)}) + self.output_queue.put(message) + my_end.poll(None) + return my_end.recv() + + def test_play_uri_existing_file_returns_true(self): + message = {'command': 'play_uri', 'uri': self.song_uri} + self.assertEqual(True, self.send(message)) + From 419de169c6d1616aa5596383153eb8430ea218be Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 14 Aug 2010 15:26:57 +0200 Subject: [PATCH 065/138] Add test_play_uri_non_existing_file for output --- tests/outputs/gstreamer_test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/outputs/gstreamer_test.py b/tests/outputs/gstreamer_test.py index a75eef0d..7cb95279 100644 --- a/tests/outputs/gstreamer_test.py +++ b/tests/outputs/gstreamer_test.py @@ -24,7 +24,11 @@ class GStreamerOutputTest(unittest.TestCase): my_end.poll(None) return my_end.recv() - def test_play_uri_existing_file_returns_true(self): + def test_play_uri_existing_file(self): message = {'command': 'play_uri', 'uri': self.song_uri} self.assertEqual(True, self.send(message)) + + def test_play_uri_non_existing_file(self): + message = {'command': 'play_uri', 'uri': self.song_uri + 'bogus'} + self.assertEqual(False, self.send(message)) From 8dfa55b667b17751738acc6eb0b63b067de881ea Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 15:34:53 +0200 Subject: [PATCH 066/138] docs: Add step on removing the build/ dir of pyspotify to rebuild the C code --- docs/installation/libspotify.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/installation/libspotify.rst b/docs/installation/libspotify.rst index 635c0495..911bf39e 100644 --- a/docs/installation/libspotify.rst +++ b/docs/installation/libspotify.rst @@ -63,4 +63,12 @@ Check out the pyspotify code, and install it:: git clone git://github.com/jodal/pyspotify.git cd pyspotify/pyspotify/ + sudo rm -rf build/ # If you are upgrading pyspotify sudo python setup.py install + +.. note:: + + The ``sudo rm -rf build/`` step is needed if you are upgrading pyspotify. + Simply running ``python setup.py clean`` will *not* clean out the C parts + of the ``build/`` directory, and you will thus not get any changes to the C + code included in your installation. From 7ed8563347e70ba6bb0fadc76d305db2750c81e5 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 14 Aug 2010 15:36:47 +0200 Subject: [PATCH 067/138] Attempt to setup both appsrc and uridecodebin in same pipeline --- mopidy/outputs/gstreamer.py | 10 ++++------ tests/outputs/gstreamer_test.py | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 19f56c59..e6e9fcea 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -42,8 +42,7 @@ class GStreamerProcess(BaseProcess): http://jameswestby.net/weblog/tech/14-caution-python-multiprocessing-and-glib-dont-mix.html. """ - pipeline_description = \ - 'uridecodebin name=uri ! volume name=volume ! autoaudiosink name=sink' + pipeline_description = '(appsrc uridecodebin) ! volume ! autoaudiosink' def __init__(self, core_queue, output_queue): super(GStreamerProcess, self).__init__() @@ -55,7 +54,6 @@ class GStreamerProcess(BaseProcess): self.gst_uri_bin = None self.gst_data_src = None self.gst_volume = None - self.gst_sink = None def run_inside_try(self): self.setup() @@ -72,9 +70,9 @@ class GStreamerProcess(BaseProcess): messages_thread.start() self.gst_pipeline = gst.parse_launch(self.pipeline_description) - self.gst_uri_bin = self.gst_pipeline.get_by_name('uri') - self.gst_volume = self.gst_pipeline.get_by_name('volume') - self.gst_sink = self.gst_pipeline.get_by_name('sink') + self.gst_data_src = self.gst_pipeline.get_by_name('appsrc0') + self.gst_uri_bin = self.gst_pipeline.get_by_name('uridecodebin0') + self.gst_volume = self.gst_pipeline.get_by_name('volume0') # Setup bus and message processor self.gst_bus = self.gst_pipeline.get_bus() diff --git a/tests/outputs/gstreamer_test.py b/tests/outputs/gstreamer_test.py index 7cb95279..9f7764e1 100644 --- a/tests/outputs/gstreamer_test.py +++ b/tests/outputs/gstreamer_test.py @@ -31,4 +31,6 @@ class GStreamerOutputTest(unittest.TestCase): def test_play_uri_non_existing_file(self): message = {'command': 'play_uri', 'uri': self.song_uri + 'bogus'} self.assertEqual(False, self.send(message)) + + From fe9ad74e1b12825d999bd2631b3230bbdeb060b5 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 15:44:05 +0200 Subject: [PATCH 068/138] fixed test_seek and test_seekid --- tests/frontends/mpd/playback_test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/frontends/mpd/playback_test.py b/tests/frontends/mpd/playback_test.py index 42525d90..60e96d88 100644 --- a/tests/frontends/mpd/playback_test.py +++ b/tests/frontends/mpd/playback_test.py @@ -271,17 +271,17 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_seek(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.load([Track(length=40000)]) self.h.handle_request(u'seek "0"') result = self.h.handle_request(u'seek "0" "30"') self.assert_(u'OK' in result) - self.assert_(self.b.playback.time_position > 30000) + self.assert_(self.b.playback.time_position >= 30000) def test_seekid(self): - self.b.current_playlist.load([Track()]) - result = self.h.handle_request(u'seekid "0" "30"') + self.b.current_playlist.load([Track(length=40000)]) + result = self.h.handle_request(u'seekid "1" "30"') self.assert_(u'OK' in result) - self.assert_(self.b.playback.time_position > 30000) + self.assert_(self.b.playback.time_position >= 30000) def test_stop(self): From 7db0bd25fd6c9495f9ad5d69c975634ed7ffda37 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 14 Aug 2010 15:56:00 +0200 Subject: [PATCH 069/138] Add basic volume tests for gstreamer output --- tests/outputs/gstreamer_test.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/outputs/gstreamer_test.py b/tests/outputs/gstreamer_test.py index 9f7764e1..8f4f83bc 100644 --- a/tests/outputs/gstreamer_test.py +++ b/tests/outputs/gstreamer_test.py @@ -17,20 +17,36 @@ class GStreamerOutputTest(unittest.TestCase): def tearDown(self): self.output.destroy() - def send(self, message): + def send_recv(self, message): (my_end, other_end) = multiprocessing.Pipe() message.update({'reply_to': pickle_connection(other_end)}) self.output_queue.put(message) my_end.poll(None) return my_end.recv() + def send(self, message): + self.output_queue.put(message) + def test_play_uri_existing_file(self): message = {'command': 'play_uri', 'uri': self.song_uri} - self.assertEqual(True, self.send(message)) + self.assertEqual(True, self.send_recv(message)) def test_play_uri_non_existing_file(self): message = {'command': 'play_uri', 'uri': self.song_uri + 'bogus'} - self.assertEqual(False, self.send(message)) + self.assertEqual(False, self.send_recv(message)) - - + def test_default_get_volume_result(self): + message = {'command': 'get_volume'} + self.assertEqual(100, self.send_recv(message)) + + def test_set_volume(self): + self.send({'command': 'set_volume', 'volume': 50}) + self.assertEqual(50, self.send_recv({'command': 'get_volume'})) + + def test_set_volume_to_zero(self): + self.send({'command': 'set_volume', 'volume': 0}) + self.assertEqual(0, self.send_recv({'command': 'get_volume'})) + + def test_set_volume_to_one_hundred(self): + self.send({'command': 'set_volume', 'volume': 100}) + self.assertEqual(100, self.send_recv({'command': 'get_volume'})) From 8599bcd491d66644c6f2be67d31097c52d3ed5de Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 15:50:15 +0200 Subject: [PATCH 070/138] test seekid updates cpid --- tests/frontends/mpd/playback_test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/frontends/mpd/playback_test.py b/tests/frontends/mpd/playback_test.py index 60e96d88..d347308c 100644 --- a/tests/frontends/mpd/playback_test.py +++ b/tests/frontends/mpd/playback_test.py @@ -283,6 +283,13 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) self.assert_(self.b.playback.time_position >= 30000) + def test_seekid_with_cpid(self): + seek_track = Track(uri='2', length=40000) + self.b.current_playlist.load( + [Track(length=40000), seek_track]) + result = self.h.handle_request(u'seekid "2" "30"') + self.assertEqual(self.b.playback.current_cpid, 2) + self.assertEqual(self.b.playback.current_track, seek_track) def test_stop(self): result = self.h.handle_request(u'stop') From 00f59e590b58339770276ba7c149ce74f42f5f93 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 16:00:06 +0200 Subject: [PATCH 071/138] test seek with songpos --- tests/frontends/mpd/playback_test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/frontends/mpd/playback_test.py b/tests/frontends/mpd/playback_test.py index d347308c..a1331bb3 100644 --- a/tests/frontends/mpd/playback_test.py +++ b/tests/frontends/mpd/playback_test.py @@ -277,6 +277,13 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) self.assert_(self.b.playback.time_position >= 30000) + def test_seek_with_songpos(self): + seek_track = Track(uri='2', length=40000) + self.b.current_playlist.load( + [Track(uri='1', length=40000), seek_track]) + result = self.h.handle_request(u'seek "1" "30"') + self.assertEqual(self.b.playback.current_track, seek_track) + def test_seekid(self): self.b.current_playlist.load([Track(length=40000)]) result = self.h.handle_request(u'seekid "1" "30"') From 9196140999fb17d6a7094768e6151bae6dd6dc02 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 14 Aug 2010 16:07:46 +0200 Subject: [PATCH 072/138] Add placeholder for possible set_state test --- tests/outputs/gstreamer_test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/outputs/gstreamer_test.py b/tests/outputs/gstreamer_test.py index 8f4f83bc..f483a68a 100644 --- a/tests/outputs/gstreamer_test.py +++ b/tests/outputs/gstreamer_test.py @@ -5,7 +5,7 @@ from mopidy.utils import path_to_uri from mopidy.process import pickle_connection from mopidy.outputs.gstreamer import GStreamerOutput -from tests import data_folder +from tests import data_folder, SkipTest class GStreamerOutputTest(unittest.TestCase): def setUp(self): @@ -50,3 +50,7 @@ class GStreamerOutputTest(unittest.TestCase): def test_set_volume_to_one_hundred(self): self.send({'command': 'set_volume', 'volume': 100}) self.assertEqual(100, self.send_recv({'command': 'get_volume'})) + + @SkipTest + def test_set_state(self): + raise NotImplementedError From 7bf8b19e4da2babceb27efa42af604ae7606be06 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 14 Aug 2010 16:23:59 +0200 Subject: [PATCH 073/138] Update pipeline description with names --- mopidy/outputs/gstreamer.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index e6e9fcea..9ce514df 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -42,7 +42,8 @@ class GStreamerProcess(BaseProcess): http://jameswestby.net/weblog/tech/14-caution-python-multiprocessing-and-glib-dont-mix.html. """ - pipeline_description = '(appsrc uridecodebin) ! volume ! autoaudiosink' + pipeline_description = \ + 'appsrc name=src uridecodebin name=uri ! volume name=volume ! autoaudiosink' def __init__(self, core_queue, output_queue): super(GStreamerProcess, self).__init__() @@ -70,9 +71,9 @@ class GStreamerProcess(BaseProcess): messages_thread.start() self.gst_pipeline = gst.parse_launch(self.pipeline_description) - self.gst_data_src = self.gst_pipeline.get_by_name('appsrc0') - self.gst_uri_bin = self.gst_pipeline.get_by_name('uridecodebin0') - self.gst_volume = self.gst_pipeline.get_by_name('volume0') + self.gst_data_src = self.gst_pipeline.get_by_name('src') + self.gst_uri_bin = self.gst_pipeline.get_by_name('uri') + self.gst_volume = self.gst_pipeline.get_by_name('volume') # Setup bus and message processor self.gst_bus = self.gst_pipeline.get_bus() From d04b4c318197a17de6dee353ec0ead9f1d92763a Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 14 Aug 2010 16:24:28 +0200 Subject: [PATCH 074/138] Skip local backend tests as they break new gso tests due to gst usage --- tests/backends/local_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/backends/local_test.py b/tests/backends/local_test.py index 23a12bca..a5222276 100644 --- a/tests/backends/local_test.py +++ b/tests/backends/local_test.py @@ -19,6 +19,7 @@ from tests import SkipTest, data_folder song = data_folder('song%s.wav') generate_song = lambda i: path_to_uri(song % i) +raise SkipTest # FIXME can be switched to generic test class LocalCurrentPlaylistControllerTest(BaseCurrentPlaylistControllerTest, From c30720f81ae433384babd21301dab78b53d8c292 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 14 Aug 2010 16:30:42 +0200 Subject: [PATCH 075/138] Fix pylint long line warning --- mopidy/outputs/gstreamer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 9ce514df..c2547bdb 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -42,8 +42,11 @@ class GStreamerProcess(BaseProcess): http://jameswestby.net/weblog/tech/14-caution-python-multiprocessing-and-glib-dont-mix.html. """ - pipeline_description = \ - 'appsrc name=src uridecodebin name=uri ! volume name=volume ! autoaudiosink' + pipeline_description = ' ! '.join([ + 'appsrc name=src uridecodebin name=uri', + 'volume name=volume', + 'autoaudiosink name=sink', + ]) def __init__(self, core_queue, output_queue): super(GStreamerProcess, self).__init__() From 473c31fec8fa55004dca449e5854c810ac68a554 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 16:42:46 +0200 Subject: [PATCH 076/138] Revert "Fix set_state method in GStreamerOutput" This reverts commit dc27434df9e66e530247fd47270729618be65a8d. --- mopidy/outputs/gstreamer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 5e64378f..a28329f7 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -159,10 +159,10 @@ class GStreamerProcess(BaseProcess): :type state_name: string :rtype: :class:`True` or :class:`False` """ - state = getattr(gst, 'STATE_' + state_name) - self.gst_pipeline.set_state(state) - new_state = self.gst_pipeline.get_state()[1] - if new_state == state: + # XXX Setting state to PLAYING often returns False even if it works + result = self.gst_pipeline.set_state( + getattr(gst, 'STATE_' + state_name)) + if result == gst.STATE_CHANGE_SUCCESS: logger.debug('Setting GStreamer state to %s: OK', state_name) return True else: From b4325c67db852c4cf961616be33e478a51a6f6b4 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 16:44:39 +0200 Subject: [PATCH 077/138] rename next_cp_track to cp_track_at_next to differ between next and end of track events --- mopidy/backends/base/playback.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index 2cf15629..08050523 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -100,16 +100,16 @@ class BasePlaybackController(object): """ The next track in the playlist. - A :class:`mopidy.models.Track` extracted from :attr:`next_cp_track` for + A :class:`mopidy.models.Track` extracted from :attr:`cp_track_at_next` for convenience. """ - next_cp_track = self.next_cp_track - if next_cp_track is None: + cp_track_at_next = self.cp_track_at_next + if cp_track_at_next is None: return None - return next_cp_track[1] + return cp_track_at_next[1] @property - def next_cp_track(self): + def cp_track_at_next(self): """ The next track in the playlist. @@ -247,7 +247,7 @@ class BasePlaybackController(object): Typically called by :class:`mopidy.process.CoreProcess` after a message from a library thread is received. """ - if self.next_cp_track is not None: + if self.cp_track_at_next is not None: self.next() else: self.stop() @@ -278,10 +278,10 @@ class BasePlaybackController(object): if self.state == self.STOPPED: return - elif self.next_cp_track is not None and self._next(self.next_track): - self.current_cp_track = self.next_cp_track + elif self.cp_track_at_next is not None and self._next(self.next_track): + self.current_cp_track = self.cp_track_at_next self.state = self.PLAYING - elif self.next_cp_track is None: + elif self.cp_track_at_next is None: self.stop() self.current_cp_track = None @@ -315,7 +315,7 @@ class BasePlaybackController(object): if cp_track is not None: assert cp_track in self.backend.current_playlist.cp_tracks elif not self.current_cp_track: - cp_track = self.next_cp_track + cp_track = self.cp_track_at_next if self.state == self.PAUSED and cp_track is None: self.resume() From a3b03b63565649a739b83731504f93f4fb4ec2ba Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 17:16:28 +0200 Subject: [PATCH 078/138] copied cp_track_at_next to cp_track_at_end_of_track and let the end of track implement it's own next functionality instead of calling next --- mopidy/backends/base/playback.py | 49 ++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index 08050523..e1167022 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -108,10 +108,46 @@ class BasePlaybackController(object): return None return cp_track_at_next[1] + @property + def cp_track_at_eot(self): + """ + The next track in the playlist which should be played when + we get an end of track event, such as when a track is finished playing. + + A two-tuple of (CPID integer, :class:`mopidy.models.Track`). + """ + cp_tracks = self.backend.current_playlist.cp_tracks + + if not cp_tracks: + return None + + if self.random and not self._shuffled: + if self.repeat or self._first_shuffle: + logger.debug('Shuffling tracks') + self._shuffled = cp_tracks + random.shuffle(self._shuffled) + self._first_shuffle = False + + if self._shuffled: + return self._shuffled[0] + + if self.current_cp_track is None: + return cp_tracks[0] + + if self.repeat: + return cp_tracks[ + (self.current_playlist_position + 1) % len(cp_tracks)] + + try: + return cp_tracks[self.current_playlist_position + 1] + except IndexError: + return None + @property def cp_track_at_next(self): """ - The next track in the playlist. + The next track in the playlist which should be played when we get a + event, such as a user clicking the next button. A two-tuple of (CPID integer, :class:`mopidy.models.Track`). @@ -247,8 +283,15 @@ class BasePlaybackController(object): Typically called by :class:`mopidy.process.CoreProcess` after a message from a library thread is received. """ - if self.cp_track_at_next is not None: - self.next() + if self.cp_track_at_eot is not None: + original_cp_track = self.current_cp_track + self.current_cp_track = self.cp_track_at_eot + + if self.consume: + self.backend.current_playlist.remove(cpid=original_cp_track[0]) + + if self.random and self.current_cp_track in self._shuffled: + self._shuffled.remove(self.current_cp_track) else: self.stop() self.current_cp_track = None From 622b96ef27b10a0dcb4b325e78a46a2ce67079b8 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 17:19:03 +0200 Subject: [PATCH 079/138] support single mode at end of track --- mopidy/backends/base/playback.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index e1167022..13f1e73b 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -134,6 +134,10 @@ class BasePlaybackController(object): if self.current_cp_track is None: return cp_tracks[0] + if self.repeat and self.single: + return cp_tracks[ + (self.current_playlist_position) % len(cp_tracks)] + if self.repeat: return cp_tracks[ (self.current_playlist_position + 1) % len(cp_tracks)] From 97ff6bf04293e9d6d9e6ed6247287e05da1ef0b0 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 17:24:06 +0200 Subject: [PATCH 080/138] Check if failure instead of chacking for success when setting GStreamer state --- mopidy/outputs/gstreamer.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index a28329f7..44e12afb 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -159,15 +159,14 @@ class GStreamerProcess(BaseProcess): :type state_name: string :rtype: :class:`True` or :class:`False` """ - # XXX Setting state to PLAYING often returns False even if it works result = self.gst_pipeline.set_state( getattr(gst, 'STATE_' + state_name)) - if result == gst.STATE_CHANGE_SUCCESS: - logger.debug('Setting GStreamer state to %s: OK', state_name) - return True - else: + if result == gst.STATE_CHANGE_FAILURE: logger.warning('Setting GStreamer state to %s: failed', state_name) return False + else: + logger.debug('Setting GStreamer state to %s: OK', state_name) + return True def get_volume(self): """Get volume in range [0..100]""" From 4205a3d49bb70c715a6c852a41b4328c6fc2de86 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 17:49:17 +0200 Subject: [PATCH 081/138] Remove recalibration at volume=0 with NadMixer. It's just way to frustrating. --- mopidy/mixers/nad.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mopidy/mixers/nad.py b/mopidy/mixers/nad.py index 56958005..d78863aa 100644 --- a/mopidy/mixers/nad.py +++ b/mopidy/mixers/nad.py @@ -22,10 +22,7 @@ class NadMixer(BaseMixer): currently used by this mixer. Sadly, this means that if you use the remote control to change the volume - on the amplifier, Mopidy will no longer report the correct volume. To - recalibrate the mixer, set the volume to 0 through Mopidy. This will reset - the amplifier to a known state, including powering on the device, selecting - the configured speakers and input sources. + on the amplifier, Mopidy will no longer report the correct volume. **Dependencies** @@ -51,8 +48,6 @@ class NadMixer(BaseMixer): def _set_volume(self, volume): self._volume = volume - if volume == 0: - self._pipe.send({'command': 'reset_device'}) self._pipe.send({'command': 'set_volume', 'volume': volume}) From 200cc3dd2a5b9e25ed0b10c155a98c0ca9cfa898 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 18:00:18 +0200 Subject: [PATCH 082/138] end of track to call play on the next track --- mopidy/backends/base/playback.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index 13f1e73b..08b7932d 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -287,9 +287,11 @@ class BasePlaybackController(object): Typically called by :class:`mopidy.process.CoreProcess` after a message from a library thread is received. """ - if self.cp_track_at_eot is not None: + next_cp_track = self.cp_track_at_eot + if next_cp_track is not None and self._next(next_cp_track[1]): original_cp_track = self.current_cp_track - self.current_cp_track = self.cp_track_at_eot + self.current_cp_track = next_cp_track + self.state = self.PLAYING if self.consume: self.backend.current_playlist.remove(cpid=original_cp_track[0]) From 968433641b68dccff26a66780f70986ec36bce27 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 18:01:16 +0200 Subject: [PATCH 083/138] Add MIXER_MAX_VOLUME setting for capping the max volume --- docs/changes.rst | 1 + mopidy/mixers/__init__.py | 7 +++++-- mopidy/settings.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index d3ed3db2..12028a17 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -34,6 +34,7 @@ greatly improved MPD client support. ``SPOTIFY_LIB_APPKEY`` setting is thus removed. - Added new :mod:`mopidy.mixers.GStreamerSoftwareMixer` which now is the default mixer on all platforms. +- New setting ``MIXER_MAX_VOLUME`` for capping the maximum output volume. - MPD frontend: - Relocate from :mod:`mopidy.mpd` to :mod:`mopidy.frontends.mpd`. diff --git a/mopidy/mixers/__init__.py b/mopidy/mixers/__init__.py index 3ef1b645..b03e3a4b 100644 --- a/mopidy/mixers/__init__.py +++ b/mopidy/mixers/__init__.py @@ -1,3 +1,5 @@ +from mopidy import settings + class BaseMixer(object): """ :param backend: a backend instance @@ -6,6 +8,7 @@ class BaseMixer(object): def __init__(self, backend, *args, **kwargs): self.backend = backend + self.amplification_factor = settings.MIXER_MAX_VOLUME / 100.0 @property def volume(self): @@ -15,11 +18,11 @@ class BaseMixer(object): Integer in range [0, 100]. :class:`None` if unknown. Values below 0 is equal to 0. Values above 100 is equal to 100. """ - return self._get_volume() + return self._get_volume() / self.amplification_factor @volume.setter def volume(self, volume): - volume = int(volume) + volume = int(volume) * self.amplification_factor if volume < 0: volume = 0 elif volume > 100: diff --git a/mopidy/settings.py b/mopidy/settings.py index 232adda8..67b0c24f 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -115,6 +115,16 @@ MIXER_EXT_SPEAKERS_A = None #: Default: :class:`None`. MIXER_EXT_SPEAKERS_B = None +#: The maximum volume. Integer in the range 0 to 100. +#: +#: If this settings is set to 80, the mixer will set the actual volume to 80 +#: when asked to set it to 100. +#: +#: Default:: +#: +#: MIXER_MAX_VOLUME = 100 +MIXER_MAX_VOLUME = 100 + #: Audio output handler to use. #: #: Default:: From 074976d9f3bdff2b42e6fa189ad97a033c60a689 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 18:18:15 +0200 Subject: [PATCH 084/138] Test MIXER_MAX_VOLUME and fix detected bugs --- mopidy/mixers/__init__.py | 6 ++++-- tests/mixers/base_test.py | 14 ++++++-------- tests/mixers/denon_test.py | 7 +++++-- tests/mixers/dummy_test.py | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 tests/mixers/dummy_test.py diff --git a/mopidy/mixers/__init__.py b/mopidy/mixers/__init__.py index b03e3a4b..c9543863 100644 --- a/mopidy/mixers/__init__.py +++ b/mopidy/mixers/__init__.py @@ -18,11 +18,13 @@ class BaseMixer(object): Integer in range [0, 100]. :class:`None` if unknown. Values below 0 is equal to 0. Values above 100 is equal to 100. """ - return self._get_volume() / self.amplification_factor + if self._get_volume() is None: + return None + return int(self._get_volume() / self.amplification_factor) @volume.setter def volume(self, volume): - volume = int(volume) * self.amplification_factor + volume = int(int(volume) * self.amplification_factor) if volume < 0: volume = 0 elif volume > 100: diff --git a/tests/mixers/base_test.py b/tests/mixers/base_test.py index 292edcda..d6129ad5 100644 --- a/tests/mixers/base_test.py +++ b/tests/mixers/base_test.py @@ -1,18 +1,16 @@ -import unittest - -from mopidy.mixers.dummy import DummyMixer - -class BaseMixerTest(unittest.TestCase): +class BaseMixerTest(object): MIN = 0 MAX = 100 - ACTUAL_MIN = MIN ACTUAL_MAX = MAX - INITIAL = None + mixer_class = None + def setUp(self): - self.mixer = DummyMixer(None) + assert self.mixer_class is not None, \ + "mixer_class must be set in subclass" + self.mixer = self.mixer_class(None) def test_initial_volume(self): self.assertEqual(self.mixer.volume, self.INITIAL) diff --git a/tests/mixers/denon_test.py b/tests/mixers/denon_test.py index e0f59705..5370f155 100644 --- a/tests/mixers/denon_test.py +++ b/tests/mixers/denon_test.py @@ -1,3 +1,5 @@ +import unittest + from mopidy.mixers.denon import DenonMixer from tests.mixers.base_test import BaseMixerTest @@ -22,11 +24,12 @@ class DenonMixerDeviceMock(object): def open(self): self._open = True -class DenonMixerTest(BaseMixerTest): +class DenonMixerTest(BaseMixerTest, unittest.TestCase): ACTUAL_MAX = 99 - INITIAL = 1 + mixer_class = DenonMixer + def setUp(self): self.device = DenonMixerDeviceMock() self.mixer = DenonMixer(None, device=self.device) diff --git a/tests/mixers/dummy_test.py b/tests/mixers/dummy_test.py new file mode 100644 index 00000000..334dc8a1 --- /dev/null +++ b/tests/mixers/dummy_test.py @@ -0,0 +1,17 @@ +import unittest + +from mopidy.mixers.dummy import DummyMixer +from tests.mixers.base_test import BaseMixerTest + +class DenonMixerTest(BaseMixerTest, unittest.TestCase): + mixer_class = DummyMixer + + def test_set_volume_is_capped(self): + self.mixer.amplification_factor = 0.5 + self.mixer.volume = 100 + self.assertEquals(self.mixer._volume, 50) + + def test_get_volume_does_not_show_that_the_volume_is_capped(self): + self.mixer.amplification_factor = 0.5 + self.mixer._volume = 50 + self.assertEquals(self.mixer.volume, 100) From ca52dd6363b39a235a5baabdc53cfa6916b630cb Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Sat, 14 Aug 2010 18:30:22 +0200 Subject: [PATCH 085/138] added tests for next track in single and repeat mode --- tests/backends/base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/backends/base.py b/tests/backends/base.py index 64ca7797..19f28ba5 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -811,6 +811,14 @@ class BasePlaybackControllerTest(object): self.playback.next() self.assert_(self.tracks[0] not in self.backend.current_playlist.tracks) + @populate_playlist + def test_next_with_single_and_repeat(self): + self.playback.single = True + self.playback.repeat = True + self.playback.play() + self.playback.next() + self.assertEqual(self.playback.current_track, self.tracks[1]) + @populate_playlist def test_playlist_is_empty_after_all_tracks_are_played_with_consume(self): self.playback.consume = True @@ -851,6 +859,14 @@ class BasePlaybackControllerTest(object): self.playback.end_of_track_callback() self.assertEqual(self.playback.current_track, self.tracks[1]) + @populate_playlist + def test_end_of_song_with_single_and_repeat_starts_same(self): + self.playback.single = True + self.playback.repeat = True + self.playback.play() + self.playback.end_of_track_callback() + self.assertEqual(self.playback.current_track, self.tracks[0]) + @populate_playlist def test_end_of_playlist_stops(self): self.playback.play(self.current_playlist.cp_tracks[-1]) From 4bea82c2f178eae8a069c0e3a38fbaa5d6d581ee Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 19:03:37 +0200 Subject: [PATCH 086/138] Shrink audio test data --- tests/data/blank.flac | Bin 9034 -> 14691 bytes tests/data/blank.mp3 | Bin 81920 -> 8208 bytes tests/data/blank.ogg | Bin 58178 -> 8671 bytes tests/data/blank.wav | Bin 845984 -> 35292 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/tests/data/blank.flac b/tests/data/blank.flac index b838b98eb40ae951f722aa4df50475536882cb2d..ae18d36f2ba07805ab46b7aae5b6727491870b47 100644 GIT binary patch literal 14691 zcmeI0-)|eqmfy9rlV49U0t86*VQ~@IR&2-Cz2=M+j$}51MFL3v!9ZhP!9Qdo8(WM$ z9y1Uv6SPRy-IpK<0t7HEYiUxf4PaRjJ(d>3u?6Y}JHY0JLy-lTBP+Bd_CrJ#s2^;E zC9!X*yX&NM-|{B}P!j}*Vt4iFPkrlr&*|Z-|K`s+Iy(NziH;K;9bf!a#~0*}_B;N4 zN5_Bq>wom<^nZ8#CHs@r|Gn`)Iz}A-@Q*t>{((I6|2a-{eA&_QPk$xHM(z*aAG!bd z-`@Y#qX&Qfude=!Kl{~hE?m6un_pf0^{=~s?fgym(Pe+padhVKaZKQtz%hYi0>=c7 z2^e*Zte==cvOzEn0WJ8IjP%Zs3QeE@g|@u1T3N5N-;O03fGvw+K2D%<)?gv26o z`pjY|KsU2Q<#f~0*k@TsYKSo)P9=EFqZV@Rl~GO4U;Z&az5F&YsjBvtP5c^n z>50l-VGHZm4Y>0$%nu>?lgT_2kOa*lSAiJ1g0uWHu{BMzN4$Y016a$e%cseGzr)+! z!=T0~H1v>-FEP{H2Zbq$SBRkaw2dG1yHH2Hm;dpRlK<#0q>|wOu1 ztD*#*6K33S#2cy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ioCF;(}@Y0a7s0KZpya^#@47ME@WznARU41rz;)xL{g;fD}yh58{I9 M|Fu83|FfO^1)G#PO8@`> diff --git a/tests/data/blank.ogg b/tests/data/blank.ogg index 3b1c57a1c68a11ba2a7c5e36a08a790252878d79..e67e428b1f3e6f67839e34379d9ea6ff70c386a3 100644 GIT binary patch literal 8671 zcmbtYcT`hbvkw-KA|RrI0*VkJ2?RnDP!vIdgdRdmK!s2YO(7HoMXxjoMTLY83KAfJ zgqqL4h)=-KQ>eT_X6XcStorN8ef=&ZQcu6}m zc{>imGoL7F9*YzN`&lxB51TJ!;?oc&viLqMDi_Z|0DNdPGM^}=?*;ad)Hmr^aKEjt zPbn}`Ztj{wFRI3naHOV@qjo&iXeo0-%RV>a3Tt=*<` zX+^ivO6uuq+e|o*xw6zC8Xa4<2bc?zGRY6IfJTWMcN<4b;s-RJi5rVpbjskZve3p z@re6G z36DO=f>f#%YBnde4;e3o??VVsh*qfi!k_`<>%xN|koe!g_o}?)(W;Z62M0mwW+_F^ zS*J*8MezmRB>GZ(0Uev?os~zR)4j9kK6E-Si@wyIHlJApJT7Gx(Md&14Mp?@W-*=Z z*FcA7Gkv(sC*%vELEbd~L9KVHM?c*CazrZ11K z!fS^1G$Xj|PdyEAnN%e@y_nAAWzu--cXbUh+?V&W^e&!Hmrxu%%rPiGhy5! zUUwBRcdffBAc4u_6#;soJ*}%t4Tv{v#&!X333zNM@2+AtHmq(}1qe3+P6l*Wm1hHH zu$jU=W!wft19PpkO7$mQMfe4CyH$gC4j=4##nInc%3*&ny*it~Qn z93avd@UxpC+*38qu6)zLP$@4z)&^g`jr&2#qK~r|8~%s~{HO_;bTk>+xHHVYbA{qL zT^n)wvB76U`MWFII(n=-lSDrG`OP zh-dwsCzY_;&%!`3-T;C2sppIQ_g`!%9wZ9k&vzFx+LvD_ZUjAqM{CR#dh{V7RI(%r z$#Azo&E=5aARzhVG!%pujmAQ$?UE>hDwX4oqIKAye5r*TfR9Rcw_tQgAx?pTfC6Tu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LYKfO{pL?1I%!nzKYp5#;+~6N0aUa__Ne@SN@$3&gG5$aiwM`6t#n-goZ^X`>RluiMEj~8bNb}c<1P3G^Hl^_laBNyiUjo%kf`j zI~<bu=%6ndWzRzC2Qoq2@R!x4ckJg`9 z_D7$0RkN|Q{G|5AoQ1&<|Hadau7?x!bb0`{V--V6S$i)I3fUfP3uFRm9t-=0X}lgt z#u%?5)zwLLemZYiwP_fVOxEYRG|yo?T~t_ZVVv=;#>#0D%Y$z9E?<+G6nclu5aR4wQFNtQlyX@)r#c2}Mh{ zpcd{^C;wp&D#arpd~4G})QYw0swMMVBxJ3HK^_I_Pdk#?>Lrwlf>Q0F7>NN3qMb3B_x+_)U4@+p`?euDpS3YR26X+dPV&%P{fqCOqo9SkcS@#Z%BXB^ za2EdboS^66$@FDc*BOjzU0_2v9*egr!2gduS7`cbcB@ zIfo44ytHQ|;ygds@vb}MI#SmONyS99v+p#1s$9O6T2&@OPAVQpcni2zt9lN&vFOtI zI>tGTOeSziw5|ylvI_SX_?RFMTTTf28%y|PyI8ptVvCyghk%^H_RAvWAr|*8A3AnL zAJ)1EC1`^H-cOwKw^KR~FO!l&NYCS%ZzTvMV9e~E6U(_|((3ZJZF8m11@JZwoC@qA z#k`prpCh$~2D$G>sZ{BrVC`OLxTd2L;RiG=gOGH_02l`?&QXEBp|IS-Tf()b;Vo>F z7POo#Obam^tccqx1Bhp#mdxl v1#?P9{9O0AACa{yG&aY>+>8s{@2XD*GwRWllC06fVk^yuChyiL$Y%OKkwfK8 literal 845984 zcmeIup$&sj07cPPf Date: Sat, 14 Aug 2010 20:42:12 +0200 Subject: [PATCH 087/138] docs: Fix link from 'licenses' to 'authors' --- docs/licenses.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/licenses.rst b/docs/licenses.rst index c7bf9433..c3a13904 100644 --- a/docs/licenses.rst +++ b/docs/licenses.rst @@ -2,7 +2,7 @@ Licenses ******** -For a list of contributors, see :ref:`authors`. For details on who have +For a list of contributors, see :doc:`authors`. For details on who have contributed what, please refer to our git repository. Source code license From fb6b19664658bda6f8fa453bb229adffca6f48a3 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 21:24:39 +0200 Subject: [PATCH 088/138] Fix 'load' so one can append a playlist to the current playlist --- docs/changes.rst | 6 +- mopidy/backends/base/current_playlist.py | 5 +- mopidy/backends/base/playback.py | 20 +++--- .../mpd/protocol/current_playlist.py | 1 + .../mpd/protocol/stored_playlists.py | 10 ++- tests/backends/base.py | 63 +++++++++---------- 6 files changed, 53 insertions(+), 52 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 12028a17..3856dfff 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -50,6 +50,7 @@ greatly improved MPD client support. - Implement ``seek`` and ``seekid``. - Fix ``playlistfind`` output so the correct song is played when playing songs directly from search results in GMPC. + - Fix ``load`` so that one can append a playlist to the current playlist. - Backends: @@ -73,7 +74,10 @@ greatly improved MPD client support. - :meth:`mopidy.backends.base.BaseBackend()` now accepts an ``output_queue`` which it can use to send messages (i.e. audio data) to the output process. - + - :meth:`mopidy.backends.base.BaseCurrentPlaylistController.load()` now + appends to the existing playlist. Use + :meth:`mopidy.backends.base.BaseCurrentPlaylistController.clear()` if you + want to clear it first. 0.1.0a3 (2010-08-03) diff --git a/mopidy/backends/base/current_playlist.py b/mopidy/backends/base/current_playlist.py index fc17bbee..ae6cfc0c 100644 --- a/mopidy/backends/base/current_playlist.py +++ b/mopidy/backends/base/current_playlist.py @@ -107,16 +107,15 @@ class BaseCurrentPlaylistController(object): def load(self, tracks): """ - Replace the tracks in the current playlist with the given tracks. + Append the given tracks to the current playlist. :param tracks: tracks to load :type tracks: list of :class:`mopidy.models.Track` """ - self._cp_tracks = [] self.version += 1 for track in tracks: self.add(track) - self.backend.playback.new_playlist_loaded_callback() + self.backend.playback.on_current_playlist_change() def move(self, start, end, to_position): """ diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index 2cf15629..f2b810e2 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -253,23 +253,21 @@ class BasePlaybackController(object): self.stop() self.current_cp_track = None - def new_playlist_loaded_callback(self): + def on_current_playlist_change(self): """ - Tell the playback controller that a new playlist has been loaded. + Tell the playback controller that the current playlist has changed. - Typically called by :class:`mopidy.process.CoreProcess` after a message - from a library thread is received. + Used by :class:`mopidy.backends.base.BaseCurrentPlaylistController`. """ - self.current_cp_track = None self._first_shuffle = True self._shuffled = [] - if self.state == self.PLAYING: - if len(self.backend.current_playlist.tracks) > 0: - self.play() - else: - self.stop() - elif self.state == self.PAUSED: + if not self.backend.current_playlist.cp_tracks: + self.stop() + self.current_cp_track = None + elif (self.current_cp_track not in + self.backend.current_playlist.cp_tracks): + self.current_cp_track = None self.stop() def next(self): diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index c10d1dad..17b019e9 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -341,6 +341,7 @@ def swap(frontend, songpos1, songpos2): tracks.insert(songpos1, song2) del tracks[songpos2] tracks.insert(songpos2, song1) + frontend.backend.current_playlist.clear() frontend.backend.current_playlist.load(tracks) @handle_pattern(r'^swapid "(?P\d+)" "(?P\d+)"$') diff --git a/mopidy/frontends/mpd/protocol/stored_playlists.py b/mopidy/frontends/mpd/protocol/stored_playlists.py index ecd8b321..adc455c3 100644 --- a/mopidy/frontends/mpd/protocol/stored_playlists.py +++ b/mopidy/frontends/mpd/protocol/stored_playlists.py @@ -86,6 +86,10 @@ def load(frontend, name): ``load {NAME}`` Loads the playlist ``NAME.m3u`` from the playlist directory. + + *Clarifications:* + + - ``load`` appends the given playlist to the current playlist. """ matches = frontend.backend.stored_playlists.search(name) if matches: @@ -139,9 +143,9 @@ def playlistmove(frontend, name, from_pos, to_pos): *Clarifications:* - - The second argument is not a ``SONGID`` as used elsewhere in the - protocol documentation, but just the ``SONGPOS`` to move *from*, - i.e. ``playlistmove {NAME} {FROM_SONGPOS} {TO_SONGPOS}``. + - The second argument is not a ``SONGID`` as used elsewhere in the protocol + documentation, but just the ``SONGPOS`` to move *from*, i.e. + ``playlistmove {NAME} {FROM_SONGPOS} {TO_SONGPOS}``. """ raise MpdNotImplemented # TODO diff --git a/tests/backends/base.py b/tests/backends/base.py index 64ca7797..3aaa725f 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -91,12 +91,6 @@ class BaseCurrentPlaylistControllerTest(object): self.controller.clear() self.assertEqual(self.playback.state, self.playback.STOPPED) - def test_load(self): - tracks = [] - self.assertNotEqual(id(tracks), id(self.controller.tracks)) - self.controller.load(tracks) - self.assertEqual(tracks, self.controller.tracks) - def test_get_by_uri_returns_unique_match(self): track = Track(uri='a') self.controller.load([Track(uri='z'), track, Track(uri='y')]) @@ -136,10 +130,15 @@ class BaseCurrentPlaylistControllerTest(object): self.controller.load([track1, track2, track3]) self.assertEqual(track2, self.controller.get(uri='b')[1]) - @populate_playlist - def test_load_replaces_playlist(self): - self.backend.current_playlist.load([]) - self.assertEqual(len(self.backend.current_playlist.tracks), 0) + def test_load_appends_to_the_current_playlist(self): + self.controller.load([Track(uri='a'), Track(uri='b')]) + self.assertEqual(len(self.controller.tracks), 2) + self.controller.load([Track(uri='c'), Track(uri='d')]) + self.assertEqual(len(self.controller.tracks), 4) + self.assertEqual(self.controller.tracks[0].uri, 'a') + self.assertEqual(self.controller.tracks[1].uri, 'b') + self.assertEqual(self.controller.tracks[2].uri, 'c') + self.assertEqual(self.controller.tracks[3].uri, 'd') def test_load_does_not_reset_version(self): version = self.controller.version @@ -148,22 +147,17 @@ class BaseCurrentPlaylistControllerTest(object): @populate_playlist def test_load_preserves_playing_state(self): - tracks = self.controller.tracks - playback = self.playback - self.playback.play() - self.controller.load([tracks[1]]) - self.assertEqual(playback.state, playback.PLAYING) - self.assertEqual(tracks[1], self.playback.current_track) + track = self.playback.current_track + self.controller.load(self.controller.tracks[1:2]) + self.assertEqual(self.playback.state, self.playback.PLAYING) + self.assertEqual(self.playback.current_track, track) @populate_playlist def test_load_preserves_stopped_state(self): - tracks = self.controller.tracks - playback = self.playback - - self.controller.load([tracks[2]]) - self.assertEqual(playback.state, playback.STOPPED) - self.assertEqual(None, self.playback.current_track) + self.controller.load(self.controller.tracks[1:2]) + self.assertEqual(self.playback.state, self.playback.STOPPED) + self.assertEqual(self.playback.current_track, None) @populate_playlist def test_move_single(self): @@ -575,15 +569,15 @@ class BasePlaybackControllerTest(object): self.playback.end_of_track_callback() self.assertEqual(self.playback.current_playlist_position, None) - def test_new_playlist_loaded_callback_gets_called(self): - callback = self.playback.new_playlist_loaded_callback + def test_on_current_playlist_change_gets_called(self): + callback = self.playback.on_current_playlist_change def wrapper(): wrapper.called = True return callback() wrapper.called = False - self.playback.new_playlist_loaded_callback = wrapper + self.playback.on_current_playlist_change = wrapper self.backend.current_playlist.load([]) self.assert_(wrapper.called) @@ -608,27 +602,28 @@ class BasePlaybackControllerTest(object): self.assert_(event.is_set()) @populate_playlist - def test_new_playlist_loaded_callback_when_playing(self): + def test_on_current_playlist_change_when_playing(self): self.playback.play() + current_track = self.playback.current_track self.backend.current_playlist.load([self.tracks[2]]) self.assertEqual(self.playback.state, self.playback.PLAYING) - self.assertEqual(self.playback.current_track, self.tracks[2]) + self.assertEqual(self.playback.current_track, current_track) @populate_playlist - def test_new_playlist_loaded_callback_when_stopped(self): + def test_on_current_playlist_change_when_stopped(self): + current_track = self.playback.current_track self.backend.current_playlist.load([self.tracks[2]]) self.assertEqual(self.playback.state, self.playback.STOPPED) self.assertEqual(self.playback.current_track, None) - self.assertEqual(self.playback.next_track, self.tracks[2]) @populate_playlist - def test_new_playlist_loaded_callback_when_paused(self): + def test_on_current_playlist_change_when_paused(self): self.playback.play() self.playback.pause() + current_track = self.playback.current_track self.backend.current_playlist.load([self.tracks[2]]) - self.assertEqual(self.playback.state, self.playback.STOPPED) - self.assertEqual(self.playback.current_track, None) - self.assertEqual(self.playback.next_track, self.tracks[2]) + self.assertEqual(self.playback.state, self.backend.playback.PAUSED) + self.assertEqual(self.playback.current_track, current_track) @populate_playlist def test_pause_when_stopped(self): @@ -899,7 +894,7 @@ class BasePlaybackControllerTest(object): self.playback.random = True self.assertEqual(self.playback.next_track, self.tracks[2]) self.backend.current_playlist.load(self.tracks[:1]) - self.assertEqual(self.playback.next_track, self.tracks[0]) + self.assertEqual(self.playback.next_track, self.tracks[1]) @populate_playlist def test_played_track_during_random_not_played_again(self): From b7030b127ad8adda2853d03ee6d75108dc0c2879 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 21:58:39 +0200 Subject: [PATCH 089/138] MPD: Fix 'play[id] -1' behaviour when current track is set --- docs/changes.rst | 3 +- mopidy/frontends/mpd/protocol/playback.py | 23 ++++++++----- tests/frontends/mpd/playback_test.py | 40 ++++++++++++++++++----- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 3856dfff..a0a4dad2 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -40,7 +40,8 @@ greatly improved MPD client support. - Relocate from :mod:`mopidy.mpd` to :mod:`mopidy.frontends.mpd`. - Split gigantic protocol implementation into eleven modules. - Search improvements, including support for multi-word search. - - Fixed ``play "-1"`` and ``playid "-1"`` behaviour when playlist is empty. + - Fixed ``play "-1"`` and ``playid "-1"`` behaviour when playlist is empty + or when a current track is set. - Support ``plchanges "-1"`` to work better with MPDroid. - Support ``pause`` without arguments to work better with MPDroid. - Support ``plchanges``, ``play``, ``consume``, ``random``, ``repeat``, and diff --git a/mopidy/frontends/mpd/protocol/playback.py b/mopidy/frontends/mpd/protocol/playback.py index bfff275e..7abc4509 100644 --- a/mopidy/frontends/mpd/protocol/playback.py +++ b/mopidy/frontends/mpd/protocol/playback.py @@ -139,9 +139,7 @@ def playid(frontend, cpid): cpid = int(cpid) try: if cpid == -1: - if not frontend.backend.current_playlist.cp_tracks: - return # Fail silently - cp_track = frontend.backend.current_playlist.cp_tracks[0] + cp_track = _get_cp_track_for_play_minus_one(frontend) else: cp_track = frontend.backend.current_playlist.get(cpid=cpid) return frontend.backend.playback.play(cp_track) @@ -158,10 +156,11 @@ def playpos(frontend, songpos): Begins playing the playlist at song number ``SONGPOS``. - *MPoD:* + *Many clients:* - - issues ``play "-1"`` after playlist replacement to start playback at - the first track. + - issue ``play "-1"`` after playlist replacement to start the current + track. If the current track is not set, start playback at the first + track. *BitMPC:* @@ -170,15 +169,21 @@ def playpos(frontend, songpos): songpos = int(songpos) try: if songpos == -1: - if not frontend.backend.current_playlist.cp_tracks: - return # Fail silently - cp_track = frontend.backend.current_playlist.cp_tracks[0] + cp_track = _get_cp_track_for_play_minus_one(frontend) else: cp_track = frontend.backend.current_playlist.cp_tracks[songpos] return frontend.backend.playback.play(cp_track) except IndexError: raise MpdArgError(u'Bad song index', command=u'play') +def _get_cp_track_for_play_minus_one(frontend): + if not frontend.backend.current_playlist.cp_tracks: + return # Fail silently + cp_track = frontend.backend.playback.current_cp_track + if cp_track is None: + cp_track = frontend.backend.current_playlist.cp_tracks[0] + return cp_track + @handle_pattern(r'^previous$') def previous(frontend): """ diff --git a/tests/frontends/mpd/playback_test.py b/tests/frontends/mpd/playback_test.py index a1331bb3..ce3130bf 100644 --- a/tests/frontends/mpd/playback_test.py +++ b/tests/frontends/mpd/playback_test.py @@ -225,13 +225,25 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assertEqual(result[0], u'ACK [2@0] {play} Bad song index') self.assertEqual(self.b.playback.STOPPED, self.b.playback.state) - def test_play_minus_one_plays_first_in_playlist(self): - track = Track() - self.b.current_playlist.load([track]) + def test_play_minus_one_plays_first_in_playlist_if_no_current_track(self): + self.assertEqual(self.b.playback.current_track, None) + self.b.current_playlist.load([Track(uri='a'), Track(uri='b')]) result = self.h.handle_request(u'play "-1"') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) - self.assertEqual(self.b.playback.current_track, track) + self.assertEqual(self.b.playback.current_track.uri, 'a') + + def test_play_minus_one_plays_current_track_if_current_track_is_set(self): + self.b.current_playlist.load([Track(uri='a'), Track(uri='b')]) + self.assertEqual(self.b.playback.current_track, None) + self.b.playback.play() + self.b.playback.next() + self.b.playback.stop() + self.assertNotEqual(self.b.playback.current_track, None) + result = self.h.handle_request(u'play "-1"') + self.assert_(u'OK' in result) + self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) + self.assertEqual(self.b.playback.current_track.uri, 'b') def test_play_minus_one_on_empty_playlist_does_not_ack(self): self.b.current_playlist.clear() @@ -246,13 +258,25 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) - def test_playid_minus_one_plays_first_in_playlist(self): - track = Track() - self.b.current_playlist.load([track]) + def test_playid_minus_one_plays_first_in_playlist_if_no_current_track(self): + self.assertEqual(self.b.playback.current_track, None) + self.b.current_playlist.load([Track(uri='a'), Track(uri='b')]) result = self.h.handle_request(u'playid "-1"') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) - self.assertEqual(self.b.playback.current_track, track) + self.assertEqual(self.b.playback.current_track.uri, 'a') + + def test_play_minus_one_plays_current_track_if_current_track_is_set(self): + self.b.current_playlist.load([Track(uri='a'), Track(uri='b')]) + self.assertEqual(self.b.playback.current_track, None) + self.b.playback.play() + self.b.playback.next() + self.b.playback.stop() + self.assertNotEqual(self.b.playback.current_track, None) + result = self.h.handle_request(u'playid "-1"') + self.assert_(u'OK' in result) + self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) + self.assertEqual(self.b.playback.current_track.uri, 'b') def test_playid_minus_one_on_empty_playlist_does_not_ack(self): self.b.current_playlist.clear() From 187d3544c483ea9dad9ba38b20dbfbf739d01be2 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 23:08:42 +0200 Subject: [PATCH 090/138] Play next track at play error --- docs/changes.rst | 1 + mopidy/backends/base/playback.py | 46 ++++++++++++-------------- mopidy/backends/libspotify/playback.py | 2 +- tests/backends/base.py | 36 ++++++++++++++++---- 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index a0a4dad2..76f01610 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -35,6 +35,7 @@ greatly improved MPD client support. - Added new :mod:`mopidy.mixers.GStreamerSoftwareMixer` which now is the default mixer on all platforms. - New setting ``MIXER_MAX_VOLUME`` for capping the maximum output volume. +- If failing to play a track, playback will skip to the next track. - MPD frontend: - Relocate from :mod:`mopidy.mpd` to :mod:`mopidy.frontends.mpd`. diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index f2b810e2..da951154 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -272,27 +272,24 @@ class BasePlaybackController(object): def next(self): """Play the next track.""" - original_cp_track = self.current_cp_track - if self.state == self.STOPPED: return - elif self.next_cp_track is not None and self._next(self.next_track): - self.current_cp_track = self.next_cp_track - self.state = self.PLAYING - elif self.next_cp_track is None: + + original_cp_track = self.current_cp_track + if self.next_cp_track: + self.play(self.next_cp_track) + else: self.stop() self.current_cp_track = None - # FIXME handle in play aswell? + # FIXME This should only be applied when reaching end of track, and not + # when pressing "next" if self.consume: self.backend.current_playlist.remove(cpid=original_cp_track[0]) if self.random and self.current_cp_track in self._shuffled: self._shuffled.remove(self.current_cp_track) - def _next(self, track): - return self._play(track) - def pause(self): """Pause playback.""" if self.state == self.PLAYING and self._pause(): @@ -301,13 +298,16 @@ class BasePlaybackController(object): def _pause(self): raise NotImplementedError - def play(self, cp_track=None): + def play(self, cp_track=None, on_error_step=1): """ Play the given track or the currently active track. :param cp_track: track to play :type cp_track: two-tuple (CPID integer, :class:`mopidy.models.Track`) or :class:`None` + :param on_error_step: direction to step at play error, 1 for next + track (default), -1 for previous track + :type on_error_step: int, -1 or 1 """ if cp_track is not None: @@ -317,13 +317,14 @@ class BasePlaybackController(object): if self.state == self.PAUSED and cp_track is None: self.resume() - elif cp_track is not None and self._play(cp_track[1]): + elif cp_track is not None: self.current_cp_track = cp_track self.state = self.PLAYING - - # TODO Do something sensible when _play() returns False, like calling - # next(). Adding this todo instead of just implementing it as I want a - # test case first. + if not self._play(cp_track[1]): + if at_error_step == 1: + self.next() + elif at_error_step == -1: + self.previous() if self.random and self.current_cp_track in self._shuffled: self._shuffled.remove(self.current_cp_track) @@ -333,14 +334,11 @@ class BasePlaybackController(object): def previous(self): """Play the previous track.""" - if (self.previous_cp_track is not None - and self.state != self.STOPPED - and self._previous(self.previous_track)): - self.current_cp_track = self.previous_cp_track - self.state = self.PLAYING - - def _previous(self, track): - return self._play(track) + if self.previous_cp_track is None: + return + if self.state == self.STOPPED: + return + self.play(self.previous_cp_track, on_error_step=-1) def resume(self): """If paused, resume playing the current track.""" diff --git a/mopidy/backends/libspotify/playback.py b/mopidy/backends/libspotify/playback.py index 60a5d355..1195e9bc 100644 --- a/mopidy/backends/libspotify/playback.py +++ b/mopidy/backends/libspotify/playback.py @@ -26,7 +26,7 @@ class LibspotifyPlaybackController(BasePlaybackController): def _play(self, track): self._set_output_state('READY') if self.state == self.PLAYING: - self.stop() + self.backend.spotify.session.play(0) if track.uri is None: return False try: diff --git a/tests/backends/base.py b/tests/backends/base.py index 3aaa725f..2976f5cc 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -345,6 +345,14 @@ class BasePlaybackControllerTest(object): self.playback.play(self.current_playlist.cp_tracks[-1]) self.assertEqual(self.playback.current_track, self.tracks[-1]) + @populate_playlist + def test_play_skips_to_next_track_on_failure(self): + # If _play() returns False, it is a failure. + self.playback._play = lambda track: track != self.tracks[0] + self.playback.play() + self.assertNotEqual(self.playback.current_track, self.tracks[0]) + self.assertEqual(self.playback.current_track, self.tracks[1]) + @populate_playlist def test_current_track_after_completed_playlist(self): self.playback.play(self.current_playlist.cp_tracks[-1]) @@ -411,6 +419,16 @@ class BasePlaybackControllerTest(object): self.playback.next() self.assertEqual(self.playback.state, self.playback.STOPPED) + @populate_playlist + def test_next_skips_to_next_track_on_failure(self): + # If _play() returns False, it is a failure. + self.playback._play = lambda track: track != self.tracks[1] + self.playback.play() + self.assertEqual(self.playback.current_track, self.tracks[0]) + self.playback.next() + self.assertNotEqual(self.playback.current_track, self.tracks[1]) + self.assertEqual(self.playback.current_track, self.tracks[2]) + @populate_playlist def test_previous(self): self.playback.play() @@ -451,6 +469,16 @@ class BasePlaybackControllerTest(object): self.assertEqual(self.playback.state, self.playback.STOPPED) self.assertEqual(self.playback.current_track, None) + @populate_playlist + def test_previous_skips_to_previous_track_on_failure(self): + # If _play() returns False, it is a failure. + self.playback._play = lambda track: track != self.tracks[1] + self.playback.play(self.current_playlist.cp_tracks[2]) + self.assertEqual(self.playback.current_track, self.tracks[2]) + self.playback.previous() + self.assertNotEqual(self.playback.current_track, self.tracks[1]) + self.assertEqual(self.playback.current_track, self.tracks[0]) + @populate_playlist def test_next_track_before_play(self): self.assertEqual(self.playback.next_track, self.tracks[0]) @@ -906,13 +934,9 @@ class BasePlaybackControllerTest(object): played.append(self.playback.current_track) self.playback.next() - def test_playing_track_with_invalid_uri(self): - self.backend.current_playlist.load([Track(uri='foobar')]) - self.playback.play() - self.assertEqual(self.playback.state, self.playback.STOPPED) - + @populate_playlist def test_playing_track_that_isnt_in_playlist(self): - test = lambda: self.playback.play(self.tracks[0]) + test = lambda: self.playback.play((17, Track())) self.assertRaises(AssertionError, test) From 79eb5028ca29e3a51786850b824051c3ecde7d67 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 23:52:03 +0200 Subject: [PATCH 091/138] Rename variables forgotten in previous commit --- mopidy/backends/base/playback.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index da951154..99162b47 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -321,9 +321,9 @@ class BasePlaybackController(object): self.current_cp_track = cp_track self.state = self.PLAYING if not self._play(cp_track[1]): - if at_error_step == 1: + if on_error_step == 1: self.next() - elif at_error_step == -1: + elif on_error_step == -1: self.previous() if self.random and self.current_cp_track in self._shuffled: From bb712a6d6eca7a9249d772842c78466d2833720e Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 23:52:56 +0200 Subject: [PATCH 092/138] Call on_current_playlist_change whenever the current playlist changes --- mopidy/backends/base/current_playlist.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mopidy/backends/base/current_playlist.py b/mopidy/backends/base/current_playlist.py index ae6cfc0c..8aefe8cd 100644 --- a/mopidy/backends/base/current_playlist.py +++ b/mopidy/backends/base/current_playlist.py @@ -66,10 +66,9 @@ class BaseCurrentPlaylistController(object): def clear(self): """Clear the current playlist.""" - self.backend.playback.stop() - self.backend.playback.current_cp_track = None self._cp_tracks = [] self.version += 1 + self.backend.playback.on_current_playlist_change() def get(self, **criteria): """ @@ -147,6 +146,7 @@ class BaseCurrentPlaylistController(object): to_position += 1 self._cp_tracks = new_cp_tracks self.version += 1 + self.backend.playback.on_current_playlist_change() def remove(self, **criteria): """ @@ -191,6 +191,7 @@ class BaseCurrentPlaylistController(object): random.shuffle(shuffled) self._cp_tracks = before + shuffled + after self.version += 1 + self.backend.playback.on_current_playlist_change() def mpd_format(self, *args, **kwargs): """Not a part of the generic backend API.""" From cf3e4aae5e2bc7ae157cacbd652a2374228c32fb Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 15 Aug 2010 00:11:22 +0200 Subject: [PATCH 093/138] We get 160kbps, not 320kbps, from pyspotify --- mopidy/backends/libspotify/translator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mopidy/backends/libspotify/translator.py b/mopidy/backends/libspotify/translator.py index 3a39aad5..ff8f3c5c 100644 --- a/mopidy/backends/libspotify/translator.py +++ b/mopidy/backends/libspotify/translator.py @@ -39,7 +39,7 @@ class LibspotifyTranslator(object): track_no=spotify_track.index(), date=date, length=spotify_track.duration(), - bitrate=320, + bitrate=160, ) @classmethod From d5c5fc16f5da6ffc68fd68781d8c1a19678df048 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 15 Aug 2010 00:28:50 +0200 Subject: [PATCH 094/138] Add Spotify Core notices as required by Spotify --- docs/installation/libspotify.rst | 18 ++++++++++++------ mopidy/backends/libspotify/__init__.py | 17 +++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/docs/installation/libspotify.rst b/docs/installation/libspotify.rst index 911bf39e..629998b9 100644 --- a/docs/installation/libspotify.rst +++ b/docs/installation/libspotify.rst @@ -2,15 +2,21 @@ libspotify installation *********************** -We are working on a -`libspotify `_ backend. -To use the libspotify backend you must install libspotify and -`pyspotify `_. +Mopidy uses `libspotify +`_ for playing music from +the Spotify music service. To use :mod:`mopidy.backends.libspotify` you must +install libspotify and `pyspotify `_. .. warning:: - This backend requires a Spotify premium account, and it requires you to get - an application key from Spotify before use. + This backend requires a `Spotify premium account + `_. + +.. note:: + + This product uses SPOTIFY CORE but is not endorsed, certified or otherwise + approved in any way by Spotify. Spotify is the registered trade mark of the + Spotify Group. Installing libspotify on Linux diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index 7a971bc5..f00ec1f0 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -9,14 +9,18 @@ ENCODING = 'utf-8' class LibspotifyBackend(BaseBackend): """ - A Spotify backend which uses the official `libspotify library - `_. - - `pyspotify `_ is the Python bindings - for libspotify. It got no documentation, but multiple examples are - available. Like libspotify, pyspotify's calls are mostly asynchronous. + A `Spotify `_ backend which uses the official + `libspotify `_ + library and the `pyspotify `_ Python + bindings for libspotify. **Issues:** http://github.com/jodal/mopidy/issues/labels/backend-libspotify + + .. note:: + + This product uses SPOTIFY(R) CORE but is not endorsed, certified or + otherwise approved in any way by Spotify. Spotify is the registered + trade mark of the Spotify Group. """ # Imports inside methods are to prevent loading of __init__.py to fail on @@ -40,6 +44,7 @@ class LibspotifyBackend(BaseBackend): def _connect(self): from .session_manager import LibspotifySessionManager + logger.info(u'Mopidy uses SPOTIFY(R) CORE') logger.info(u'Connecting to Spotify') spotify = LibspotifySessionManager( settings.SPOTIFY_USERNAME, settings.SPOTIFY_PASSWORD, From e4b5dd194a50337dec514347945e6df6b3fba00e Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 12:43:18 +0200 Subject: [PATCH 095/138] docs: Installing pyspotify on OS X --- docs/installation/libspotify.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/installation/libspotify.rst b/docs/installation/libspotify.rst index 629998b9..b3ea06fa 100644 --- a/docs/installation/libspotify.rst +++ b/docs/installation/libspotify.rst @@ -65,6 +65,8 @@ Install pyspotify's dependencies. At Debian/Ubuntu systems:: sudo aptitude install python-dev +In OS X no additional dependencies are needed. + Check out the pyspotify code, and install it:: git clone git://github.com/jodal/pyspotify.git From e859ca4ceb9b16c652876189fa8e28724d2ab5e2 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 18:47:47 +0200 Subject: [PATCH 096/138] Add single repeat fix to changelog --- docs/changes.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changes.rst b/docs/changes.rst index 76f01610..7fe59eb5 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -53,6 +53,7 @@ greatly improved MPD client support. - Fix ``playlistfind`` output so the correct song is played when playing songs directly from search results in GMPC. - Fix ``load`` so that one can append a playlist to the current playlist. + - Support for single track repeat added. (Fixes: :issue:`4`) - Backends: From 4e0b51ffbddaab2c2737d8fdd8b68d22fffd6bba Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Mon, 16 Aug 2010 18:50:29 +0200 Subject: [PATCH 097/138] remove consume on next() since it should be performed only at end of track --- mopidy/backends/base/playback.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index 973743e5..4dd0271b 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -322,18 +322,12 @@ class BasePlaybackController(object): if self.state == self.STOPPED: return - original_cp_track = self.current_cp_track if self.cp_track_at_next: self.play(self.cp_track_at_next) else: self.stop() self.current_cp_track = None - # FIXME This should only be applied when reaching end of track, and not - # when pressing "next" - if self.consume: - self.backend.current_playlist.remove(cpid=original_cp_track[0]) - if self.random and self.current_cp_track in self._shuffled: self._shuffled.remove(self.current_cp_track) From 6fbebff2900baa5642c201f7d71e2e0658e3e391 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 18:51:38 +0200 Subject: [PATCH 098/138] Removal of the despotify backend fixes GH-9, GH-10, GH-13 --- docs/changes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changes.rst b/docs/changes.rst index 7fe59eb5..b25360dc 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -59,7 +59,8 @@ greatly improved MPD client support. - Rename :mod:`mopidy.backends.gstreamer` to :mod:`mopidy.backends.local`. - Remove :mod:`mopidy.backends.despotify`, as Despotify is little maintained - and the Libspotify backend is working much better. + and the Libspotify backend is working much better. (Fixes: :issue:`9`, + :issue:`10`, :issue:`13`) - Rename ``mopidy.frontends.mpd.{serializer => translator}`` to match naming in backends. From 8e8d8407679593a80c6e339e93f2b3b0f76000f3 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 19:44:35 +0200 Subject: [PATCH 099/138] Modify changes done in gstreamer-output-testing to keep appsrc working --- mopidy/outputs/gstreamer.py | 4 ++-- tests/outputs/gstreamer_test.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mopidy/outputs/gstreamer.py b/mopidy/outputs/gstreamer.py index 332f2beb..ca5a98c5 100644 --- a/mopidy/outputs/gstreamer.py +++ b/mopidy/outputs/gstreamer.py @@ -43,7 +43,7 @@ class GStreamerProcess(BaseProcess): """ pipeline_description = ' ! '.join([ - 'appsrc name=src uridecodebin name=uri', + 'appsrc name=src', 'volume name=volume', 'autoaudiosink name=sink', ]) @@ -75,7 +75,7 @@ class GStreamerProcess(BaseProcess): self.gst_pipeline = gst.parse_launch(self.pipeline_description) self.gst_data_src = self.gst_pipeline.get_by_name('src') - self.gst_uri_bin = self.gst_pipeline.get_by_name('uri') + #self.gst_uri_bin = self.gst_pipeline.get_by_name('uri') self.gst_volume = self.gst_pipeline.get_by_name('volume') # Setup bus and message processor diff --git a/tests/outputs/gstreamer_test.py b/tests/outputs/gstreamer_test.py index f483a68a..62207659 100644 --- a/tests/outputs/gstreamer_test.py +++ b/tests/outputs/gstreamer_test.py @@ -27,10 +27,12 @@ class GStreamerOutputTest(unittest.TestCase): def send(self, message): self.output_queue.put(message) + @SkipTest def test_play_uri_existing_file(self): message = {'command': 'play_uri', 'uri': self.song_uri} self.assertEqual(True, self.send_recv(message)) + @SkipTest def test_play_uri_non_existing_file(self): message = {'command': 'play_uri', 'uri': self.song_uri + 'bogus'} self.assertEqual(False, self.send_recv(message)) From 927b9477f081afb396c958aee602cb2409bffe0b Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 20:08:40 +0200 Subject: [PATCH 100/138] Move AUTHORS.rst into docs --- AUTHORS.rst | 9 --------- docs/authors.rst | 11 ++++++++++- 2 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 AUTHORS.rst diff --git a/AUTHORS.rst b/AUTHORS.rst deleted file mode 100644 index fc4b5611..00000000 --- a/AUTHORS.rst +++ /dev/null @@ -1,9 +0,0 @@ -Authors -======= - -Contributors to Mopidy in the order of appearance: - -- Stein Magnus Jodal -- Johannes Knutsen -- Thomas Adamcik -- Kristian Klette diff --git a/docs/authors.rst b/docs/authors.rst index e122f914..e21b79f6 100644 --- a/docs/authors.rst +++ b/docs/authors.rst @@ -1 +1,10 @@ -.. include:: ../AUTHORS.rst +******* +Authors +******* + +Contributors to Mopidy in the order of appearance: + +- Stein Magnus Jodal +- Johannes Knutsen +- Thomas Adamcik +- Kristian Klette From 937e10cadc59916b951e886fc208bf8e21c45930 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 20:21:11 +0200 Subject: [PATCH 101/138] Reorganize changelog a bit --- docs/changes.rst | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index b25360dc..36525cda 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -30,12 +30,6 @@ greatly improved MPD client support. - Exit early if not Python >= 2.6, < 3. - Include Sphinx scripts for building docs, pylintrc, tests and test data in the packages created by ``setup.py`` for i.e. PyPI. -- A Spotify application key is now bundled with the source. The - ``SPOTIFY_LIB_APPKEY`` setting is thus removed. -- Added new :mod:`mopidy.mixers.GStreamerSoftwareMixer` which now is the - default mixer on all platforms. -- New setting ``MIXER_MAX_VOLUME`` for capping the maximum output volume. -- If failing to play a track, playback will skip to the next track. - MPD frontend: - Relocate from :mod:`mopidy.mpd` to :mod:`mopidy.frontends.mpd`. @@ -54,6 +48,8 @@ greatly improved MPD client support. songs directly from search results in GMPC. - Fix ``load`` so that one can append a playlist to the current playlist. - Support for single track repeat added. (Fixes: :issue:`4`) + - Rename ``mopidy.frontends.mpd.{serializer => translator}`` to match naming + in backends. - Backends: @@ -61,8 +57,15 @@ greatly improved MPD client support. - Remove :mod:`mopidy.backends.despotify`, as Despotify is little maintained and the Libspotify backend is working much better. (Fixes: :issue:`9`, :issue:`10`, :issue:`13`) - - Rename ``mopidy.frontends.mpd.{serializer => translator}`` to match naming - in backends. + - A Spotify application key is now bundled with the source. The + ``SPOTIFY_LIB_APPKEY`` setting is thus removed. + - If failing to play a track, playback will skip to the next track. + +- Mixers: + + - Added new :mod:`mopidy.mixers.GStreamerSoftwareMixer` which now is the + default mixer on all platforms. + - New setting ``MIXER_MAX_VOLUME`` for capping the maximum output volume. - Backend API: From 5524b1a0114c5d3c31530dded75b131b7f1c63c0 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Mon, 16 Aug 2010 21:00:31 +0200 Subject: [PATCH 102/138] test next() keeps skipped cp track, but end_of_track removes track --- tests/backends/base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/backends/base.py b/tests/backends/base.py index 05379c57..31892de2 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -832,6 +832,13 @@ class BasePlaybackControllerTest(object): self.playback.consume = True self.playback.play() self.playback.next() + self.assert_(self.tracks[0] in self.backend.current_playlist.tracks) + + @populate_playlist + def test_end_of_track_with_consume(self): + self.playback.consume = True + self.playback.play() + self.playback.end_of_track_callback() self.assert_(self.tracks[0] not in self.backend.current_playlist.tracks) @populate_playlist @@ -847,7 +854,7 @@ class BasePlaybackControllerTest(object): self.playback.consume = True self.playback.play() for i in range(len(self.backend.current_playlist.tracks)): - self.playback.next() + self.playback.end_of_track_callback() self.assertEqual(len(self.backend.current_playlist.tracks), 0) @populate_playlist From 0e875da0e8bde1243195b3592501bc09fe6fd596 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Mon, 16 Aug 2010 21:01:16 +0200 Subject: [PATCH 103/138] make consume also remove the last track in cp when finished playing --- mopidy/backends/base/playback.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index 4dd0271b..bb0ab3dc 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -291,15 +291,15 @@ class BasePlaybackController(object): if self.cp_track_at_eot: self.play(self.cp_track_at_eot) - if self.consume: - self.backend.current_playlist.remove(cpid=original_cp_track[0]) - if self.random and self.current_cp_track in self._shuffled: self._shuffled.remove(self.current_cp_track) else: self.stop() self.current_cp_track = None + if self.consume: + self.backend.current_playlist.remove(cpid=original_cp_track[0]) + def on_current_playlist_change(self): """ Tell the playback controller that the current playlist has changed. From 4cfbfbb2d21a92703932006bfa07c61675cdf73f Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 21:27:38 +0200 Subject: [PATCH 104/138] Fix some missing renames in PlaybackController. Doc changes from singlerepeat branch. --- docs/changes.rst | 23 +++++- mopidy/backends/base/playback.py | 132 ++++++++++++++++++++++--------- 2 files changed, 114 insertions(+), 41 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 36525cda..b6e827f2 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -72,19 +72,36 @@ greatly improved MPD client support. - Relocate from :mod:`mopidy.backends` to :mod:`mopidy.backends.base`. - The ``id`` field of :class:`mopidy.models.Track` has been removed, as it is no longer needed after the CPID refactoring. + - :meth:`mopidy.backends.base.BaseBackend()` now accepts an + ``output_queue`` which it can use to send messages (i.e. audio data) + to the output process. - :meth:`mopidy.backends.base.BaseLibraryController.find_exact()` now accepts keyword arguments of the form ``find_exact(artist=['foo'], album=['bar'])``. - :meth:`mopidy.backends.base.BaseLibraryController.search()` now accepts keyword arguments of the form ``search(artist=['foo', 'fighters'], album=['bar', 'grooves'])``. - - :meth:`mopidy.backends.base.BaseBackend()` now accepts an - ``output_queue`` which it can use to send messages (i.e. audio data) - to the output process. - :meth:`mopidy.backends.base.BaseCurrentPlaylistController.load()` now appends to the existing playlist. Use :meth:`mopidy.backends.base.BaseCurrentPlaylistController.clear()` if you want to clear it first. + - The following fields in + :class:`mopidy.backends.base.BasePlaybackController` has been renamed to + reflect their relation to methods called on the controller: + + - ``next_track`` to ``track_at_next`` + - ``next_cp_track`` to ``cp_track_at_next`` + - ``previous_track`` to ``track_at_previous`` + - ``previous_cp_track`` to ``cp_track_at_previous`` + + - :attr:`mopidy.backends.base.BasePlaybackController.track_at_eot` and + :attr:`mopidy.backends.base.BasePlaybackController.cp_track_at_eot` has + been added to better handle the difference between the user pressing next + and the current track ending. + - Rename + :meth:`mopidy.backends.base.BasePlaybackController.new_playlist_loaded_callback()` + to + :meth:`mopidy.backends.base.BasePlaybackController.on_current_playlist_change()`. 0.1.0a3 (2010-08-03) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index bb0ab3dc..b86678a2 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -25,7 +25,7 @@ class BasePlaybackController(object): #: Tracks are not removed from the playlist. consume = False - #: The currently playing or selected track + #: The currently playing or selected track. #: #: A two-tuple of (CPID integer, :class:`mopidy.models.Track`) or #: :class:`None`. @@ -45,7 +45,8 @@ class BasePlaybackController(object): repeat = False #: :class:`True` - #: Playback is stopped after current song, unless in repeat mode. + #: Playback is stopped after current song, unless in :attr:`repeat` + #: mode. #: :class:`False` #: Playback continues after current song. single = False @@ -59,19 +60,32 @@ class BasePlaybackController(object): self._play_time_started = None def destroy(self): - """Cleanup after component.""" + """ + Cleanup after component. + + May be overridden by subclasses. + """ pass + def _get_cpid(self, cp_track): + if cp_track is None: + return None + return cp_track[0] + + def _get_track(self, cp_track): + if cp_track is None: + return None + return cp_track[1] + @property def current_cpid(self): """ - The CPID (current playlist ID) of :attr:`current_track`. + The CPID (current playlist ID) of the currently playing or selected + track. Read-only. Extracted from :attr:`current_cp_track` for convenience. """ - if self.current_cp_track is None: - return None - return self.current_cp_track[0] + return self._get_cpid(self.current_cp_track) @property def current_track(self): @@ -80,13 +94,15 @@ class BasePlaybackController(object): Read-only. Extracted from :attr:`current_cp_track` for convenience. """ - if self.current_cp_track is None: - return None - return self.current_cp_track[1] + return self._get_track(self.current_cp_track) @property def current_playlist_position(self): - """The position of the current track in the current playlist.""" + """ + The position of the current track in the current playlist. + + Read-only. + """ if self.current_cp_track is None: return None try: @@ -96,25 +112,23 @@ class BasePlaybackController(object): return None @property - def next_track(self): + def track_at_eot(self): """ - The next track in the playlist. + The track that will be played at the end of the current track. - A :class:`mopidy.models.Track` extracted from :attr:`cp_track_at_next` for - convenience. + Read-only. A :class:`mopidy.models.Track` extracted from + :attr:`cp_track_at_eot` for convenience. """ - cp_track_at_next = self.cp_track_at_next - if cp_track_at_next is None: - return None - return cp_track_at_next[1] + return self._get_track(self.cp_track_at_eot) @property def cp_track_at_eot(self): """ - The next track in the playlist which should be played when - we get an end of track event, such as when a track is finished playing. + The track that will be played at the end of the current track. - A two-tuple of (CPID integer, :class:`mopidy.models.Track`). + Read-only. A two-tuple of (CPID integer, :class:`mopidy.models.Track`). + + Not necessarily the same track as :attr:`cp_track_at_next`. """ cp_tracks = self.backend.current_playlist.cp_tracks @@ -147,13 +161,22 @@ class BasePlaybackController(object): except IndexError: return None + @property + def track_at_next(self): + """ + The track that will be played if calling :meth:`next()`. + + Read-only. A :class:`mopidy.models.Track` extracted from + :attr:`cp_track_at_next` for convenience. + """ + return self._get_track(self.cp_track_at_next) + @property def cp_track_at_next(self): """ - The next track in the playlist which should be played when we get a - event, such as a user clicking the next button. + The track that will be played if calling :meth:`next()`. - A two-tuple of (CPID integer, :class:`mopidy.models.Track`). + Read-only. A two-tuple of (CPID integer, :class:`mopidy.models.Track`). 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 @@ -188,22 +211,19 @@ class BasePlaybackController(object): return None @property - def previous_track(self): + def track_at_previous(self): """ - The previous track in the playlist. + The track that will be played if calling :meth:`previous()`. - A :class:`mopidy.models.Track` extracted from :attr:`previous_cp_track` - for convenience. + Read-only. A :class:`mopidy.models.Track` extracted from + :attr:`cp_track_at_previous` for convenience. """ - previous_cp_track = self.previous_cp_track - if previous_cp_track is None: - return None - return previous_cp_track[1] + return self._get_track(self.cp_track_at_previous) @property - def previous_cp_track(self): + def cp_track_at_previous(self): """ - The previous track in the playlist. + The track that will be played if calling :meth:`previous()`. A two-tuple of (CPID integer, :class:`mopidy.models.Track`). @@ -337,11 +357,18 @@ class BasePlaybackController(object): self.state = self.PAUSED def _pause(self): + """ + To be overridden by subclass. Implement your backend's pause + functionality here. + + :rtype: :class:`True` if successful, else :class:`False` + """ raise NotImplementedError def play(self, cp_track=None, on_error_step=1): """ - Play the given track or the currently active track. + Play the given track, or if the given track is :class:`None`, play the + currently active track. :param cp_track: track to play :type cp_track: two-tuple (CPID integer, :class:`mopidy.models.Track`) @@ -371,15 +398,24 @@ class BasePlaybackController(object): self._shuffled.remove(self.current_cp_track) def _play(self, track): + """ + To be overridden by subclass. Implement your backend's play + functionality here. + + :param track: the track to play + :type track: :class:`mopidy.models.Track` + :rtype: :class:`True` if successful, else :class:`False` + """ + raise NotImplementedError def previous(self): """Play the previous track.""" - if self.previous_cp_track is None: + if self.cp_track_at_previous is None: return if self.state == self.STOPPED: return - self.play(self.previous_cp_track, on_error_step=-1) + self.play(self.cp_track_at_previous, on_error_step=-1) def resume(self): """If paused, resume playing the current track.""" @@ -387,6 +423,12 @@ class BasePlaybackController(object): self.state = self.PLAYING def _resume(self): + """ + To be overridden by subclass. Implement your backend's resume + functionality here. + + :rtype: :class:`True` if successful, else :class:`False` + """ raise NotImplementedError def seek(self, time_position): @@ -413,6 +455,14 @@ class BasePlaybackController(object): self._seek(time_position) def _seek(self, time_position): + """ + To be overridden by subclass. Implement your backend's seek + functionality here. + + :param time_position: time position in milliseconds + :type time_position: int + :rtype: :class:`True` if successful, else :class:`False` + """ raise NotImplementedError def stop(self): @@ -421,4 +471,10 @@ class BasePlaybackController(object): self.state = self.STOPPED def _stop(self): + """ + To be overridden by subclass. Implement your backend's stop + functionality here. + + :rtype: :class:`True` if successful, else :class:`False` + """ raise NotImplementedError From e4421eec1c505ac85ae9b3811e9426c59e5dbbf1 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 21:28:15 +0200 Subject: [PATCH 105/138] Rename PlaybackController.{end_of_track_callback => on_end_of_track} --- docs/changes.rst | 3 +++ mopidy/backends/base/playback.py | 2 +- mopidy/process.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index b6e827f2..01b3c5bc 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -102,6 +102,9 @@ greatly improved MPD client support. :meth:`mopidy.backends.base.BasePlaybackController.new_playlist_loaded_callback()` to :meth:`mopidy.backends.base.BasePlaybackController.on_current_playlist_change()`. + - Rename + :meth:`mopidy.backends.base.BasePlaybackController.end_of_track_callback()` + to :meth:`mopidy.backends.base.BasePlaybackController.on_end_of_track()`. 0.1.0a3 (2010-08-03) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index b86678a2..f484bf89 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -300,7 +300,7 @@ class BasePlaybackController(object): def _current_wall_time(self): return int(time.time() * 1000) - def end_of_track_callback(self): + def on_end_of_track(self): """ Tell the playback controller that end of track is reached. diff --git a/mopidy/process.py b/mopidy/process.py index 53b6fbb5..01ac8ed4 100644 --- a/mopidy/process.py +++ b/mopidy/process.py @@ -68,7 +68,7 @@ class CoreProcess(BaseProcess): connection = unpickle_connection(message['reply_to']) connection.send(response) elif message['command'] == 'end_of_track': - self.backend.playback.end_of_track_callback() + self.backend.playback.on_end_of_track() elif message['command'] == 'stop_playback': self.backend.playback.stop() elif message['command'] == 'set_stored_playlists': From d7bf31bab4e2b1e4f501c1d3e1470d3a7e08d0a2 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 21:32:08 +0200 Subject: [PATCH 106/138] Rename CurrentPlaylistController.{load => append} --- docs/changes.rst | 7 +- mopidy/backends/base/current_playlist.py | 24 +++---- .../mpd/protocol/current_playlist.py | 2 +- .../mpd/protocol/stored_playlists.py | 2 +- tests/frontends/mpd/current_playlist_test.py | 66 +++++++++---------- tests/frontends/mpd/playback_test.py | 34 +++++----- tests/frontends/mpd/status_test.py | 12 ++-- 7 files changed, 74 insertions(+), 73 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 01b3c5bc..dfe46951 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -81,10 +81,11 @@ greatly improved MPD client support. - :meth:`mopidy.backends.base.BaseLibraryController.search()` now accepts keyword arguments of the form ``search(artist=['foo', 'fighters'], album=['bar', 'grooves'])``. - - :meth:`mopidy.backends.base.BaseCurrentPlaylistController.load()` now - appends to the existing playlist. Use + - :meth:`mopidy.backends.base.BaseCurrentPlaylistController.append()` + replaces + :meth:`mopidy.backends.base.BaseCurrentPlaylistController.load()`. Use :meth:`mopidy.backends.base.BaseCurrentPlaylistController.clear()` if you - want to clear it first. + want to clear the current playlist. - The following fields in :class:`mopidy.backends.base.BasePlaybackController` has been renamed to reflect their relation to methods called on the controller: diff --git a/mopidy/backends/base/current_playlist.py b/mopidy/backends/base/current_playlist.py index 8aefe8cd..c8c83a62 100644 --- a/mopidy/backends/base/current_playlist.py +++ b/mopidy/backends/base/current_playlist.py @@ -64,6 +64,18 @@ class BaseCurrentPlaylistController(object): self.version += 1 return cp_track + def append(self, tracks): + """ + Append the given tracks to the current playlist. + + :param tracks: tracks to append + :type tracks: list of :class:`mopidy.models.Track` + """ + self.version += 1 + for track in tracks: + self.add(track) + self.backend.playback.on_current_playlist_change() + def clear(self): """Clear the current playlist.""" self._cp_tracks = [] @@ -104,18 +116,6 @@ class BaseCurrentPlaylistController(object): else: raise LookupError(u'"%s" match multiple tracks' % criteria_string) - def load(self, tracks): - """ - Append the given tracks to the current playlist. - - :param tracks: tracks to load - :type tracks: list of :class:`mopidy.models.Track` - """ - self.version += 1 - for track in tracks: - self.add(track) - self.backend.playback.on_current_playlist_change() - def move(self, start, end, to_position): """ Move the tracks in the slice ``[start:end]`` to ``to_position``. diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index 17b019e9..89376945 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -342,7 +342,7 @@ def swap(frontend, songpos1, songpos2): del tracks[songpos2] tracks.insert(songpos2, song1) frontend.backend.current_playlist.clear() - frontend.backend.current_playlist.load(tracks) + frontend.backend.current_playlist.append(tracks) @handle_pattern(r'^swapid "(?P\d+)" "(?P\d+)"$') def swapid(frontend, cpid1, cpid2): diff --git a/mopidy/frontends/mpd/protocol/stored_playlists.py b/mopidy/frontends/mpd/protocol/stored_playlists.py index adc455c3..25ae4c32 100644 --- a/mopidy/frontends/mpd/protocol/stored_playlists.py +++ b/mopidy/frontends/mpd/protocol/stored_playlists.py @@ -93,7 +93,7 @@ def load(frontend, name): """ matches = frontend.backend.stored_playlists.search(name) if matches: - frontend.backend.current_playlist.load(matches[0].tracks) + frontend.backend.current_playlist.append(matches[0].tracks) @handle_pattern(r'^playlistadd "(?P[^"]+)" "(?P[^"]+)"$') def playlistadd(frontend, name, uri): diff --git a/tests/frontends/mpd/current_playlist_test.py b/tests/frontends/mpd/current_playlist_test.py index 6b5c822e..a063b513 100644 --- a/tests/frontends/mpd/current_playlist_test.py +++ b/tests/frontends/mpd/current_playlist_test.py @@ -13,7 +13,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): def test_add(self): needle = Track(uri='dummy://foo') self.b.library._library = [Track(), Track(), needle, Track()] - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 5) result = self.h.handle_request(u'add "dummy://foo"') @@ -30,7 +30,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): def test_addid_without_songpos(self): needle = Track(uri='dummy://foo') self.b.library._library = [Track(), Track(), needle, Track()] - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 5) result = self.h.handle_request(u'addid "dummy://foo"') @@ -43,7 +43,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): def test_addid_with_songpos(self): needle = Track(uri='dummy://foo') self.b.library._library = [Track(), Track(), needle, Track()] - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 5) result = self.h.handle_request(u'addid "dummy://foo" "3"') @@ -56,7 +56,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): def test_addid_with_songpos_out_of_bounds_should_ack(self): needle = Track(uri='dummy://foo') self.b.library._library = [Track(), Track(), needle, Track()] - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 5) result = self.h.handle_request(u'addid "dummy://foo" "6"') @@ -67,7 +67,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assertEqual(result[0], u'ACK [50@0] {addid} No such song') def test_clear(self): - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 5) result = self.h.handle_request(u'clear') @@ -76,7 +76,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_delete_songpos(self): - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 5) result = self.h.handle_request(u'delete "%d"' % @@ -85,7 +85,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_delete_songpos_out_of_bounds(self): - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 5) result = self.h.handle_request(u'delete "5"') @@ -93,7 +93,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assertEqual(result[0], u'ACK [2@0] {delete} Bad song index') def test_delete_open_range(self): - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 5) result = self.h.handle_request(u'delete "1:"') @@ -101,7 +101,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_delete_closed_range(self): - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 5) result = self.h.handle_request(u'delete "1:3"') @@ -109,7 +109,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_delete_range_out_of_bounds(self): - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 5) result = self.h.handle_request(u'delete "5:7"') @@ -117,21 +117,21 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assertEqual(result[0], u'ACK [2@0] {delete} Bad song index') def test_deleteid(self): - self.b.current_playlist.load([Track(), Track()]) + self.b.current_playlist.append([Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 2) result = self.h.handle_request(u'deleteid "2"') self.assertEqual(len(self.b.current_playlist.tracks), 1) self.assert_(u'OK' in result) def test_deleteid_does_not_exist(self): - self.b.current_playlist.load([Track(), Track()]) + self.b.current_playlist.append([Track(), Track()]) self.assertEqual(len(self.b.current_playlist.tracks), 2) result = self.h.handle_request(u'deleteid "12345"') self.assertEqual(len(self.b.current_playlist.tracks), 2) self.assertEqual(result[0], u'ACK [50@0] {deleteid} No such song') def test_move_songpos(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -145,7 +145,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_move_open_range(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -159,7 +159,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_move_closed_range(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -173,7 +173,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_moveid(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -208,7 +208,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_playlistfind_by_filename_in_current_playlist(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(uri='file:///exists')]) result = self.h.handle_request( u'playlistfind filename "file:///exists"') @@ -218,14 +218,14 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_playlistid_without_songid(self): - self.b.current_playlist.load([Track(name='a'), Track(name='b')]) + self.b.current_playlist.append([Track(name='a'), Track(name='b')]) result = self.h.handle_request(u'playlistid') self.assert_(u'Title: a' in result) self.assert_(u'Title: b' in result) self.assert_(u'OK' in result) def test_playlistid_with_songid(self): - self.b.current_playlist.load([Track(name='a'), Track(name='b')]) + self.b.current_playlist.append([Track(name='a'), Track(name='b')]) result = self.h.handle_request(u'playlistid "2"') self.assert_(u'Title: a' not in result) self.assert_(u'Id: 1' not in result) @@ -234,12 +234,12 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_playlistid_with_not_existing_songid_fails(self): - self.b.current_playlist.load([Track(name='a'), Track(name='b')]) + self.b.current_playlist.append([Track(name='a'), Track(name='b')]) result = self.h.handle_request(u'playlistid "25"') self.assertEqual(result[0], u'ACK [50@0] {playlistid} No such song') def test_playlistinfo_without_songpos_or_range(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -253,7 +253,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_playlistinfo_with_songpos(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -272,7 +272,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assertEqual(result1, result2) def test_playlistinfo_with_open_range(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -286,7 +286,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_playlistinfo_with_closed_range(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -316,7 +316,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'ACK [0@0] {} Not implemented' in result) def test_plchanges(self): - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(name='a'), Track(name='b'), Track(name='c')]) result = self.h.handle_request(u'plchanges "0"') self.assert_(u'Title: a' in result) @@ -325,7 +325,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_plchanges_with_minus_one_returns_entire_playlist(self): - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(name='a'), Track(name='b'), Track(name='c')]) result = self.h.handle_request(u'plchanges "-1"') self.assert_(u'Title: a' in result) @@ -334,7 +334,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_plchanges_without_quotes_works(self): - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(name='a'), Track(name='b'), Track(name='c')]) result = self.h.handle_request(u'plchanges 0') self.assert_(u'Title: a' in result) @@ -343,7 +343,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_plchangesposid(self): - self.b.current_playlist.load([Track(), Track(), Track()]) + self.b.current_playlist.append([Track(), Track(), Track()]) result = self.h.handle_request(u'plchangesposid "0"') self.assert_(u'cpos: 0' in result) self.assert_(u'Id: %d' % self.b.current_playlist.cp_tracks[0][0] @@ -357,7 +357,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_shuffle_without_range(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -367,7 +367,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_shuffle_with_open_range(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -381,7 +381,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_shuffle_with_closed_range(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -395,7 +395,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_swap(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) @@ -409,7 +409,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_swapid(self): - self.b.current_playlist.load([ + self.b.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'), ]) diff --git a/tests/frontends/mpd/playback_test.py b/tests/frontends/mpd/playback_test.py index ce3130bf..17263aef 100644 --- a/tests/frontends/mpd/playback_test.py +++ b/tests/frontends/mpd/playback_test.py @@ -174,7 +174,7 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_pause_off(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.append([Track()]) self.h.handle_request(u'play "0"') self.h.handle_request(u'pause "1"') result = self.h.handle_request(u'pause "0"') @@ -182,14 +182,14 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) def test_pause_on(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.append([Track()]) self.h.handle_request(u'play "0"') result = self.h.handle_request(u'pause "1"') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PAUSED, self.b.playback.state) def test_pause_toggle(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.append([Track()]) result = self.h.handle_request(u'play "0"') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) @@ -201,40 +201,40 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) def test_play_without_pos(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.append([Track()]) self.b.playback.state = self.b.playback.PAUSED result = self.h.handle_request(u'play') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) def test_play_with_pos(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.append([Track()]) result = self.h.handle_request(u'play "0"') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) def test_play_with_pos_without_quotes(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.append([Track()]) result = self.h.handle_request(u'play 0') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) def test_play_with_pos_out_of_bounds(self): - self.b.current_playlist.load([]) + self.b.current_playlist.append([]) result = self.h.handle_request(u'play "0"') self.assertEqual(result[0], u'ACK [2@0] {play} Bad song index') self.assertEqual(self.b.playback.STOPPED, self.b.playback.state) def test_play_minus_one_plays_first_in_playlist_if_no_current_track(self): self.assertEqual(self.b.playback.current_track, None) - self.b.current_playlist.load([Track(uri='a'), Track(uri='b')]) + self.b.current_playlist.append([Track(uri='a'), Track(uri='b')]) result = self.h.handle_request(u'play "-1"') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) self.assertEqual(self.b.playback.current_track.uri, 'a') def test_play_minus_one_plays_current_track_if_current_track_is_set(self): - self.b.current_playlist.load([Track(uri='a'), Track(uri='b')]) + self.b.current_playlist.append([Track(uri='a'), Track(uri='b')]) self.assertEqual(self.b.playback.current_track, None) self.b.playback.play() self.b.playback.next() @@ -253,21 +253,21 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assertEqual(self.b.playback.current_track, None) def test_playid(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.append([Track()]) result = self.h.handle_request(u'playid "1"') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) def test_playid_minus_one_plays_first_in_playlist_if_no_current_track(self): self.assertEqual(self.b.playback.current_track, None) - self.b.current_playlist.load([Track(uri='a'), Track(uri='b')]) + self.b.current_playlist.append([Track(uri='a'), Track(uri='b')]) result = self.h.handle_request(u'playid "-1"') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) self.assertEqual(self.b.playback.current_track.uri, 'a') def test_play_minus_one_plays_current_track_if_current_track_is_set(self): - self.b.current_playlist.load([Track(uri='a'), Track(uri='b')]) + self.b.current_playlist.append([Track(uri='a'), Track(uri='b')]) self.assertEqual(self.b.playback.current_track, None) self.b.playback.play() self.b.playback.next() @@ -286,7 +286,7 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assertEqual(self.b.playback.current_track, None) def test_playid_which_does_not_exist(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.append([Track()]) result = self.h.handle_request(u'playid "12345"') self.assertEqual(result[0], u'ACK [50@0] {playid} No such song') @@ -295,7 +295,7 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_seek(self): - self.b.current_playlist.load([Track(length=40000)]) + self.b.current_playlist.append([Track(length=40000)]) self.h.handle_request(u'seek "0"') result = self.h.handle_request(u'seek "0" "30"') self.assert_(u'OK' in result) @@ -303,20 +303,20 @@ class PlaybackControlHandlerTest(unittest.TestCase): def test_seek_with_songpos(self): seek_track = Track(uri='2', length=40000) - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(uri='1', length=40000), seek_track]) result = self.h.handle_request(u'seek "1" "30"') self.assertEqual(self.b.playback.current_track, seek_track) def test_seekid(self): - self.b.current_playlist.load([Track(length=40000)]) + self.b.current_playlist.append([Track(length=40000)]) result = self.h.handle_request(u'seekid "1" "30"') self.assert_(u'OK' in result) self.assert_(self.b.playback.time_position >= 30000) def test_seekid_with_cpid(self): seek_track = Track(uri='2', length=40000) - self.b.current_playlist.load( + self.b.current_playlist.append( [Track(length=40000), seek_track]) result = self.h.handle_request(u'seekid "2" "30"') self.assertEqual(self.b.playback.current_cpid, 2) diff --git a/tests/frontends/mpd/status_test.py b/tests/frontends/mpd/status_test.py index 907788f5..9839acfe 100644 --- a/tests/frontends/mpd/status_test.py +++ b/tests/frontends/mpd/status_test.py @@ -16,7 +16,7 @@ class StatusHandlerTest(unittest.TestCase): def test_currentsong(self): track = Track() - self.b.current_playlist.load([track]) + self.b.current_playlist.append([track]) self.b.playback.play() result = self.h.handle_request(u'currentsong') self.assert_(u'file: ' in result) @@ -155,21 +155,21 @@ class StatusHandlerTest(unittest.TestCase): self.assertEqual(result['state'], 'pause') def test_status_method_when_playlist_loaded_contains_song(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.append([Track()]) self.b.playback.play() result = dict(frontend.status.status(self.h)) self.assert_('song' in result) self.assert_(int(result['song']) >= 0) def test_status_method_when_playlist_loaded_contains_cpid_as_songid(self): - self.b.current_playlist.load([Track()]) + self.b.current_playlist.append([Track()]) self.b.playback.play() result = dict(frontend.status.status(self.h)) self.assert_('songid' in result) self.assertEqual(int(result['songid']), 1) def test_status_method_when_playing_contains_time_with_no_length(self): - self.b.current_playlist.load([Track(length=None)]) + self.b.current_playlist.append([Track(length=None)]) self.b.playback.play() result = dict(frontend.status.status(self.h)) self.assert_('time' in result) @@ -179,7 +179,7 @@ class StatusHandlerTest(unittest.TestCase): self.assert_(position <= total) def test_status_method_when_playing_contains_time_with_length(self): - self.b.current_playlist.load([Track(length=10000)]) + self.b.current_playlist.append([Track(length=10000)]) self.b.playback.play() result = dict(frontend.status.status(self.h)) self.assert_('time' in result) @@ -196,7 +196,7 @@ class StatusHandlerTest(unittest.TestCase): self.assertEqual(int(result['elapsed']), 59123) def test_status_method_when_playing_contains_bitrate(self): - self.b.current_playlist.load([Track(bitrate=320)]) + self.b.current_playlist.append([Track(bitrate=320)]) self.b.playback.play() result = dict(frontend.status.status(self.h)) self.assert_('bitrate' in result) From b41629658a02a577c526b896c2a82b71cbab1f9d Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 21:53:09 +0200 Subject: [PATCH 107/138] Update roadmap --- docs/development/roadmap.rst | 72 ++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/docs/development/roadmap.rst b/docs/development/roadmap.rst index 243243ab..f9588cb8 100644 --- a/docs/development/roadmap.rst +++ b/docs/development/roadmap.rst @@ -28,35 +28,51 @@ released when we reach the other goal. possible to have both Spotify tracks and local tracks in the same playlist. -Stuff we really want to do, but just not right now -================================================== +Stuff we want to do, but not right now, and maybe never +======================================================= -- **[PENDING]** Create `Homebrew `_ recipies - for all our dependencies and Mopidy itself to make OS X installation a - breeze. See `Homebrew's issue #1612 - `_. -- Create `Debian packages `_ of all our - dependencies and Mopidy itself (hosted in our own Debian repo until we get - stuff into the various distros) to make Debian/Ubuntu installation a breeze. -- Run frontend tests against a real MPD server to ensure we are in sync. -- Start working with MPD client maintainers to get rid of weird assumptions - like only searching for first two letters and doing the rest of the filtering - locally in the client, etc. +- Packaging and distribution: + - **[PENDING]** Create `Homebrew `_ + recipies for all our dependencies and Mopidy itself to make OS X + installation a breeze. See `Homebrew's issue #1612 + `_. + - Create `Debian packages `_ of all + our dependencies and Mopidy itself (hosted in our own Debian repo until we + get stuff into the various distros) to make Debian/Ubuntu installation a + breeze. -Crazy stuff we had to write down somewhere -========================================== +- Compatability: -- Add an `XMMS2 `_ frontend, so Mopidy can serve XMMS2 - clients. -- Add support for serving the music as an `Icecast `_ - stream instead of playing it locally. -- Integrate with `Squeezebox `_ in some - way. -- AirPort Express support, like in - `PulseAudio `_. -- DNLA and/or UPnP support. Maybe using - `Coherence `_. -- `Media Player Remote Interfacing Specification - `_ - support. + - Run frontend tests against a real MPD server to ensure we are in sync. + - Start working with MPD client maintainers to get rid of weird assumptions + like only searching for first two letters and doing the rest of the + filtering locally in the client (:issue:`1`), etc. + +- Backends: + + - `Last.fm `_ + - `WIMP `_ + - DNLA/UPnP to Mopidy can play music from other DNLA MediaServers. + +- Frontends: + + - D-Bus/`MPRIS `_ + - REST/JSON web service with a jQuery client as example application. Maybe + based upon `Tornado `_ and `jQuery + Mobile `_. + - DNLA/UPnP to Mopidy can be controlled from i.e. TVs. + - `XMMS2 `_ + - LIRC frontend for controlling Mopidy with a remote. + +- Mixers: + + - LIRC mixer for controlling arbitrary amplifiers remotely. + +- Audio streaming: + + - Ogg Vorbis/MP3 audio stream over HTTP, to MPD clients, `Squeezeboxes + `_, etc. + - Feed audio to an `Icecast `_ server. + - Stream to AirPort Express using `RAOP + `_. From b067c25b0c0afa9b2da6a4ce6efb2ea739b39e78 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 22:05:25 +0200 Subject: [PATCH 108/138] Update README --- README.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 350f959b..1e4430e2 100644 --- a/README.rst +++ b/README.rst @@ -2,10 +2,11 @@ Mopidy ****** -Mopidy is an `Music Player Daemon `_ (MPD) server with a -`Spotify `_ backend. Using a standard MPD client you -can search for music in Spotify's vast archive, manage Spotify playlists and -play music from Spotify. +Mopidy is a music server which can play music from `Spotify +`_ or from your local hard drive. To search for music +in Spotify's vast archive, manage playlists, and play music, you can use most +`MPD clients `_. MPD clients are available for most +platforms, including Windows, Mac OS X, Linux, and iPhone and Android phones. To install Mopidy, check out `the installation docs `_. @@ -14,4 +15,3 @@ To install Mopidy, check out * `Source code `_ * `Issue tracker `_ * IRC: ``#mopidy`` at `irc.freenode.net `_ -* `Presentation of Mopidy `_ From 4efc51e524b0df503c19094af9d1214292c0596f Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 22:13:22 +0200 Subject: [PATCH 109/138] Add link to donations page at Pledgie --- docs/authors.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/authors.rst b/docs/authors.rst index e21b79f6..f56242a5 100644 --- a/docs/authors.rst +++ b/docs/authors.rst @@ -8,3 +8,15 @@ Contributors to Mopidy in the order of appearance: - Johannes Knutsen - Thomas Adamcik - Kristian Klette + + +Donations +========= + +If you already enjoy Mopidy, or don't enjoy it and want to help us making +Mopidy better, you can `donate money `_ to +Mopidy's development. + +Any donated money will be used to cover service subscriptions (e.g. Spotify +and Last.fm) and hardware devices (e.g. an used iPod Touch for testing Mopidy +with MPod) needed for developing Mopidy. From 73258d6f9d412d2977ed4dedf084a4a95cb3d2e8 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 22:33:04 +0200 Subject: [PATCH 110/138] Reimplement 'load' using SPC.get() instead of search() --- docs/changes.rst | 7 ++++--- .../mpd/protocol/stored_playlists.py | 8 +++++--- tests/frontends/mpd/stored_playlists_test.py | 20 +++++++++++++++---- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index dfe46951..d5428a68 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -41,12 +41,13 @@ greatly improved MPD client support. - Support ``pause`` without arguments to work better with MPDroid. - Support ``plchanges``, ``play``, ``consume``, ``random``, ``repeat``, and ``single`` without quotes to work better with BitMPC. - - Fixed delete current playing track from playlist, which crashed several - clients. + - Fixed deletion of the currently playing track from the current playlist, + which crashed several clients. - Implement ``seek`` and ``seekid``. - Fix ``playlistfind`` output so the correct song is played when playing songs directly from search results in GMPC. - - Fix ``load`` so that one can append a playlist to the current playlist. + - Fix ``load`` so that one can append a playlist to the current playlist, and + make it return the correct error message if the playlist is not found. - Support for single track repeat added. (Fixes: :issue:`4`) - Rename ``mopidy.frontends.mpd.{serializer => translator}`` to match naming in backends. diff --git a/mopidy/frontends/mpd/protocol/stored_playlists.py b/mopidy/frontends/mpd/protocol/stored_playlists.py index 25ae4c32..39a2e150 100644 --- a/mopidy/frontends/mpd/protocol/stored_playlists.py +++ b/mopidy/frontends/mpd/protocol/stored_playlists.py @@ -91,9 +91,11 @@ def load(frontend, name): - ``load`` appends the given playlist to the current playlist. """ - matches = frontend.backend.stored_playlists.search(name) - if matches: - frontend.backend.current_playlist.append(matches[0].tracks) + try: + playlist = frontend.backend.stored_playlists.get(name=name) + frontend.backend.current_playlist.append(playlist.tracks) + except LookupError as e: + raise MpdNoExistError(u'No such playlist', command=u'load') @handle_pattern(r'^playlistadd "(?P[^"]+)" "(?P[^"]+)"$') def playlistadd(frontend, name, uri): diff --git a/tests/frontends/mpd/stored_playlists_test.py b/tests/frontends/mpd/stored_playlists_test.py index 9babc670..b49ccce1 100644 --- a/tests/frontends/mpd/stored_playlists_test.py +++ b/tests/frontends/mpd/stored_playlists_test.py @@ -49,12 +49,24 @@ class StoredPlaylistsHandlerTest(unittest.TestCase): self.assert_(u'Last-Modified: 2001-03-17T13:41:17Z' in result) self.assert_(u'OK' in result) - def test_load(self): - result = self.h.handle_request(u'load "name"') + def test_load_known_playlist_appends_to_current_playlist(self): + self.b.current_playlist.append([Track(uri='a'), Track(uri='b')]) + self.assertEqual(len(self.b.current_playlist.tracks), 2) + self.b.stored_playlists.playlists = [Playlist(name='A-list', + tracks=[Track(uri='c'), Track(uri='d'), Track(uri='e')])] + result = self.h.handle_request(u'load "A-list"') self.assert_(u'OK' in result) + self.assertEqual(len(self.b.current_playlist.tracks), 5) + self.assertEqual(self.b.current_playlist.tracks[0].uri, 'a') + self.assertEqual(self.b.current_playlist.tracks[1].uri, 'b') + self.assertEqual(self.b.current_playlist.tracks[2].uri, 'c') + self.assertEqual(self.b.current_playlist.tracks[3].uri, 'd') + self.assertEqual(self.b.current_playlist.tracks[4].uri, 'e') - def test_load_appends(self): - raise SkipTest + def test_load_unknown_playlist_acks(self): + result = self.h.handle_request(u'load "unknown playlist"') + self.assert_(u'ACK [50@0] {load} No such playlist' in result) + self.assertEqual(len(self.b.current_playlist.tracks), 0) def test_playlistadd(self): result = self.h.handle_request( From 7674775718f54b49b765f19d45202637ec41c569 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Mon, 16 Aug 2010 22:34:00 +0200 Subject: [PATCH 111/138] Don't call lookup on backends with uris they don't support --- mopidy/frontends/mpd/protocol/current_playlist.py | 14 +++++++++----- tests/frontends/mpd/current_playlist_test.py | 6 ++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index 17b019e9..0dab4b79 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -11,11 +11,15 @@ def add(frontend, uri): Adds the file ``URI`` to the playlist (directories add recursively). ``URI`` can also be a single file. """ - track = frontend.backend.library.lookup(uri) - if track is None: - raise MpdNoExistError( - u'directory or file not found', command=u'add') - frontend.backend.current_playlist.add(track) + for handler_prefix in frontend.backend.uri_handlers: + if uri.startswith(handler_prefix): + track = frontend.backend.library.lookup(uri) + if track is not None: + frontend.backend.current_playlist.add(track) + return + + raise MpdNoExistError( + u'directory or file not found', command=u'add') @handle_pattern(r'^addid "(?P[^"]*)"( "(?P\d+)")*$') def addid(frontend, uri, songpos=None): diff --git a/tests/frontends/mpd/current_playlist_test.py b/tests/frontends/mpd/current_playlist_test.py index 6b5c822e..5bd110e0 100644 --- a/tests/frontends/mpd/current_playlist_test.py +++ b/tests/frontends/mpd/current_playlist_test.py @@ -22,6 +22,12 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assertEqual(len(result), 1) self.assert_(u'OK' in result) + def test_add_with_uri_not_found_in_library_should_not_call_lookup(self): + self.b.library.lookup = lambda uri: self.fail("Shouldn't run") + result = self.h.handle_request(u'add "foo"') + self.assertEqual(result[0], + u'ACK [50@0] {add} directory or file not found') + def test_add_with_uri_not_found_in_library_should_ack(self): result = self.h.handle_request(u'add "dummy://foo"') self.assertEqual(result[0], From c4dc6164d5c3301ac7a8af75a0e7b9698c8acc55 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 22:36:02 +0200 Subject: [PATCH 112/138] Remove SPC.search() --- docs/changes.rst | 4 ++++ mopidy/backends/base/stored_playlists.py | 10 ---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index d5428a68..37e0d202 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -107,6 +107,10 @@ greatly improved MPD client support. - Rename :meth:`mopidy.backends.base.BasePlaybackController.end_of_track_callback()` to :meth:`mopidy.backends.base.BasePlaybackController.on_end_of_track()`. + - Remove :meth:`mopidy.backends.base.BaseStoredPlaylistsController.search()` + since it was barely used, untested, and we got no use case for non-exact + search in stored playlists yet. Use + :meth:`mopidy.backends.base.BaseStoredPlaylistsController.get()` instead. 0.1.0a3 (2010-08-03) diff --git a/mopidy/backends/base/stored_playlists.py b/mopidy/backends/base/stored_playlists.py index 31185cd4..61722c81 100644 --- a/mopidy/backends/base/stored_playlists.py +++ b/mopidy/backends/base/stored_playlists.py @@ -107,13 +107,3 @@ class BaseStoredPlaylistsController(object): :type playlist: :class:`mopidy.models.Playlist` """ raise NotImplementedError - - def search(self, query): - """ - Search for playlists whose name contains ``query``. - - :param query: query to search for - :type query: string - :rtype: list of :class:`mopidy.models.Playlist` - """ - return filter(lambda p: query in p.name, self._playlists) From b313d6bf74c07e0852989e97d56c2a13d34ba5d1 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 22:56:24 +0200 Subject: [PATCH 113/138] Mark settings in changelog properly, to get links to settings reference docs --- docs/changes.rst | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 37e0d202..323f899e 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -22,8 +22,11 @@ greatly improved MPD client support. `. - If you used :mod:`mopidy.backends.libspotify` previously, pyspotify must be updated when updating to this release, to get working seek functionality. -- The settings ``SERVER_HOSTNAME`` and ``SERVER_PORT`` has been renamed to - ``MPD_SERVER_HOSTNAME`` and ``MPD_SERVER_PORT``. +- :attr:`mopidy.settings.SERVER_HOSTNAME` and + :attr:`mopidy.settings.SERVER_PORT` has been renamed to + :attr:`mopidy.settings.MPD_SERVER_HOSTNAME` and + :attr:`mopidy.settings.MPD_SERVER_PORT` to allow for multiple frontends in + the future. **Changes** @@ -58,15 +61,16 @@ greatly improved MPD client support. - Remove :mod:`mopidy.backends.despotify`, as Despotify is little maintained and the Libspotify backend is working much better. (Fixes: :issue:`9`, :issue:`10`, :issue:`13`) - - A Spotify application key is now bundled with the source. The - ``SPOTIFY_LIB_APPKEY`` setting is thus removed. + - A Spotify application key is now bundled with the source. + :attr:`mopidy.settings.SPOTIFY_LIB_APPKEY` is thus removed. - If failing to play a track, playback will skip to the next track. - Mixers: - - Added new :mod:`mopidy.mixers.GStreamerSoftwareMixer` which now is the - default mixer on all platforms. - - New setting ``MIXER_MAX_VOLUME`` for capping the maximum output volume. + - Added new :mod:`mopidy.mixers.gstreamer_software.GStreamerSoftwareMixer` + which now is the default mixer on all platforms. + - New setting :attr:`mopidy.settings.MIXER_MAX_VOLUME` for capping the + maximum output volume. - Backend API: From 87e489a26ddae4c6c540504414f5d192152b1f34 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Mon, 16 Aug 2010 23:55:00 +0200 Subject: [PATCH 114/138] rearranged test_next tests --- tests/backends/base.py | 164 ++++++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/tests/backends/base.py b/tests/backends/base.py index 31892de2..fa35f382 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -365,6 +365,56 @@ class BasePlaybackControllerTest(object): self.assertEqual(self.playback.state, self.playback.STOPPED) self.assertEqual(self.playback.current_track, None) + @populate_playlist + def test_previous(self): + self.playback.play() + self.playback.next() + self.playback.previous() + self.assertEqual(self.playback.current_track, self.tracks[0]) + + @populate_playlist + def test_previous_more(self): + self.playback.play() # At track 0 + self.playback.next() # At track 1 + self.playback.next() # At track 2 + self.playback.previous() # At track 1 + self.assertEqual(self.playback.current_track, self.tracks[1]) + + @populate_playlist + def test_previous_return_value(self): + self.playback.play() + self.playback.next() + self.assertEqual(self.playback.previous(), None) + + @populate_playlist + def test_previous_does_not_trigger_playback(self): + self.playback.play() + self.playback.next() + self.playback.stop() + self.playback.previous() + self.assertEqual(self.playback.state, self.playback.STOPPED) + + @populate_playlist + def test_previous_at_start_of_playlist(self): + self.playback.previous() + self.assertEqual(self.playback.state, self.playback.STOPPED) + self.assertEqual(self.playback.current_track, None) + + def test_previous_for_empty_playlist(self): + self.playback.previous() + self.assertEqual(self.playback.state, self.playback.STOPPED) + self.assertEqual(self.playback.current_track, None) + + @populate_playlist + def test_previous_skips_to_previous_track_on_failure(self): + # If _play() returns False, it is a failure. + self.playback._play = lambda track: track != self.tracks[1] + self.playback.play(self.current_playlist.cp_tracks[2]) + self.assertEqual(self.playback.current_track, self.tracks[2]) + self.playback.previous() + self.assertNotEqual(self.playback.current_track, self.tracks[1]) + self.assertEqual(self.playback.current_track, self.tracks[0]) + @populate_playlist def test_next(self): self.playback.play() @@ -429,56 +479,6 @@ class BasePlaybackControllerTest(object): self.assertNotEqual(self.playback.current_track, self.tracks[1]) self.assertEqual(self.playback.current_track, self.tracks[2]) - @populate_playlist - def test_previous(self): - self.playback.play() - self.playback.next() - self.playback.previous() - self.assertEqual(self.playback.current_track, self.tracks[0]) - - @populate_playlist - def test_previous_more(self): - self.playback.play() # At track 0 - self.playback.next() # At track 1 - self.playback.next() # At track 2 - self.playback.previous() # At track 1 - self.assertEqual(self.playback.current_track, self.tracks[1]) - - @populate_playlist - def test_previous_return_value(self): - self.playback.play() - self.playback.next() - self.assertEqual(self.playback.previous(), None) - - @populate_playlist - def test_previous_does_not_trigger_playback(self): - self.playback.play() - self.playback.next() - self.playback.stop() - self.playback.previous() - self.assertEqual(self.playback.state, self.playback.STOPPED) - - @populate_playlist - def test_previous_at_start_of_playlist(self): - self.playback.previous() - self.assertEqual(self.playback.state, self.playback.STOPPED) - self.assertEqual(self.playback.current_track, None) - - def test_previous_for_empty_playlist(self): - self.playback.previous() - self.assertEqual(self.playback.state, self.playback.STOPPED) - self.assertEqual(self.playback.current_track, None) - - @populate_playlist - def test_previous_skips_to_previous_track_on_failure(self): - # If _play() returns False, it is a failure. - self.playback._play = lambda track: track != self.tracks[1] - self.playback.play(self.current_playlist.cp_tracks[2]) - self.assertEqual(self.playback.current_track, self.tracks[2]) - self.playback.previous() - self.assertNotEqual(self.playback.current_track, self.tracks[1]) - self.assertEqual(self.playback.current_track, self.tracks[0]) - @populate_playlist def test_next_track_before_play(self): self.assertEqual(self.playback.next_track, self.tracks[0]) @@ -519,6 +519,38 @@ class BasePlaybackControllerTest(object): self.playback.random = True self.assertEqual(self.playback.next_track, self.tracks[2]) + @populate_playlist + def test_next_with_consume(self): + self.playback.consume = True + self.playback.play() + self.playback.next() + self.assert_(self.tracks[0] in self.backend.current_playlist.tracks) + + @populate_playlist + def test_next_with_single_and_repeat(self): + self.playback.single = True + self.playback.repeat = True + self.playback.play() + self.playback.next() + self.assertEqual(self.playback.current_track, self.tracks[1]) + + @populate_playlist + def test_next_with_random(self): + # FIXME feels very fragile + random.seed(1) + self.playback.random = True + self.playback.play() + self.playback.next() + self.assertEqual(self.playback.current_track, self.tracks[1]) + + @populate_playlist + def test_next_track_with_random_after_load_playlist(self): + random.seed(1) + self.playback.random = True + self.assertEqual(self.playback.next_track, self.tracks[2]) + self.backend.current_playlist.load(self.tracks[:1]) + self.assertEqual(self.playback.next_track, self.tracks[1]) + @populate_playlist def test_previous_track_before_play(self): self.assertEqual(self.playback.previous_track, None) @@ -827,13 +859,6 @@ class BasePlaybackControllerTest(object): self.playback.play() self.assertEqual(self.playback.current_track, self.tracks[0]) - @populate_playlist - def test_next_with_consume(self): - self.playback.consume = True - self.playback.play() - self.playback.next() - self.assert_(self.tracks[0] in self.backend.current_playlist.tracks) - @populate_playlist def test_end_of_track_with_consume(self): self.playback.consume = True @@ -841,14 +866,6 @@ class BasePlaybackControllerTest(object): self.playback.end_of_track_callback() self.assert_(self.tracks[0] not in self.backend.current_playlist.tracks) - @populate_playlist - def test_next_with_single_and_repeat(self): - self.playback.single = True - self.playback.repeat = True - self.playback.play() - self.playback.next() - self.assertEqual(self.playback.current_track, self.tracks[1]) - @populate_playlist def test_playlist_is_empty_after_all_tracks_are_played_with_consume(self): self.playback.consume = True @@ -864,15 +881,6 @@ class BasePlaybackControllerTest(object): self.playback.play() self.assertEqual(self.playback.current_track, self.tracks[2]) - @populate_playlist - def test_next_with_random(self): - # FIXME feels very fragile - random.seed(1) - self.playback.random = True - self.playback.play() - self.playback.next() - self.assertEqual(self.playback.current_track, self.tracks[1]) - @populate_playlist def test_previous_with_random(self): random.seed(1) @@ -939,14 +947,6 @@ class BasePlaybackControllerTest(object): self.playback.next() self.assertNotEqual(self.playback.next_track, None) - @populate_playlist - def test_next_track_with_random_after_load_playlist(self): - random.seed(1) - self.playback.random = True - self.assertEqual(self.playback.next_track, self.tracks[2]) - self.backend.current_playlist.load(self.tracks[:1]) - self.assertEqual(self.playback.next_track, self.tracks[1]) - @populate_playlist def test_played_track_during_random_not_played_again(self): self.playback.random = True From 664c731f77d892f67999b03e6ed7adac940d5219 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 16 Aug 2010 23:57:23 +0200 Subject: [PATCH 115/138] Remove unused variable --- mopidy/frontends/mpd/protocol/stored_playlists.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mopidy/frontends/mpd/protocol/stored_playlists.py b/mopidy/frontends/mpd/protocol/stored_playlists.py index 39a2e150..3d7a8710 100644 --- a/mopidy/frontends/mpd/protocol/stored_playlists.py +++ b/mopidy/frontends/mpd/protocol/stored_playlists.py @@ -94,7 +94,7 @@ def load(frontend, name): try: playlist = frontend.backend.stored_playlists.get(name=name) frontend.backend.current_playlist.append(playlist.tracks) - except LookupError as e: + except LookupError: raise MpdNoExistError(u'No such playlist', command=u'load') @handle_pattern(r'^playlistadd "(?P[^"]+)" "(?P[^"]+)"$') From b5026439106df13913443e8e8b342d7bf33c96d6 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Tue, 17 Aug 2010 00:01:20 +0200 Subject: [PATCH 116/138] added the same tests for end_of_track_callback as was for next --- tests/backends/base.py | 144 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 137 insertions(+), 7 deletions(-) diff --git a/tests/backends/base.py b/tests/backends/base.py index fa35f382..6fb978c9 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -551,6 +551,143 @@ class BasePlaybackControllerTest(object): self.backend.current_playlist.load(self.tracks[:1]) self.assertEqual(self.playback.next_track, self.tracks[1]) + @populate_playlist + def test_end_of_track(self): + self.playback.play() + + old_position = self.playback.current_playlist_position + old_uri = self.playback.current_track.uri + + self.playback.end_of_track_callback() + + self.assertEqual(self.playback.current_playlist_position, + old_position+1) + self.assertNotEqual(self.playback.current_track.uri, old_uri) + + @populate_playlist + def test_end_of_track_return_value(self): + self.playback.play() + self.assertEqual(self.playback.end_of_track_callback(), None) + + @populate_playlist + def test_end_of_track_does_not_trigger_playback(self): + self.playback.end_of_track_callback() + self.assertEqual(self.playback.state, self.playback.STOPPED) + + @populate_playlist + def test_end_of_track_at_end_of_playlist(self): + self.playback.play() + + for i, track in enumerate(self.tracks): + self.assertEqual(self.playback.state, self.playback.PLAYING) + self.assertEqual(self.playback.current_track, track) + self.assertEqual(self.playback.current_playlist_position, i) + + self.playback.end_of_track_callback() + + self.assertEqual(self.playback.state, self.playback.STOPPED) + + @populate_playlist + def test_end_of_track_until_end_of_playlist_and_play_from_start(self): + self.playback.play() + + for track in self.tracks: + self.playback.end_of_track_callback() + + self.assertEqual(self.playback.current_track, None) + self.assertEqual(self.playback.state, self.playback.STOPPED) + + self.playback.play() + self.assertEqual(self.playback.state, self.playback.PLAYING) + self.assertEqual(self.playback.current_track, self.tracks[0]) + + def test_end_of_track_for_empty_playlist(self): + self.playback.end_of_track_callback() + self.assertEqual(self.playback.state, self.playback.STOPPED) + + @populate_playlist + def test_end_of_track_skips_to_next_track_on_failure(self): + # If _play() returns False, it is a failure. + self.playback._play = lambda track: track != self.tracks[1] + self.playback.play() + self.assertEqual(self.playback.current_track, self.tracks[0]) + self.playback.end_of_track_callback() + self.assertNotEqual(self.playback.current_track, self.tracks[1]) + self.assertEqual(self.playback.current_track, self.tracks[2]) + + @populate_playlist + def test_end_of_track_track_before_play(self): + self.assertEqual(self.playback.next_track, self.tracks[0]) + + @populate_playlist + def test_end_of_track_track_during_play(self): + self.playback.play() + self.assertEqual(self.playback.next_track, self.tracks[1]) + + @populate_playlist + def test_end_of_track_track_after_previous(self): + self.playback.play() + self.playback.end_of_track_callback() + self.playback.previous() + self.assertEqual(self.playback.next_track, self.tracks[1]) + + def test_end_of_track_track_empty_playlist(self): + self.assertEqual(self.playback.next_track, None) + + @populate_playlist + def test_end_of_track_track_at_end_of_playlist(self): + self.playback.play() + for track in self.current_playlist.cp_tracks[1:]: + self.playback.end_of_track_callback() + self.assertEqual(self.playback.next_track, None) + + @populate_playlist + def test_end_of_track_track_at_end_of_playlist_with_repeat(self): + self.playback.repeat = True + self.playback.play() + for track in self.tracks[1:]: + self.playback.end_of_track_callback() + self.assertEqual(self.playback.next_track, self.tracks[0]) + + @populate_playlist + def test_end_of_track_track_with_random(self): + random.seed(1) + self.playback.random = True + self.assertEqual(self.playback.next_track, self.tracks[2]) + + + @populate_playlist + def test_end_of_track_with_consume(self): + self.playback.consume = True + self.playback.play() + self.playback.end_of_track_callback() + self.assert_(self.tracks[0] not in self.backend.current_playlist.tracks) + + @populate_playlist + def test_end_of_track_with_single_and_repeat(self): + self.playback.single = True + self.playback.repeat = True + self.playback.play() + self.playback.end_of_track_callback() + self.assertEqual(self.playback.current_track, self.tracks[1]) + + @populate_playlist + def test_end_of_track_with_random(self): + # FIXME feels very fragile + random.seed(1) + self.playback.random = True + self.playback.play() + self.playback.end_of_track_callback() + self.assertEqual(self.playback.current_track, self.tracks[1]) + + @populate_playlist + def test_end_of_track_track_with_random_after_load_playlist(self): + random.seed(1) + self.playback.random = True + self.assertEqual(self.playback.next_track, self.tracks[2]) + self.backend.current_playlist.load(self.tracks[:1]) + self.assertEqual(self.playback.next_track, self.tracks[1]) + @populate_playlist def test_previous_track_before_play(self): self.assertEqual(self.playback.previous_track, None) @@ -859,13 +996,6 @@ class BasePlaybackControllerTest(object): self.playback.play() self.assertEqual(self.playback.current_track, self.tracks[0]) - @populate_playlist - def test_end_of_track_with_consume(self): - self.playback.consume = True - self.playback.play() - self.playback.end_of_track_callback() - self.assert_(self.tracks[0] not in self.backend.current_playlist.tracks) - @populate_playlist def test_playlist_is_empty_after_all_tracks_are_played_with_consume(self): self.playback.consume = True From b32dfee65eea9513d122577125c6edc941e4c2e0 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Tue, 17 Aug 2010 00:18:46 +0200 Subject: [PATCH 117/138] rename end_of_track_callback to on_end_of_track --- tests/backends/base.py | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/backends/base.py b/tests/backends/base.py index 6fb978c9..f341ab48 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -356,7 +356,7 @@ class BasePlaybackControllerTest(object): @populate_playlist def test_current_track_after_completed_playlist(self): self.playback.play(self.current_playlist.cp_tracks[-1]) - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.state, self.playback.STOPPED) self.assertEqual(self.playback.current_track, None) @@ -558,7 +558,7 @@ class BasePlaybackControllerTest(object): old_position = self.playback.current_playlist_position old_uri = self.playback.current_track.uri - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.current_playlist_position, old_position+1) @@ -567,11 +567,11 @@ class BasePlaybackControllerTest(object): @populate_playlist def test_end_of_track_return_value(self): self.playback.play() - self.assertEqual(self.playback.end_of_track_callback(), None) + self.assertEqual(self.playback.on_end_of_track(), None) @populate_playlist def test_end_of_track_does_not_trigger_playback(self): - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.state, self.playback.STOPPED) @populate_playlist @@ -583,7 +583,7 @@ class BasePlaybackControllerTest(object): self.assertEqual(self.playback.current_track, track) self.assertEqual(self.playback.current_playlist_position, i) - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.state, self.playback.STOPPED) @@ -592,7 +592,7 @@ class BasePlaybackControllerTest(object): self.playback.play() for track in self.tracks: - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.current_track, None) self.assertEqual(self.playback.state, self.playback.STOPPED) @@ -602,7 +602,7 @@ class BasePlaybackControllerTest(object): self.assertEqual(self.playback.current_track, self.tracks[0]) def test_end_of_track_for_empty_playlist(self): - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.state, self.playback.STOPPED) @populate_playlist @@ -611,7 +611,7 @@ class BasePlaybackControllerTest(object): self.playback._play = lambda track: track != self.tracks[1] self.playback.play() self.assertEqual(self.playback.current_track, self.tracks[0]) - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertNotEqual(self.playback.current_track, self.tracks[1]) self.assertEqual(self.playback.current_track, self.tracks[2]) @@ -627,7 +627,7 @@ class BasePlaybackControllerTest(object): @populate_playlist def test_end_of_track_track_after_previous(self): self.playback.play() - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.playback.previous() self.assertEqual(self.playback.next_track, self.tracks[1]) @@ -638,7 +638,7 @@ class BasePlaybackControllerTest(object): def test_end_of_track_track_at_end_of_playlist(self): self.playback.play() for track in self.current_playlist.cp_tracks[1:]: - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.next_track, None) @populate_playlist @@ -646,7 +646,7 @@ class BasePlaybackControllerTest(object): self.playback.repeat = True self.playback.play() for track in self.tracks[1:]: - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.next_track, self.tracks[0]) @populate_playlist @@ -660,7 +660,7 @@ class BasePlaybackControllerTest(object): def test_end_of_track_with_consume(self): self.playback.consume = True self.playback.play() - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assert_(self.tracks[0] not in self.backend.current_playlist.tracks) @populate_playlist @@ -668,7 +668,7 @@ class BasePlaybackControllerTest(object): self.playback.single = True self.playback.repeat = True self.playback.play() - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.current_track, self.tracks[1]) @populate_playlist @@ -677,7 +677,7 @@ class BasePlaybackControllerTest(object): random.seed(1) self.playback.random = True self.playback.play() - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.current_track, self.tracks[1]) @populate_playlist @@ -763,7 +763,7 @@ class BasePlaybackControllerTest(object): @populate_playlist def test_current_playlist_position_at_end_of_playlist(self): self.playback.play(self.current_playlist.cp_tracks[-1]) - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.current_playlist_position, None) def test_on_current_playlist_change_gets_called(self): @@ -780,16 +780,16 @@ class BasePlaybackControllerTest(object): self.assert_(wrapper.called) @populate_playlist - def test_end_of_track_callback_gets_called(self): - end_of_track_callback = self.playback.end_of_track_callback + def test_on_end_of_track_gets_called(self): + on_end_of_track = self.playback.on_end_of_track event = threading.Event() def wrapper(): - result = end_of_track_callback() + result = on_end_of_track() event.set() return result - self.playback.end_of_track_callback = wrapper + self.playback.on_end_of_track = wrapper self.playback.play() self.playback.seek(self.tracks[0].length - 10) @@ -1001,7 +1001,7 @@ class BasePlaybackControllerTest(object): self.playback.consume = True self.playback.play() for i in range(len(self.backend.current_playlist.tracks)): - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(len(self.backend.current_playlist.tracks), 0) @populate_playlist @@ -1024,7 +1024,7 @@ class BasePlaybackControllerTest(object): @populate_playlist def test_end_of_song_starts_next_track(self): self.playback.play() - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.current_track, self.tracks[1]) @populate_playlist @@ -1032,13 +1032,13 @@ class BasePlaybackControllerTest(object): self.playback.single = True self.playback.repeat = True self.playback.play() - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.current_track, self.tracks[0]) @populate_playlist def test_end_of_playlist_stops(self): self.playback.play(self.current_playlist.cp_tracks[-1]) - self.playback.end_of_track_callback() + self.playback.on_end_of_track() self.assertEqual(self.playback.state, self.playback.STOPPED) def test_repeat_off_by_default(self): From e4edd70c6d419cb6892827fdfcdb10c2b856462b Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 17 Aug 2010 00:32:31 +0200 Subject: [PATCH 118/138] Split mopidy.utils into smaller pieces --- mopidy/backends/local/__init__.py | 4 +- .../local/translator.py} | 51 +---------- mopidy/utils/__init__.py | 38 ++++++++ mopidy/utils/path.py | 21 +++++ tests/backends/local/__init__.py | 0 .../{local_test.py => local/backend_test.py} | 2 +- .../local/translator_test.py} | 88 +------------------ tests/outputs/gstreamer_test.py | 6 +- tests/utils/__init__.py | 0 tests/utils/init_test.py | 22 +++++ tests/utils/path_test.py | 71 +++++++++++++++ 11 files changed, 163 insertions(+), 140 deletions(-) rename mopidy/{utils.py => backends/local/translator.py} (68%) create mode 100644 mopidy/utils/__init__.py create mode 100644 mopidy/utils/path.py create mode 100644 tests/backends/local/__init__.py rename tests/backends/{local_test.py => local/backend_test.py} (99%) rename tests/{utils_test.py => backends/local/translator_test.py} (57%) create mode 100644 tests/utils/__init__.py create mode 100644 tests/utils/init_test.py create mode 100644 tests/utils/path_test.py diff --git a/mopidy/backends/local/__init__.py b/mopidy/backends/local/__init__.py index 87d2f7c0..434492bf 100644 --- a/mopidy/backends/local/__init__.py +++ b/mopidy/backends/local/__init__.py @@ -14,10 +14,10 @@ import glob import shutil import threading +from mopidy import settings from mopidy.backends.base import * from mopidy.models import Playlist, Track, Album -from mopidy import settings -from mopidy.utils import parse_m3u, parse_mpd_tag_cache +from .translator import parse_m3u, parse_mpd_tag_cache logger = logging.getLogger(u'mopidy.backends.local') diff --git a/mopidy/utils.py b/mopidy/backends/local/translator.py similarity index 68% rename from mopidy/utils.py rename to mopidy/backends/local/translator.py index bdc0b632..ac69373a 100644 --- a/mopidy/utils.py +++ b/mopidy/backends/local/translator.py @@ -3,57 +3,10 @@ import os import sys import urllib -logger = logging.getLogger('mopidy.utils') +logger = logging.getLogger('mopidy.backends.local.translator') from mopidy.models import Track, Artist, Album - -def flatten(the_list): - result = [] - for element in the_list: - if isinstance(element, list): - result.extend(flatten(element)) - else: - result.append(element) - return result - -def import_module(name): - __import__(name) - return sys.modules[name] - -def get_class(name): - module_name = name[:name.rindex('.')] - class_name = name[name.rindex('.') + 1:] - logger.debug('Loading: %s', name) - try: - module = import_module(module_name) - class_object = getattr(module, class_name) - except (ImportError, AttributeError): - raise ImportError("Couldn't load: %s" % name) - return class_object - -def get_or_create_folder(folder): - folder = os.path.expanduser(folder) - if not os.path.isdir(folder): - logger.info(u'Creating %s', folder) - os.mkdir(folder, 0755) - return folder - -def path_to_uri(*paths): - path = os.path.join(*paths) - #path = os.path.expanduser(path) # FIXME - path = path.encode('utf-8') - if sys.platform == 'win32': - return 'file:' + urllib.pathname2url(path) - return 'file://' + urllib.pathname2url(path) - -def indent(string, places=4, linebreak='\n'): - lines = string.split(linebreak) - if len(lines) == 1: - return string - result = u'' - for line in lines: - result += linebreak + ' ' * places + line - return result +from mopidy.utils.path import path_to_uri def parse_m3u(file_path): """ diff --git a/mopidy/utils/__init__.py b/mopidy/utils/__init__.py new file mode 100644 index 00000000..277d2f3b --- /dev/null +++ b/mopidy/utils/__init__.py @@ -0,0 +1,38 @@ +import logging +import os +import sys + +logger = logging.getLogger('mopidy.utils') + +def flatten(the_list): + result = [] + for element in the_list: + if isinstance(element, list): + result.extend(flatten(element)) + else: + result.append(element) + return result + +def import_module(name): + __import__(name) + return sys.modules[name] + +def get_class(name): + module_name = name[:name.rindex('.')] + class_name = name[name.rindex('.') + 1:] + logger.debug('Loading: %s', name) + try: + module = import_module(module_name) + class_object = getattr(module, class_name) + except (ImportError, AttributeError): + raise ImportError("Couldn't load: %s" % name) + return class_object + +def indent(string, places=4, linebreak='\n'): + lines = string.split(linebreak) + if len(lines) == 1: + return string + result = u'' + for line in lines: + result += linebreak + ' ' * places + line + return result diff --git a/mopidy/utils/path.py b/mopidy/utils/path.py new file mode 100644 index 00000000..002b54c8 --- /dev/null +++ b/mopidy/utils/path.py @@ -0,0 +1,21 @@ +import logging +import os +import sys +import urllib + +logger = logging.getLogger('mopidy.utils.path') + +def get_or_create_folder(folder): + folder = os.path.expanduser(folder) + if not os.path.isdir(folder): + logger.info(u'Creating %s', folder) + os.mkdir(folder, 0755) + return folder + +def path_to_uri(*paths): + path = os.path.join(*paths) + #path = os.path.expanduser(path) # FIXME Waiting for test case? + path = path.encode('utf-8') + if sys.platform == 'win32': + return 'file:' + urllib.pathname2url(path) + return 'file://' + urllib.pathname2url(path) diff --git a/tests/backends/local/__init__.py b/tests/backends/local/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/backends/local_test.py b/tests/backends/local/backend_test.py similarity index 99% rename from tests/backends/local_test.py rename to tests/backends/local/backend_test.py index a5222276..7215e8eb 100644 --- a/tests/backends/local_test.py +++ b/tests/backends/local/backend_test.py @@ -11,7 +11,7 @@ from mopidy import settings from mopidy.backends.local import LocalBackend from mopidy.mixers.dummy import DummyMixer from mopidy.models import Playlist, Track -from mopidy.utils import path_to_uri +from mopidy.utils.path import path_to_uri from tests.backends.base import * from tests import SkipTest, data_folder diff --git a/tests/utils_test.py b/tests/backends/local/translator_test.py similarity index 57% rename from tests/utils_test.py rename to tests/backends/local/translator_test.py index ca44de45..a9fe58d8 100644 --- a/tests/utils_test.py +++ b/tests/backends/local/translator_test.py @@ -1,96 +1,15 @@ -#encoding: utf-8 +# encoding: utf-8 import os -import sys -import shutil import tempfile import unittest -from mopidy.utils import * +from mopidy.utils.path import path_to_uri +from mopidy.backends.local.translator import parse_m3u, parse_mpd_tag_cache from mopidy.models import Track, Artist, Album from tests import SkipTest, data_folder -class GetClassTest(unittest.TestCase): - def test_loading_module_that_does_not_exist(self): - test = lambda: get_class('foo.bar.Baz') - self.assertRaises(ImportError, test) - - def test_loading_class_that_does_not_exist(self): - test = lambda: get_class('unittest.FooBarBaz') - self.assertRaises(ImportError, test) - - def test_import_error_message_contains_complete_class_path(self): - try: - get_class('foo.bar.Baz') - except ImportError as e: - self.assert_('foo.bar.Baz' in str(e)) - - def test_loading_existing_class(self): - cls = get_class('unittest.TestCase') - self.assertEqual(cls.__name__, 'TestCase') - -class GetOrCreateFolderTest(unittest.TestCase): - def setUp(self): - self.parent = tempfile.mkdtemp() - - def tearDown(self): - if os.path.isdir(self.parent): - shutil.rmtree(self.parent) - - def test_creating_folder(self): - folder = os.path.join(self.parent, 'test') - self.assert_(not os.path.exists(folder)) - self.assert_(not os.path.isdir(folder)) - created = get_or_create_folder(folder) - self.assert_(os.path.exists(folder)) - self.assert_(os.path.isdir(folder)) - self.assertEqual(created, folder) - - def test_creating_existing_folder(self): - created = get_or_create_folder(self.parent) - self.assert_(os.path.exists(self.parent)) - self.assert_(os.path.isdir(self.parent)) - self.assertEqual(created, self.parent) - - def test_that_userfolder_is_expanded(self): - raise SkipTest # Not sure how to safely test this - - -class PathToFileURITest(unittest.TestCase): - def test_simple_path(self): - if sys.platform == 'win32': - result = path_to_uri(u'C:/WINDOWS/clock.avi') - self.assertEqual(result, 'file:///C://WINDOWS/clock.avi') - else: - result = path_to_uri(u'/etc/fstab') - self.assertEqual(result, 'file:///etc/fstab') - - def test_folder_and_path(self): - if sys.platform == 'win32': - result = path_to_uri(u'C:/WINDOWS/', u'clock.avi') - self.assertEqual(result, 'file:///C://WINDOWS/clock.avi') - else: - result = path_to_uri(u'/etc', u'fstab') - self.assertEqual(result, u'file:///etc/fstab') - - def test_space_in_path(self): - if sys.platform == 'win32': - result = path_to_uri(u'C:/test this') - self.assertEqual(result, 'file:///C://test%20this') - else: - result = path_to_uri(u'/tmp/test this') - self.assertEqual(result, u'file:///tmp/test%20this') - - def test_unicode_in_path(self): - if sys.platform == 'win32': - result = path_to_uri(u'C:/æøå') - self.assertEqual(result, 'file:///C://%C3%A6%C3%B8%C3%A5') - else: - result = path_to_uri(u'/tmp/æøå') - self.assertEqual(result, u'file:///tmp/%C3%A6%C3%B8%C3%A5') - - song1_path = data_folder('song1.mp3') song2_path = data_folder('song2.mp3') encoded_path = data_folder(u'æøå.mp3') @@ -98,7 +17,6 @@ song1_uri = path_to_uri(song1_path) song2_uri = path_to_uri(song2_path) encoded_uri = path_to_uri(encoded_path) - class M3UToUriTest(unittest.TestCase): def test_empty_file(self): uris = parse_m3u(data_folder('empty.m3u')) diff --git a/tests/outputs/gstreamer_test.py b/tests/outputs/gstreamer_test.py index 62207659..c063aaee 100644 --- a/tests/outputs/gstreamer_test.py +++ b/tests/outputs/gstreamer_test.py @@ -1,15 +1,15 @@ import multiprocessing import unittest -from mopidy.utils import path_to_uri -from mopidy.process import pickle_connection from mopidy.outputs.gstreamer import GStreamerOutput +from mopidy.process import pickle_connection +from mopidy.utils.path import path_to_uri from tests import data_folder, SkipTest class GStreamerOutputTest(unittest.TestCase): def setUp(self): - self.song_uri = path_to_uri(data_folder('song1.wav')) + self.song_uri = path_to_uri(data_folder('song1.wav')) self.output_queue = multiprocessing.Queue() self.core_queue = multiprocessing.Queue() self.output = GStreamerOutput(self.core_queue, self.output_queue) diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/utils/init_test.py b/tests/utils/init_test.py new file mode 100644 index 00000000..fb38e2ea --- /dev/null +++ b/tests/utils/init_test.py @@ -0,0 +1,22 @@ +import unittest + +from mopidy.utils import get_class + +class GetClassTest(unittest.TestCase): + def test_loading_module_that_does_not_exist(self): + test = lambda: get_class('foo.bar.Baz') + self.assertRaises(ImportError, test) + + def test_loading_class_that_does_not_exist(self): + test = lambda: get_class('unittest.FooBarBaz') + self.assertRaises(ImportError, test) + + def test_import_error_message_contains_complete_class_path(self): + try: + get_class('foo.bar.Baz') + except ImportError as e: + self.assert_('foo.bar.Baz' in str(e)) + + def test_loading_existing_class(self): + cls = get_class('unittest.TestCase') + self.assertEqual(cls.__name__, 'TestCase') diff --git a/tests/utils/path_test.py b/tests/utils/path_test.py new file mode 100644 index 00000000..ae63d5c0 --- /dev/null +++ b/tests/utils/path_test.py @@ -0,0 +1,71 @@ +# encoding: utf-8 + +import os +import shutil +import sys +import tempfile +import unittest + +from mopidy.utils.path import get_or_create_folder, path_to_uri + +from tests import SkipTest + +class GetOrCreateFolderTest(unittest.TestCase): + def setUp(self): + self.parent = tempfile.mkdtemp() + + def tearDown(self): + if os.path.isdir(self.parent): + shutil.rmtree(self.parent) + + def test_creating_folder(self): + folder = os.path.join(self.parent, 'test') + self.assert_(not os.path.exists(folder)) + self.assert_(not os.path.isdir(folder)) + created = get_or_create_folder(folder) + self.assert_(os.path.exists(folder)) + self.assert_(os.path.isdir(folder)) + self.assertEqual(created, folder) + + def test_creating_existing_folder(self): + created = get_or_create_folder(self.parent) + self.assert_(os.path.exists(self.parent)) + self.assert_(os.path.isdir(self.parent)) + self.assertEqual(created, self.parent) + + def test_that_userfolder_is_expanded(self): + raise SkipTest # Not sure how to safely test this + + +class PathToFileURITest(unittest.TestCase): + def test_simple_path(self): + if sys.platform == 'win32': + result = path_to_uri(u'C:/WINDOWS/clock.avi') + self.assertEqual(result, 'file:///C://WINDOWS/clock.avi') + else: + result = path_to_uri(u'/etc/fstab') + self.assertEqual(result, 'file:///etc/fstab') + + def test_folder_and_path(self): + if sys.platform == 'win32': + result = path_to_uri(u'C:/WINDOWS/', u'clock.avi') + self.assertEqual(result, 'file:///C://WINDOWS/clock.avi') + else: + result = path_to_uri(u'/etc', u'fstab') + self.assertEqual(result, u'file:///etc/fstab') + + def test_space_in_path(self): + if sys.platform == 'win32': + result = path_to_uri(u'C:/test this') + self.assertEqual(result, 'file:///C://test%20this') + else: + result = path_to_uri(u'/tmp/test this') + self.assertEqual(result, u'file:///tmp/test%20this') + + def test_unicode_in_path(self): + if sys.platform == 'win32': + result = path_to_uri(u'C:/æøå') + self.assertEqual(result, 'file:///C://%C3%A6%C3%B8%C3%A5') + else: + result = path_to_uri(u'/tmp/æøå') + self.assertEqual(result, u'file:///tmp/%C3%A6%C3%B8%C3%A5') From e021863fd807f43f8b910618ee4f2cf9caf48307 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 17 Aug 2010 01:20:17 +0200 Subject: [PATCH 119/138] Fix broken import --- mopidy/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mopidy/__main__.py b/mopidy/__main__.py index c92ce1ed..dd10b1f4 100644 --- a/mopidy/__main__.py +++ b/mopidy/__main__.py @@ -11,7 +11,8 @@ sys.path.insert(0, from mopidy import get_version, settings, SettingsError from mopidy.process import CoreProcess -from mopidy.utils import get_class, get_or_create_folder +from mopidy.utils import get_class +from mopidy.utils.path import get_or_create_folder logger = logging.getLogger('mopidy.main') From 7afc74d80b05887a16d44f693d3cc03f3fda6d55 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 17 Aug 2010 01:23:37 +0200 Subject: [PATCH 120/138] Cleanup settings magic --- mopidy/__init__.py | 15 +++----------- mopidy/settings.py | 12 ------------ mopidy/utils/settings.py | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 mopidy/utils/settings.py diff --git a/mopidy/__init__.py b/mopidy/__init__.py index 09d72b26..e3321041 100644 --- a/mopidy/__init__.py +++ b/mopidy/__init__.py @@ -2,8 +2,6 @@ import sys if not (2, 6) <= sys.version_info < (3,): sys.exit(u'Mopidy requires Python >= 2.6, < 3') -from mopidy import settings as raw_settings - def get_version(): return u'0.1.0a4' @@ -27,13 +25,6 @@ class MopidyException(Exception): class SettingsError(MopidyException): pass -class Settings(object): - def __getattr__(self, attr): - if attr.isupper() and not hasattr(raw_settings, attr): - raise SettingsError(u'Setting "%s" is not set.' % attr) - value = getattr(raw_settings, attr) - if type(value) != bool and not value: - raise SettingsError(u'Setting "%s" is empty.' % attr) - return value - -settings = Settings() +from mopidy import settings as default_settings_module +from mopidy.utils.settings import SettingsProxy +settings = SettingsProxy(default_settings_module) diff --git a/mopidy/settings.py b/mopidy/settings.py index 67b0c24f..c9e3606e 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -7,11 +7,6 @@ Available settings and their default values. file called ``~/.mopidy/settings.py`` and redefine settings there. """ -# Absolute import needed to import ~/.mopidy/settings.py and not ourselves -from __future__ import absolute_import -import os -import sys - #: List of playback backends to use. See :mod:`mopidy.backends` for all #: available backends. #: @@ -172,10 +167,3 @@ SPOTIFY_USERNAME = u'' #: #: Used by :mod:`mopidy.backends.libspotify`. SPOTIFY_PASSWORD = u'' - -# Import user specific settings -dotdir = os.path.expanduser(u'~/.mopidy/') -settings_file = os.path.join(dotdir, u'settings.py') -if os.path.isfile(settings_file): - sys.path.insert(0, dotdir) - from settings import * diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py new file mode 100644 index 00000000..f7209653 --- /dev/null +++ b/mopidy/utils/settings.py @@ -0,0 +1,42 @@ +# Absolute import needed to import ~/.mopidy/settings.py and not ourselves +from __future__ import absolute_import +from copy import copy +import os +import sys + +from mopidy import SettingsError + +class SettingsProxy(object): + def __init__(self, default_settings_module): + self.default_settings = self._get_settings_dict_from_module( + default_settings_module) + self.local_settings = self._get_local_settings() + self.raw_settings = copy(self.default_settings) + self.raw_settings.update(self.local_settings) + + def _get_local_settings(self): + dotdir = os.path.expanduser(u'~/.mopidy/') + settings_file = os.path.join(dotdir, u'settings.py') + if os.path.isfile(settings_file): + sys.path.insert(0, dotdir) + import settings as local_settings_module + return self._get_settings_dict_from_module(local_settings_module) + + def _get_settings_dict_from_module(self, module): + settings = filter(lambda (key, value): self._is_setting(key), + module.__dict__.iteritems()) + return dict(settings) + + def _is_setting(self, name): + return name.isupper() + + def __getattr__(self, attr): + if not self._is_setting(attr): + return + if attr not in self.raw_settings: + raise SettingsError(u'Setting "%s" is not set.' % attr) + value = self.raw_settings[attr] + if type(value) != bool and not value: + raise SettingsError(u'Setting "%s" is empty.' % attr) + return value + From 12e5bc39e310f247f74aa3312610e9600857223c Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 17 Aug 2010 01:45:52 +0200 Subject: [PATCH 121/138] Add settings validation --- docs/changes.rst | 2 ++ mopidy/__init__.py | 1 + mopidy/utils/settings.py | 57 ++++++++++++++++++++++++++++++++++++ tests/utils/settings_test.py | 40 +++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 tests/utils/settings_test.py diff --git a/docs/changes.rst b/docs/changes.rst index 323f899e..9f5efa84 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -31,6 +31,8 @@ greatly improved MPD client support. **Changes** - Exit early if not Python >= 2.6, < 3. +- Validate settings at startup and print useful error messages if the settings + has not been updated or anything is misspelled. - Include Sphinx scripts for building docs, pylintrc, tests and test data in the packages created by ``setup.py`` for i.e. PyPI. - MPD frontend: diff --git a/mopidy/__init__.py b/mopidy/__init__.py index e3321041..9faf31cb 100644 --- a/mopidy/__init__.py +++ b/mopidy/__init__.py @@ -28,3 +28,4 @@ class SettingsError(MopidyException): from mopidy import settings as default_settings_module from mopidy.utils.settings import SettingsProxy settings = SettingsProxy(default_settings_module) +settings.validate() diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index f7209653..d06e822a 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -1,6 +1,7 @@ # Absolute import needed to import ~/.mopidy/settings.py and not ourselves from __future__ import absolute_import from copy import copy +import logging import os import sys @@ -40,3 +41,59 @@ class SettingsProxy(object): raise SettingsError(u'Setting "%s" is empty.' % attr) return value + def validate(self): + if self.get_errors(): + sys.exit(self.get_errors_as_string()) + + def get_errors(self): + return validate_settings(self.default_settings, self.local_settings) + + def get_errors_as_string(self): + lines = [u'Errors:'] + for (setting, error) in self.get_errors().iteritems(): + lines.append(u' %s: %s' % (setting, error)) + return '\n'.join(lines) + + +def validate_settings(defaults, settings): + """ + Checks the settings for both errors like misspellings and against a set of + rules for renamed settings, etc. + + Returns of setting names with associated errors. + + :param defaults: Mopidy's default settings + :type defaults: dict + :param settings: the user's local settings + :type settings: dict + :rtype: dict + """ + errors = {} + + changed = { + 'SERVER_HOSTNAME': 'MPD_SERVER_HOSTNAME', + 'SERVER_PORT': 'MPD_SERVER_PORT', + 'SPOTIFY_LIB_APPKEY': None, + } + + for setting, value in settings.iteritems(): + if setting in changed: + if changed[setting] is None: + errors[setting] = u'Deprecated setting. It may be removed.' + else: + errors[setting] = u'Deprecated setting. Use %s.' % ( + changed[setting],) + break + + if setting == 'BACKENDS': + if 'mopidy.backends.despotify.DespotifyBackend' in value: + errors[setting] = (u'Deprecated setting value. ' + + '"mopidy.backends.despotify.DespotifyBackend" is no ' + + 'longer available.') + break + + if setting not in defaults: + errors[setting] = u'Unknown setting. Is it misspelled?' + break + + return errors diff --git a/tests/utils/settings_test.py b/tests/utils/settings_test.py new file mode 100644 index 00000000..0e1076c9 --- /dev/null +++ b/tests/utils/settings_test.py @@ -0,0 +1,40 @@ +import unittest + +from mopidy.utils.settings import validate_settings + +class ValidateSettingsTest(unittest.TestCase): + def setUp(self): + self.defaults = { + 'MPD_SERVER_HOSTNAME': '::', + 'MPD_SERVER_PORT': 6600, + } + + def test_no_errors_yields_empty_dict(self): + result = validate_settings(self.defaults, {}) + self.assertEqual(result, {}) + + def test_unknown_setting_returns_error(self): + result = validate_settings(self.defaults, + {'MPD_SERVER_HOSTNMAE': '127.0.0.1'}) + self.assertEqual(result['MPD_SERVER_HOSTNMAE'], + u'Unknown setting. Is it misspelled?') + + def test_not_renamed_setting_returns_error(self): + result = validate_settings(self.defaults, + {'SERVER_HOSTNAME': '127.0.0.1'}) + self.assertEqual(result['SERVER_HOSTNAME'], + u'Deprecated setting. Use MPD_SERVER_HOSTNAME.') + + def test_unneeded_settings_returns_error(self): + result = validate_settings(self.defaults, + {'SPOTIFY_LIB_APPKEY': '/tmp/foo'}) + self.assertEqual(result['SPOTIFY_LIB_APPKEY'], + u'Deprecated setting. It may be removed.') + + def test_deprecated_setting_value_returns_error(self): + result = validate_settings(self.defaults, + {'BACKENDS': ('mopidy.backends.despotify.DespotifyBackend',)}) + self.assertEqual(result['BACKENDS'], + u'Deprecated setting value. ' + + '"mopidy.backends.despotify.DespotifyBackend" is no longer ' + + 'available.') From a8c736110fb2c09870aa7ddd24dc4745d127a04b Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 17 Aug 2010 01:49:54 +0200 Subject: [PATCH 122/138] Move settings validation from module import to program start --- mopidy/__init__.py | 1 - mopidy/__main__.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/mopidy/__init__.py b/mopidy/__init__.py index 9faf31cb..e3321041 100644 --- a/mopidy/__init__.py +++ b/mopidy/__init__.py @@ -28,4 +28,3 @@ class SettingsError(MopidyException): from mopidy import settings as default_settings_module from mopidy.utils.settings import SettingsProxy settings = SettingsProxy(default_settings_module) -settings.validate() diff --git a/mopidy/__main__.py b/mopidy/__main__.py index dd10b1f4..1ea05d1f 100644 --- a/mopidy/__main__.py +++ b/mopidy/__main__.py @@ -19,6 +19,7 @@ logger = logging.getLogger('mopidy.main') def main(): options = _parse_options() _setup_logging(options.verbosity_level, options.dump) + settings.validate() logger.info('-- Starting Mopidy --') get_or_create_folder('~/.mopidy/') core_queue = multiprocessing.Queue() From 9cb84002bc550c44568f408e20cdfe34ac332841 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 17 Aug 2010 01:58:31 +0200 Subject: [PATCH 123/138] Report multiple settings errors at once --- mopidy/utils/settings.py | 6 +++--- tests/utils/settings_test.py | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index d06e822a..78982e8a 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -83,17 +83,17 @@ def validate_settings(defaults, settings): else: errors[setting] = u'Deprecated setting. Use %s.' % ( changed[setting],) - break + continue if setting == 'BACKENDS': if 'mopidy.backends.despotify.DespotifyBackend' in value: errors[setting] = (u'Deprecated setting value. ' + '"mopidy.backends.despotify.DespotifyBackend" is no ' + 'longer available.') - break + continue if setting not in defaults: errors[setting] = u'Unknown setting. Is it misspelled?' - break + continue return errors diff --git a/tests/utils/settings_test.py b/tests/utils/settings_test.py index 0e1076c9..5bf0f9b4 100644 --- a/tests/utils/settings_test.py +++ b/tests/utils/settings_test.py @@ -38,3 +38,8 @@ class ValidateSettingsTest(unittest.TestCase): u'Deprecated setting value. ' + '"mopidy.backends.despotify.DespotifyBackend" is no longer ' + 'available.') + + def test_two_errors_are_both_reported(self): + result = validate_settings(self.defaults, + {'FOO': '', 'BAR': ''}) + self.assertEquals(len(result), 2) From 61059e761049dec719af5eb68c9d11d94c449515 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 17 Aug 2010 02:02:52 +0200 Subject: [PATCH 124/138] Use logging for settings validation errors --- mopidy/utils/settings.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index 78982e8a..b478e67e 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -6,6 +6,9 @@ import os import sys from mopidy import SettingsError +from mopidy.utils import indent + +logger = logging.getLogger('mopidy.utils.settings') class SettingsProxy(object): def __init__(self, default_settings_module): @@ -43,15 +46,17 @@ class SettingsProxy(object): def validate(self): if self.get_errors(): - sys.exit(self.get_errors_as_string()) + logger.error(u'Settings validation errors: %s', + indent(self.get_errors_as_string())) + raise SettingsError(u'Settings validation failed.') def get_errors(self): return validate_settings(self.default_settings, self.local_settings) def get_errors_as_string(self): - lines = [u'Errors:'] + lines = [] for (setting, error) in self.get_errors().iteritems(): - lines.append(u' %s: %s' % (setting, error)) + lines.append(u'%s: %s' % (setting, error)) return '\n'.join(lines) From da184ac896831bc67f58a696484488c147634a8f Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 17 Aug 2010 02:34:10 +0200 Subject: [PATCH 125/138] Add '--list-settings' option --- docs/changes.rst | 6 ++++-- mopidy/__main__.py | 4 ++++ mopidy/utils/settings.py | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 9f5efa84..341ef850 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -33,6 +33,8 @@ greatly improved MPD client support. - Exit early if not Python >= 2.6, < 3. - Validate settings at startup and print useful error messages if the settings has not been updated or anything is misspelled. +- Add command line option :option:`--list-settings` to print the currently + active settings. - Include Sphinx scripts for building docs, pylintrc, tests and test data in the packages created by ``setup.py`` for i.e. PyPI. - MPD frontend: @@ -207,8 +209,8 @@ the established pace of at least a release per month. - Improvements to MPD protocol handling, making Mopidy work much better with a group of clients, including ncmpc, MPoD, and Theremin. -- New command line flag ``--dump`` for dumping debug log to ``dump.log`` in the - current directory. +- New command line flag :option:`--dump` for dumping debug log to ``dump.log`` + in the current directory. - New setting :attr:`mopidy.settings.MIXER_ALSA_CONTROL` for forcing what ALSA control :class:`mopidy.mixers.alsa.AlsaMixer` should use. diff --git a/mopidy/__main__.py b/mopidy/__main__.py index 1ea05d1f..a2230180 100644 --- a/mopidy/__main__.py +++ b/mopidy/__main__.py @@ -13,6 +13,7 @@ from mopidy import get_version, settings, SettingsError from mopidy.process import CoreProcess from mopidy.utils import get_class from mopidy.utils.path import get_or_create_folder +from mopidy.utils.settings import list_settings_optparse_callback logger = logging.getLogger('mopidy.main') @@ -42,6 +43,9 @@ def _parse_options(): parser.add_option('--dump', action='store_true', dest='dump', help='dump debug log to file') + parser.add_option('--list-settings', + action='callback', callback=list_settings_optparse_callback, + help='list current settings') return parser.parse_args()[0] def _setup_logging(verbosity_level, dump): diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index b478e67e..34457f05 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -102,3 +102,26 @@ def validate_settings(defaults, settings): continue return errors + +def list_settings_optparse_callback(*args): + """ + Prints a list of all settings. + + Called by optparse when Mopidy is run with the :option:`--list-settings` + option. + """ + from mopidy import settings + errors = settings.get_errors() + lines = [] + for (key, value) in sorted(settings.raw_settings.iteritems()): + default_value = settings.default_settings.get(key) + if key.endswith('PASSWORD'): + value = u'********' + lines.append(u'%s:' % key) + lines.append(u' Value: %s' % repr(value)) + if value != default_value and default_value is not None: + lines.append(u' Default: %s' % repr(default_value)) + if errors.get(key) is not None: + lines.append(u' Error: %s' % errors[key]) + print u'Settings: %s' % indent('\n'.join(lines), places=2) + sys.exit(0) From 7d04550f53e8c287f2c13f71294c001ed6496ada Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 17 Aug 2010 02:38:55 +0200 Subject: [PATCH 126/138] Remove unused imports --- mopidy/backends/local/translator.py | 2 -- tests/frontends/mpd/stored_playlists_test.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/mopidy/backends/local/translator.py b/mopidy/backends/local/translator.py index ac69373a..87ea15df 100644 --- a/mopidy/backends/local/translator.py +++ b/mopidy/backends/local/translator.py @@ -1,7 +1,5 @@ import logging import os -import sys -import urllib logger = logging.getLogger('mopidy.backends.local.translator') diff --git a/tests/frontends/mpd/stored_playlists_test.py b/tests/frontends/mpd/stored_playlists_test.py index b49ccce1..6e5717af 100644 --- a/tests/frontends/mpd/stored_playlists_test.py +++ b/tests/frontends/mpd/stored_playlists_test.py @@ -6,8 +6,6 @@ from mopidy.frontends.mpd import frontend from mopidy.mixers.dummy import DummyMixer from mopidy.models import Track, Playlist -from tests import SkipTest - class StoredPlaylistsHandlerTest(unittest.TestCase): def setUp(self): self.b = DummyBackend(mixer_class=DummyMixer) From 6b834e6a3353b62079fa1f2bb32425b9479d12ae Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 18 Aug 2010 00:06:45 +0200 Subject: [PATCH 127/138] Fix loading of local settings when local settings is not present --- mopidy/utils/settings.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index 34457f05..18f59df7 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -21,9 +21,10 @@ class SettingsProxy(object): def _get_local_settings(self): dotdir = os.path.expanduser(u'~/.mopidy/') settings_file = os.path.join(dotdir, u'settings.py') - if os.path.isfile(settings_file): - sys.path.insert(0, dotdir) - import settings as local_settings_module + if not os.path.isfile(settings_file): + return {} + sys.path.insert(0, dotdir) + import settings as local_settings_module return self._get_settings_dict_from_module(local_settings_module) def _get_settings_dict_from_module(self, module): From 28e1a15ac742b719830e01498e8d097964da8b46 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 18 Aug 2010 00:38:54 +0200 Subject: [PATCH 128/138] Remove SkipTest --- tests/backends/local/backend_test.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/backends/local/backend_test.py b/tests/backends/local/backend_test.py index 7215e8eb..aff84658 100644 --- a/tests/backends/local/backend_test.py +++ b/tests/backends/local/backend_test.py @@ -19,8 +19,6 @@ from tests import SkipTest, data_folder song = data_folder('song%s.wav') generate_song = lambda i: path_to_uri(song % i) -raise SkipTest - # FIXME can be switched to generic test class LocalCurrentPlaylistControllerTest(BaseCurrentPlaylistControllerTest, unittest.TestCase): From 0db797bc125ec608734ea74877bf604cd8298cf4 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 18 Aug 2010 00:39:10 +0200 Subject: [PATCH 129/138] Rename next_track in tests --- tests/backends/base.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/backends/base.py b/tests/backends/base.py index f341ab48..a18eecf8 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -481,29 +481,29 @@ class BasePlaybackControllerTest(object): @populate_playlist def test_next_track_before_play(self): - self.assertEqual(self.playback.next_track, self.tracks[0]) + self.assertEqual(self.playback.track_at_next, self.tracks[0]) @populate_playlist def test_next_track_during_play(self): self.playback.play() - self.assertEqual(self.playback.next_track, self.tracks[1]) + self.assertEqual(self.playback.track_at_next, self.tracks[1]) @populate_playlist def test_next_track_after_previous(self): self.playback.play() self.playback.next() self.playback.previous() - self.assertEqual(self.playback.next_track, self.tracks[1]) + self.assertEqual(self.playback.track_at_next, self.tracks[1]) def test_next_track_empty_playlist(self): - self.assertEqual(self.playback.next_track, None) + self.assertEqual(self.playback.track_at_next, None) @populate_playlist def test_next_track_at_end_of_playlist(self): self.playback.play() for track in self.current_playlist.cp_tracks[1:]: self.playback.next() - self.assertEqual(self.playback.next_track, None) + self.assertEqual(self.playback.track_at_next, None) @populate_playlist def test_next_track_at_end_of_playlist_with_repeat(self): @@ -511,13 +511,13 @@ class BasePlaybackControllerTest(object): self.playback.play() for track in self.tracks[1:]: self.playback.next() - self.assertEqual(self.playback.next_track, self.tracks[0]) + self.assertEqual(self.playback.track_at_next, self.tracks[0]) @populate_playlist def test_next_track_with_random(self): random.seed(1) self.playback.random = True - self.assertEqual(self.playback.next_track, self.tracks[2]) + self.assertEqual(self.playback.track_at_next, self.tracks[2]) @populate_playlist def test_next_with_consume(self): @@ -547,9 +547,9 @@ class BasePlaybackControllerTest(object): def test_next_track_with_random_after_load_playlist(self): random.seed(1) self.playback.random = True - self.assertEqual(self.playback.next_track, self.tracks[2]) + self.assertEqual(self.playback.track_at_next, self.tracks[2]) self.backend.current_playlist.load(self.tracks[:1]) - self.assertEqual(self.playback.next_track, self.tracks[1]) + self.assertEqual(self.playback.track_at_next, self.tracks[1]) @populate_playlist def test_end_of_track(self): @@ -617,29 +617,29 @@ class BasePlaybackControllerTest(object): @populate_playlist def test_end_of_track_track_before_play(self): - self.assertEqual(self.playback.next_track, self.tracks[0]) + self.assertEqual(self.playback.track_at_next, self.tracks[0]) @populate_playlist def test_end_of_track_track_during_play(self): self.playback.play() - self.assertEqual(self.playback.next_track, self.tracks[1]) + self.assertEqual(self.playback.track_at_next, self.tracks[1]) @populate_playlist def test_end_of_track_track_after_previous(self): self.playback.play() self.playback.on_end_of_track() self.playback.previous() - self.assertEqual(self.playback.next_track, self.tracks[1]) + self.assertEqual(self.playback.track_at_next, self.tracks[1]) def test_end_of_track_track_empty_playlist(self): - self.assertEqual(self.playback.next_track, None) + self.assertEqual(self.playback.track_at_next, None) @populate_playlist def test_end_of_track_track_at_end_of_playlist(self): self.playback.play() for track in self.current_playlist.cp_tracks[1:]: self.playback.on_end_of_track() - self.assertEqual(self.playback.next_track, None) + self.assertEqual(self.playback.track_at_next, None) @populate_playlist def test_end_of_track_track_at_end_of_playlist_with_repeat(self): @@ -647,13 +647,13 @@ class BasePlaybackControllerTest(object): self.playback.play() for track in self.tracks[1:]: self.playback.on_end_of_track() - self.assertEqual(self.playback.next_track, self.tracks[0]) + self.assertEqual(self.playback.track_at_next, self.tracks[0]) @populate_playlist def test_end_of_track_track_with_random(self): random.seed(1) self.playback.random = True - self.assertEqual(self.playback.next_track, self.tracks[2]) + self.assertEqual(self.playback.track_at_next, self.tracks[2]) @populate_playlist @@ -684,9 +684,9 @@ class BasePlaybackControllerTest(object): def test_end_of_track_track_with_random_after_load_playlist(self): random.seed(1) self.playback.random = True - self.assertEqual(self.playback.next_track, self.tracks[2]) + self.assertEqual(self.playback.track_at_next, self.tracks[2]) self.backend.current_playlist.load(self.tracks[:1]) - self.assertEqual(self.playback.next_track, self.tracks[1]) + self.assertEqual(self.playback.track_at_next, self.tracks[1]) @populate_playlist def test_previous_track_before_play(self): @@ -1056,14 +1056,14 @@ class BasePlaybackControllerTest(object): self.playback.play() for track in self.tracks[1:]: self.playback.next() - self.assertEqual(self.playback.next_track, None) + self.assertEqual(self.playback.track_at_next, None) @populate_playlist def test_random_until_end_of_playlist_and_play_from_start(self): self.playback.repeat = True for track in self.tracks: self.playback.next() - self.assertNotEqual(self.playback.next_track, None) + self.assertNotEqual(self.playback.track_at_next, None) self.assertEqual(self.playback.state, self.playback.STOPPED) self.playback.play() self.assertEqual(self.playback.state, self.playback.PLAYING) @@ -1075,7 +1075,7 @@ class BasePlaybackControllerTest(object): self.playback.play() for track in self.tracks: self.playback.next() - self.assertNotEqual(self.playback.next_track, None) + self.assertNotEqual(self.playback.track_at_next, None) @populate_playlist def test_played_track_during_random_not_played_again(self): From d01813b72ce33f780fd77506b09431e6862ed86d Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 18 Aug 2010 00:42:26 +0200 Subject: [PATCH 130/138] Rename previous_track in tests --- tests/backends/base.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/backends/base.py b/tests/backends/base.py index a18eecf8..1fee2379 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -690,18 +690,18 @@ class BasePlaybackControllerTest(object): @populate_playlist def test_previous_track_before_play(self): - self.assertEqual(self.playback.previous_track, None) + self.assertEqual(self.playback.track_at_previous, None) @populate_playlist def test_previous_track_after_play(self): self.playback.play() - self.assertEqual(self.playback.previous_track, None) + self.assertEqual(self.playback.track_at_previous, None) @populate_playlist def test_previous_track_after_next(self): self.playback.play() self.playback.next() - self.assertEqual(self.playback.previous_track, self.tracks[0]) + self.assertEqual(self.playback.track_at_previous, self.tracks[0]) @populate_playlist def test_previous_track_after_previous(self): @@ -709,17 +709,17 @@ class BasePlaybackControllerTest(object): self.playback.next() # At track 1 self.playback.next() # At track 2 self.playback.previous() # At track 1 - self.assertEqual(self.playback.previous_track, self.tracks[0]) + self.assertEqual(self.playback.track_at_previous, self.tracks[0]) def test_previous_track_empty_playlist(self): - self.assertEqual(self.playback.previous_track, None) + self.assertEqual(self.playback.track_at_previous, None) @populate_playlist def test_previous_track_with_consume(self): self.playback.consume = True for track in self.tracks: self.playback.next() - self.assertEqual(self.playback.previous_track, + self.assertEqual(self.playback.track_at_previous, self.playback.current_track) @populate_playlist @@ -727,7 +727,7 @@ class BasePlaybackControllerTest(object): self.playback.random = True for track in self.tracks: self.playback.next() - self.assertEqual(self.playback.previous_track, + self.assertEqual(self.playback.track_at_previous, self.playback.current_track) @populate_playlist From e66cf75d054a9ac269a65707667cdc51940b58a5 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 18 Aug 2010 00:43:58 +0200 Subject: [PATCH 131/138] Call renamed callback --- mopidy/backends/local/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mopidy/backends/local/__init__.py b/mopidy/backends/local/__init__.py index 434492bf..45e74e5d 100644 --- a/mopidy/backends/local/__init__.py +++ b/mopidy/backends/local/__init__.py @@ -69,7 +69,7 @@ class LocalPlaybackController(BasePlaybackController): def _message(self, bus, message): if message.type == gst.MESSAGE_EOS: - self.end_of_track_callback() + self.on_end_of_track() elif message.type == gst.MESSAGE_ERROR: self._bin.set_state(gst.STATE_NULL) error, debug = message.parse_error() From c0e4454e67c3e6ded3ae573c90d22d83b7965737 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 18 Aug 2010 00:49:26 +0200 Subject: [PATCH 132/138] Remove obsolete search tests --- tests/backends/base.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tests/backends/base.py b/tests/backends/base.py index 1fee2379..a26c0968 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -1174,21 +1174,6 @@ class BaseStoredPlaylistsControllerTest(object): except LookupError as e: self.assertEqual(u'"name=c" match no playlists', e[0]) - def test_search_returns_empty_list(self): - self.assertEqual([], self.stored.search('test')) - - def test_search_returns_playlist(self): - playlist = self.stored.create('test') - playlists = self.stored.search('test') - self.assert_(playlist in playlists) - - def test_search_returns_mulitple_playlists(self): - playlist1 = self.stored.create('test') - playlist2 = self.stored.create('test2') - playlists = self.stored.search('test') - self.assert_(playlist1 in playlists) - self.assert_(playlist2 in playlists) - def test_lookup(self): raise SkipTest From 785ef04e7b0fea2d5e4d0e44b8c9adaec97ee385 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 18 Aug 2010 00:53:29 +0200 Subject: [PATCH 133/138] Rename load to append in tests --- tests/backends/base.py | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/backends/base.py b/tests/backends/base.py index a26c0968..eb13af59 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -93,12 +93,12 @@ class BaseCurrentPlaylistControllerTest(object): def test_get_by_uri_returns_unique_match(self): track = Track(uri='a') - self.controller.load([Track(uri='z'), track, Track(uri='y')]) + self.controller.append([Track(uri='z'), track, Track(uri='y')]) self.assertEqual(track, self.controller.get(uri='a')[1]) def test_get_by_uri_raises_error_if_multiple_matches(self): track = Track(uri='a') - self.controller.load([Track(uri='z'), track, track]) + self.controller.append([Track(uri='z'), track, track]) try: self.controller.get(uri='a') self.fail(u'Should raise LookupError if multiple matches') @@ -118,7 +118,7 @@ class BaseCurrentPlaylistControllerTest(object): track1 = Track(uri='a', name='x') track2 = Track(uri='b', name='x') track3 = Track(uri='b', name='y') - self.controller.load([track1, track2, track3]) + self.controller.append([track1, track2, track3]) self.assertEqual(track1, self.controller.get(uri='a', name='x')[1]) self.assertEqual(track2, self.controller.get(uri='b', name='x')[1]) self.assertEqual(track3, self.controller.get(uri='b', name='y')[1]) @@ -127,35 +127,35 @@ class BaseCurrentPlaylistControllerTest(object): track1 = Track() track2 = Track(uri='b') track3 = Track() - self.controller.load([track1, track2, track3]) + self.controller.append([track1, track2, track3]) self.assertEqual(track2, self.controller.get(uri='b')[1]) - def test_load_appends_to_the_current_playlist(self): - self.controller.load([Track(uri='a'), Track(uri='b')]) + def test_append_appends_to_the_current_playlist(self): + self.controller.append([Track(uri='a'), Track(uri='b')]) self.assertEqual(len(self.controller.tracks), 2) - self.controller.load([Track(uri='c'), Track(uri='d')]) + self.controller.append([Track(uri='c'), Track(uri='d')]) self.assertEqual(len(self.controller.tracks), 4) self.assertEqual(self.controller.tracks[0].uri, 'a') self.assertEqual(self.controller.tracks[1].uri, 'b') self.assertEqual(self.controller.tracks[2].uri, 'c') self.assertEqual(self.controller.tracks[3].uri, 'd') - def test_load_does_not_reset_version(self): + def test_append_does_not_reset_version(self): version = self.controller.version - self.controller.load([]) + self.controller.append([]) self.assertEqual(self.controller.version, version + 1) @populate_playlist - def test_load_preserves_playing_state(self): + def test_append_preserves_playing_state(self): self.playback.play() track = self.playback.current_track - self.controller.load(self.controller.tracks[1:2]) + self.controller.append(self.controller.tracks[1:2]) self.assertEqual(self.playback.state, self.playback.PLAYING) self.assertEqual(self.playback.current_track, track) @populate_playlist - def test_load_preserves_stopped_state(self): - self.controller.load(self.controller.tracks[1:2]) + def test_append_preserves_stopped_state(self): + self.controller.append(self.controller.tracks[1:2]) self.assertEqual(self.playback.state, self.playback.STOPPED) self.assertEqual(self.playback.current_track, None) @@ -266,7 +266,7 @@ class BaseCurrentPlaylistControllerTest(object): def test_version(self): version = self.controller.version - self.controller.load([]) + self.controller.append([]) self.assert_(version < self.controller.version) @@ -544,11 +544,11 @@ class BasePlaybackControllerTest(object): self.assertEqual(self.playback.current_track, self.tracks[1]) @populate_playlist - def test_next_track_with_random_after_load_playlist(self): + def test_next_track_with_random_after_append_playlist(self): random.seed(1) self.playback.random = True self.assertEqual(self.playback.track_at_next, self.tracks[2]) - self.backend.current_playlist.load(self.tracks[:1]) + self.backend.current_playlist.append(self.tracks[:1]) self.assertEqual(self.playback.track_at_next, self.tracks[1]) @populate_playlist @@ -681,11 +681,11 @@ class BasePlaybackControllerTest(object): self.assertEqual(self.playback.current_track, self.tracks[1]) @populate_playlist - def test_end_of_track_track_with_random_after_load_playlist(self): + def test_end_of_track_track_with_random_after_append_playlist(self): random.seed(1) self.playback.random = True self.assertEqual(self.playback.track_at_next, self.tracks[2]) - self.backend.current_playlist.load(self.tracks[:1]) + self.backend.current_playlist.append(self.tracks[:1]) self.assertEqual(self.playback.track_at_next, self.tracks[1]) @populate_playlist @@ -775,7 +775,7 @@ class BasePlaybackControllerTest(object): wrapper.called = False self.playback.on_current_playlist_change = wrapper - self.backend.current_playlist.load([]) + self.backend.current_playlist.append([]) self.assert_(wrapper.called) @@ -802,14 +802,14 @@ class BasePlaybackControllerTest(object): def test_on_current_playlist_change_when_playing(self): self.playback.play() current_track = self.playback.current_track - self.backend.current_playlist.load([self.tracks[2]]) + self.backend.current_playlist.append([self.tracks[2]]) self.assertEqual(self.playback.state, self.playback.PLAYING) self.assertEqual(self.playback.current_track, current_track) @populate_playlist def test_on_current_playlist_change_when_stopped(self): current_track = self.playback.current_track - self.backend.current_playlist.load([self.tracks[2]]) + self.backend.current_playlist.append([self.tracks[2]]) self.assertEqual(self.playback.state, self.playback.STOPPED) self.assertEqual(self.playback.current_track, None) @@ -818,7 +818,7 @@ class BasePlaybackControllerTest(object): self.playback.play() self.playback.pause() current_track = self.playback.current_track - self.backend.current_playlist.load([self.tracks[2]]) + self.backend.current_playlist.append([self.tracks[2]]) self.assertEqual(self.playback.state, self.backend.playback.PAUSED) self.assertEqual(self.playback.current_track, current_track) From 4cf041119b82937e0f197ecc6ad06a117fcfce8a Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 18 Aug 2010 12:36:17 +0200 Subject: [PATCH 134/138] Validate state before handling the end of track event --- mopidy/backends/base/playback.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index f484bf89..d1acc05a 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -307,6 +307,9 @@ class BasePlaybackController(object): Typically called by :class:`mopidy.process.CoreProcess` after a message from a library thread is received. """ + if self.state == self.STOPPED: + return + original_cp_track = self.current_cp_track if self.cp_track_at_eot: self.play(self.cp_track_at_eot) From a87f7f9381e8b1419528735575a730de09cea8ba Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 18 Aug 2010 12:36:47 +0200 Subject: [PATCH 135/138] Remove tests as it is a duplicate of test_end_of_song_with_single_and_repeat_starts_same --- tests/backends/base.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/backends/base.py b/tests/backends/base.py index eb13af59..733c63cc 100644 --- a/tests/backends/base.py +++ b/tests/backends/base.py @@ -663,14 +663,6 @@ class BasePlaybackControllerTest(object): self.playback.on_end_of_track() self.assert_(self.tracks[0] not in self.backend.current_playlist.tracks) - @populate_playlist - def test_end_of_track_with_single_and_repeat(self): - self.playback.single = True - self.playback.repeat = True - self.playback.play() - self.playback.on_end_of_track() - self.assertEqual(self.playback.current_track, self.tracks[1]) - @populate_playlist def test_end_of_track_with_random(self): # FIXME feels very fragile From 1872082932648c3c563194e4bed4869c7190da9b Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 18 Aug 2010 13:03:24 +0200 Subject: [PATCH 136/138] Calculate the active settings dynamically, so tests can do mopidy.settings.local.clear() to get rid of local settings --- mopidy/utils/settings.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index 18f59df7..1f37cdd1 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -12,11 +12,9 @@ logger = logging.getLogger('mopidy.utils.settings') class SettingsProxy(object): def __init__(self, default_settings_module): - self.default_settings = self._get_settings_dict_from_module( + self.default = self._get_settings_dict_from_module( default_settings_module) - self.local_settings = self._get_local_settings() - self.raw_settings = copy(self.default_settings) - self.raw_settings.update(self.local_settings) + self.local = self._get_local_settings() def _get_local_settings(self): dotdir = os.path.expanduser(u'~/.mopidy/') @@ -35,12 +33,18 @@ class SettingsProxy(object): def _is_setting(self, name): return name.isupper() + @property + def active(self): + active = copy(self.default) + active.update(self.local) + return active + def __getattr__(self, attr): if not self._is_setting(attr): return - if attr not in self.raw_settings: + if attr not in self.active: raise SettingsError(u'Setting "%s" is not set.' % attr) - value = self.raw_settings[attr] + value = self.active[attr] if type(value) != bool and not value: raise SettingsError(u'Setting "%s" is empty.' % attr) return value @@ -52,7 +56,7 @@ class SettingsProxy(object): raise SettingsError(u'Settings validation failed.') def get_errors(self): - return validate_settings(self.default_settings, self.local_settings) + return validate_settings(self.default, self.local) def get_errors_as_string(self): lines = [] @@ -114,8 +118,8 @@ def list_settings_optparse_callback(*args): from mopidy import settings errors = settings.get_errors() lines = [] - for (key, value) in sorted(settings.raw_settings.iteritems()): - default_value = settings.default_settings.get(key) + for (key, value) in sorted(settings.active.iteritems()): + default_value = settings.default.get(key) if key.endswith('PASSWORD'): value = u'********' lines.append(u'%s:' % key) From 107c87477ec2b03b6e717a9ab8762876403eaca0 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 18 Aug 2010 13:05:46 +0200 Subject: [PATCH 137/138] Rename mopidy.settings.{active => current} --- mopidy/utils/settings.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index 1f37cdd1..478a03e6 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -34,17 +34,17 @@ class SettingsProxy(object): return name.isupper() @property - def active(self): - active = copy(self.default) - active.update(self.local) - return active + def current(self): + current = copy(self.default) + current.update(self.local) + return current def __getattr__(self, attr): if not self._is_setting(attr): return - if attr not in self.active: + if attr not in self.current: raise SettingsError(u'Setting "%s" is not set.' % attr) - value = self.active[attr] + value = self.current[attr] if type(value) != bool and not value: raise SettingsError(u'Setting "%s" is empty.' % attr) return value @@ -118,7 +118,7 @@ def list_settings_optparse_callback(*args): from mopidy import settings errors = settings.get_errors() lines = [] - for (key, value) in sorted(settings.active.iteritems()): + for (key, value) in sorted(settings.current.iteritems()): default_value = settings.default.get(key) if key.endswith('PASSWORD'): value = u'********' From 3b7831db286aa14476ea9ba00430f21ff450f5ef Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 18 Aug 2010 19:06:29 +0200 Subject: [PATCH 138/138] Add Zeroconf/Avahi to roadmap --- docs/development/roadmap.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/development/roadmap.rst b/docs/development/roadmap.rst index f9588cb8..dff9a9d7 100644 --- a/docs/development/roadmap.rst +++ b/docs/development/roadmap.rst @@ -57,6 +57,8 @@ Stuff we want to do, but not right now, and maybe never - Frontends: + - Publish the server's presence to the network using `Zeroconf + `_/Avahi. - D-Bus/`MPRIS `_ - REST/JSON web service with a jQuery client as example application. Maybe based upon `Tornado `_ and `jQuery