def test_set_options_triggered_on_core_events(self): with mock.patch.object(PandoraFrontend, 'set_options', mock.Mock()) as set_options_mock: tl_tracks = self.core.tracklist.get_tl_tracks().get() core_events = { 'track_playback_started': { 'tl_track': tl_tracks[0] }, 'track_playback_ended': { 'tl_track': tl_tracks[0], 'time_position': 100 }, 'track_playback_paused': { 'tl_track': tl_tracks[0], 'time_position': 100 }, 'track_playback_resumed': { 'tl_track': tl_tracks[0], 'time_position': 100 }, } self.core.playback.play(tlid=self.tl_tracks[0].tlid) for (event, kwargs) in core_events.items(): self.frontend.setup_required = True listener.send(CoreListener, event, **kwargs) self.replay_events() self.assertEqual(set_options_mock.called, True, "Setup not done for event '{}'".format(event)) set_options_mock.reset_mock()
def test_options_changed_triggers_setup(self, mopidy): with mock.patch.object(PandoraFrontend, 'set_options', mock.Mock()) as set_options_mock: mopidy.core.playback.play(tlid=mopidy.tl_tracks[0].tlid).get() mopidy.frontend.setup_required = False listener.send(CoreListener, 'options_changed') mopidy.replay_events() assert set_options_mock.called
def test_set_options_triggered_on_core_events(self, mopidy): with mock.patch.object(PandoraFrontend, 'set_options', mock.Mock()) as set_options_mock: tl_tracks = mopidy.core.tracklist.get_tl_tracks().get() core_events = { 'track_playback_started': { 'tl_track': tl_tracks[0] }, 'track_playback_ended': { 'tl_track': tl_tracks[0], 'time_position': 100 }, 'track_playback_paused': { 'tl_track': tl_tracks[0], 'time_position': 100 }, 'track_playback_resumed': { 'tl_track': tl_tracks[0], 'time_position': 100 }, } mopidy.core.playback.play(tlid=mopidy.tl_tracks[0].tlid) for (event, kwargs) in core_events.items(): mopidy.frontend.setup_required = True listener.send(CoreListener, event, **kwargs) mopidy.replay_events() assert set_options_mock.called is True set_options_mock.reset_mock()
def test_options_changed_triggers_setup(self): with mock.patch.object(PandoraFrontend, 'set_options', mock.Mock()) as set_options_mock: self.core.playback.play(tlid=self.tl_tracks[0].tlid).get() self.frontend.setup_required = False listener.send(CoreListener, 'options_changed') self.replay_events() assert set_options_mock.called
def test_options_changed_triggers_setup(self, mopidy): with mock.patch.object(PandoraFrontend, "set_options", mock.Mock()) as set_options_mock: mopidy.core.playback.play(tlid=mopidy.tl_tracks[0].tlid).get() mopidy.frontend.setup_required = False listener.send(CoreListener, "options_changed") mopidy.replay_events() assert set_options_mock.called
def test_delete_station_clears_tracklist_on_finish(self, mopidy_with_monitor): mopidy_with_monitor.core.playback.play(tlid=mopidy_with_monitor.tl_tracks[0].tlid) mopidy_with_monitor.replay_events() assert len(mopidy_with_monitor.core.tracklist.get_tl_tracks().get()) > 0 listener.send(PandoraBackendListener, 'event_processed', track_uri=mopidy_with_monitor.tracks[0].uri, pandora_event='delete_station') mopidy_with_monitor.replay_events() assert len(mopidy_with_monitor.core.tracklist.get_tl_tracks().get()) == 0
def test_delete_station_clears_tracklist_on_finish(self): self.core.playback.play(tlid=self.tl_tracks[0].tlid) self.replay_events() assert len(self.core.tracklist.get_tl_tracks().get()) > 0 listener.send(PandoraBackendListener, 'event_processed', track_uri=self.tracks[0].uri, pandora_event='delete_station') self.replay_events() assert len(self.core.tracklist.get_tl_tracks().get()) == 0
def track_playback_ended(self, tl_track, time_position): track = tl_track.track duration = track.length and track.length // 1000 or 0 time_position = time_position // 1000 if time_position < duration // 2 and time_position < 240: logger.debug( 'Track not played long enough too scrobble. (50% or 240s)') return track_id = track.uri.rsplit(':')[-1] logger.debug('Increasing play count: %s', track_id) listener.send(GMusicScrobblerListener, 'increment_song_playcount', track_id=track_id)
def test_delete_station_clears_tracklist_on_finish(self, mopidy_with_monitor): mopidy_with_monitor.core.playback.play( tlid=mopidy_with_monitor.tl_tracks[0].tlid) mopidy_with_monitor.replay_events() assert len( mopidy_with_monitor.core.tracklist.get_tl_tracks().get()) > 0 listener.send(PandoraBackendListener, 'event_processed', track_uri=mopidy_with_monitor.tracks[0].uri, pandora_event='delete_station') mopidy_with_monitor.replay_events() assert len( mopidy_with_monitor.core.tracklist.get_tl_tracks().get()) == 0
def track_playback_ended(self, tl_track, time_position): track = tl_track.track duration = track.length and track.length // 1000 or 0 time_position = time_position // 1000 if time_position < duration // 2 and time_position < 240: logger.debug( 'Track not played long enough too scrobble. (50% or 240s)') return track_id = track.uri.rsplit(':')[-1] logger.debug('Increasing play count: %s', track_id) listener.send( GMusicScrobblerListener, 'increment_song_playcount', track_id=track_id)
def test_set_options_triggered_on_core_events(self, mopidy): with mock.patch.object(PandoraFrontend, 'set_options', mock.Mock()) as set_options_mock: tl_tracks = mopidy.core.tracklist.get_tl_tracks().get() core_events = { 'track_playback_started': {'tl_track': tl_tracks[0]}, 'track_playback_ended': {'tl_track': tl_tracks[0], 'time_position': 100}, 'track_playback_paused': {'tl_track': tl_tracks[0], 'time_position': 100}, 'track_playback_resumed': {'tl_track': tl_tracks[0], 'time_position': 100}, } mopidy.core.playback.play(tlid=mopidy.tl_tracks[0].tlid) for (event, kwargs) in core_events.items(): mopidy.frontend.setup_required = True listener.send(CoreListener, event, **kwargs) mopidy.replay_events() assert set_options_mock.called is True set_options_mock.reset_mock()
def track_playback_ended(self, tl_track, time_position): if self.scrobbling: track = tl_track.track if track.uri.startswith("ytmusic:"): duration = track.length and track.length // 1000 or 0 time_position = time_position // 1000 if time_position < duration // 2 and time_position < 120: logger.debug( "Track not played long enough too scrobble. (50% or 120s)" ) return bId = track.uri.split(":")[2] logger.debug("Scrobbling: %s", bId) listener.send( YTMusicScrobbleListener, "scrobble_track", bId=bId, )
def send(event, **kwargs): """Helper to allow calling of audio listener events""" listener.send(AudioListener, event, **kwargs)
def change_track(self, track): listener.send(PandoraPlaybackListener, 'track_changing', track=track) return super(DummyPandoraPlaybackProviderWithAudioEvents, self).change_track(track)
def send(event, **kwargs): """Helper to allow calling of mixer listener events""" listener.send(MixerListener, event, **kwargs)
def send(event, **kwargs): listener.send(PandoraBackendListener, event, **kwargs)
def change_track(self, track): listener.send(PandoraPlaybackListener, "track_changing", track=track) return super().change_track(track)
def send_idle(self, subsystem): if subsystem: listener.send(session.MpdSession, subsystem)
def send(event, **kwargs): """Helper to allow calling of backend listener events""" listener.send(BackendListener, event, **kwargs)
def send(event, **kwargs): # Sends events to the EventListener for processing listener.send(JellyfinPlaybackListener, event, **kwargs)
def send(event, **kwargs): """Helper to allow calling of core listener events""" listener.send(CoreListener, event, **kwargs)
def send(event, **kwargs): listener.send(EventMonitorListener, event, **kwargs)
def send(event, **kwargs): listener.send(PandoraFrontendListener, event, **kwargs)
def send(event, **kwargs): listener.send(PandoraPlaybackListener, event, **kwargs)