Skip to content

Commit

Permalink
Release v0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jcass77 committed Feb 6, 2016
2 parents 1df4b2f + a783fd4 commit 9507c40
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 54 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========


v0.2.1 (Feb 6, 2016)
--------------------

- Fix to prevent the Mopidy-Pandora backend from starting up if logging in to the Pandora server failed.
(Fixes: `#44 <https://github.com/rectalogic/mopidy-pandora/issues/44>`_).
- Fixed an issue that would cause only the first few doubleclick events to be processed correctly.

v0.2.0 (Jan 26, 2016)
---------------------

Expand Down
12 changes: 1 addition & 11 deletions mopidy_pandora/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import pykka

import requests

from mopidy_pandora import listener, utils

from mopidy_pandora.client import MopidyAPIClient, MopidySettingsDictBuilder
Expand Down Expand Up @@ -44,16 +42,8 @@ def __init__(self, config, audio):
self.playback = PandoraPlaybackProvider(audio, self)
self.uri_schemes = [PandoraUri.SCHEME]

@utils.run_async
def on_start(self):
try:
self.api.login(self.config['username'], self.config['password'])
# Prefetch list of stations linked to the user's profile
self.api.get_station_list()
# Prefetch genre category list
self.api.get_genre_stations()
except requests.exceptions.RequestException:
logger.exception('Error logging in to Pandora.')
self.api.login(self.config['username'], self.config['password'])

def end_of_tracklist_reached(self, station_id=None, auto_play=False):
self.prepare_next_track(station_id, auto_play)
Expand Down
14 changes: 7 additions & 7 deletions mopidy_pandora/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,13 @@ def on_start(self):
self.event_sequences.append(EventSequence(self.config['on_pause_previous_click'],
['track_playback_paused',
'track_playback_ended',
'track_changing',
'track_playback_paused'], self.sequence_match_results,
wait_for='track_changed_previous',
interval=interval))

self.event_sequences.append(EventSequence(self.config['on_pause_next_click'],
['track_playback_paused',
'track_playback_ended',
'track_changing',
'track_playback_paused'], self.sequence_match_results,
wait_for='track_changed_next',
interval=interval))
Expand Down Expand Up @@ -341,7 +339,7 @@ def monitor_sequences(self):
match = self.sequence_match_results.get()
self.sequence_match_results.task_done()

if match and match.ratio >= 0.80:
if match and match.ratio == 1.0:
if match.marker.uri and type(PandoraUri.factory(match.marker.uri)) is AdItemUri:
logger.info('Ignoring doubleclick event for Pandora advertisement...')
else:
Expand Down Expand Up @@ -472,12 +470,14 @@ def reset(self):
def get_ratio(self):
if self.wait_for:
# Add 'wait_for' event as well to make ratio more accurate.
self.target_sequence.append(self.wait_for)
match_sequence = self.target_sequence + [self.wait_for]
else:
match_sequence = self.target_sequence
if self.strict:
ratio = EventSequence.match_sequence(self.events_seen, self.target_sequence)
ratio = EventSequence.match_sequence(self.events_seen, match_sequence)
else:
filtered_list = [e for e in self.events_seen if e in self.target_sequence]
ratio = EventSequence.match_sequence(filtered_list, self.target_sequence)
filtered_list = [e for e in self.events_seen if e in match_sequence]
ratio = EventSequence.match_sequence(filtered_list, match_sequence)
if ratio < 1.0 and self.strict:
return 0
return ratio
Expand Down
5 changes: 0 additions & 5 deletions mopidy_pandora/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from pydora.utils import iterate_forever

from mopidy_pandora import utils
from mopidy_pandora.uri import AdItemUri, GenreStationUri, GenreUri, PandoraUri, StationUri, TrackUri # noqa I101

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -52,7 +51,6 @@ def browse(self, uri):
return self._browse_tracks(uri)

def lookup(self, uri):

pandora_uri = PandoraUri.factory(uri)
if isinstance(pandora_uri, TrackUri):
try:
Expand Down Expand Up @@ -132,9 +130,6 @@ def _formatted_station_list(self, list):
return list

def _browse_stations(self):
# Prefetch genre category list
utils.run_async(self.backend.api.get_genre_stations)()

station_directories = []

stations = self.backend.api.get_station_list()
Expand Down
33 changes: 2 additions & 31 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from mopidy_pandora import client, library, playback
from mopidy_pandora.backend import PandoraBackend
from mopidy_pandora.library import PandoraLibraryProvider
from tests.conftest import get_backend, get_station_list_mock, request_exception_mock
from tests.conftest import get_backend


def test_uri_schemes(config):
Expand Down Expand Up @@ -60,40 +60,11 @@ def test_on_start_logs_in(config):

login_mock = mock.Mock()
backend.api.login = login_mock
t = backend.on_start()
t.join()
backend.on_start()

backend.api.login.assert_called_once_with('john', 'smith')


def test_on_start_pre_fetches_lists(config):
with mock.patch.object(APIClient, 'get_station_list', get_station_list_mock):
backend = get_backend(config)

backend.api.login = mock.Mock()
backend.api.get_genre_stations = mock.Mock()

assert backend.api.station_list_cache.currsize == 0
assert backend.api.genre_stations_cache.currsize == 0

t = backend.on_start()
t.join()

assert backend.api.station_list_cache.currsize == 1
assert backend.api.get_genre_stations.called


def test_on_start_handles_request_exception(config, caplog):
backend = get_backend(config, True)

backend.api.login = request_exception_mock
t = backend.on_start()
t.join()

# Check that request exceptions are caught and logged
assert 'Error logging in to Pandora' in caplog.text()


def test_prepare_next_track_triggers_event(config):
with mock.patch.object(PandoraLibraryProvider,
'get_next_pandora_track',
Expand Down

0 comments on commit 9507c40

Please sign in to comment.