Beispiel #1
0
class TestPlayerAndPlaylist(TestCase):
    def setUp(self):
        self.player = MpvPlayer()
        self.playlist = self.player.playlist
        self.player.initialize()

    def tearDown(self):
        self.playlist.clear()
        self.player.shutdown()

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_change_song(self):
        s1 = FakeValidSongModel()
        s2 = FakeValidSongModel()

        playlist = self.player.playlist
        playlist.add(s1)
        playlist.add(s2)

        self.player.play_song(s1)
        self.player.play_next()
        self.assertTrue(playlist.current_song, s2)

        self.player.play_previous()
        self.assertTrue(playlist.current_song, s1)

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_remove_current_song_2(self):
        """当播放列表只有一首歌时,移除它"""
        s1 = FakeValidSongModel()
        self.playlist.current_song = s1
        time.sleep(MPV_SLEEP_SECOND)  # 让 Mpv 真正的开始播放
        self.assertTrue(self.player.state, State.playing)
        self.playlist.remove(s1)
        self.assertEqual(len(self.playlist), 0)
        self.assertEqual(self.player.state, State.stopped)
Beispiel #2
0
class TestPlayerAndPlaylist(TestCase):

    def setUp(self):
        self.player = MpvPlayer()

    def tearDown(self):
        self.player.stop()
        self.player.shutdown()

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    @mock.patch.object(MpvPlayer, 'play')
    def test_change_song(self, _):
        s1 = FakeValidSongModel()
        s2 = FakeValidSongModel()

        playlist = self.player.playlist
        playlist.add(s1)
        playlist.add(s2)

        self.player.play_song(s1)
        playlist.next()
        self.assertTrue(playlist.current_song, s2)

        playlist.previous()
        self.assertTrue(playlist.current_song, s1)

    @skipIf(cannot_play_audio, '')
    @mock.patch.object(MpvPlayer, 'play')
    def test_remove_current_song_2(self, mock_play):
        """当播放列表只有一首歌时,移除它"""
        s1 = FakeValidSongModel()
        self.player.playlist.current_song = s1
        time.sleep(MPV_SLEEP_SECOND)  # 让 Mpv 真正的开始播放
        self.player.playlist.remove(s1)
        self.assertEqual(len(self.player.playlist), 0)
        self.assertEqual(self.player.state, State.stopped)
Beispiel #3
0
 def setUp(self):
     self.player = MpvPlayer()
     self.player.volume = 0
     self.player.initialize()
Beispiel #4
0
class TestPlayer(TestCase):
    def setUp(self):
        self.player = MpvPlayer()
        self.player.volume = 0
        self.player.initialize()

    def tearDown(self):
        self.player.stop()
        self.player.shutdown()

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_play(self):
        self.player.play(MP3_URL)
        self.player.stop()

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_duration(self):
        # This may failed?
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.assertIsNotNone(self.player.duration)

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_seek(self):
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.position = 100

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_replay(self):
        song = FakeValidSongModel()
        self.player.play_song(song)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.position = 100
        self.player.replay()
        time.sleep(MPV_SLEEP_SECOND)
        self.assertTrue(self.player.position < 10)

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_play_pause_toggle_resume_stop(self):
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.toggle()
        self.assertEqual(self.player.state, State.paused)
        self.player.resume()
        self.assertEqual(self.player.state, State.playing)
        self.player.pause()
        self.assertEqual(self.player.state, State.paused)
        self.player.stop()
        self.assertEqual(self.player.state, State.stopped)

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_set_volume(self):
        self.player.volume = 30
        self.assertEqual(self.player.volume, 30)
Beispiel #5
0
def main():
    parser = setup_argparse()
    args = parser.parse_args()

    if is_port_used(23333) or is_port_used(23334):
        print('\033[0;31m', end='')
        print(
            'Port(23333 or 23334) is used, maybe another feeluown is running?')
        print('\033[0m', end='')
        sys.exit(1)

    debug = args.debug
    mpv_audio_device = args.mpv_audio_device
    cli_only = args.no_window
    logger_config(debug, to_file=args.log_to_file)

    from fuocore.player import MpvPlayer

    player = MpvPlayer(audio_device=bytes(mpv_audio_device, 'utf-8'))
    player.initialize()

    # 设置 exception hook
    sys.excepthook = excepthook

    if not cli_only:
        try:
            import PyQt5  # noqa
        except ImportError:
            logger.warning('PyQt5 is not installed,can only use CLI mode.')
            cli_only = True

    if not cli_only:
        from PyQt5.QtWidgets import QApplication
        from quamash import QEventLoop
        from feeluown.guiapp import GuiApp

        q_app = QApplication(sys.argv)
        q_app.setQuitOnLastWindowClosed(True)
        q_app.setApplicationName('FeelUOwn')

        app_event_loop = QEventLoop(q_app)
        asyncio.set_event_loop(app_event_loop)
        pubsub_gateway, pubsub_server = run_pubsub()

        app = GuiApp(pubsub_gateway, player=player)
        app.initialize()
        load_rcfile(app)
        # TODO: 调用 show 时,会弹出主界面,但这时界面还没开始绘制
        # 为了让提升启动速度,一些非必须的初始化操作可以在 show 之后进行
        app.show()
    else:
        from feeluown.app import CliApp

        pubsub_gateway, pubsub_server = run_pubsub()
        app = CliApp(pubsub_gateway)
        app.initialize()

    live_lyric = app.live_lyric
    event_loop = asyncio.get_event_loop()
    event_loop.create_task(run_server(app, live_lyric))
    try:
        event_loop.run_forever()
        logger.info('Event loop stopped.')
    except KeyboardInterrupt:
        # NOTE: gracefully shutdown?
        pass
    finally:
        pubsub_server.close()
        event_loop.close()
Beispiel #6
0
 def setUp(self):
     self.player = MpvPlayer()
     self.player.volume = 0
Beispiel #7
0
class TestPlayer(TestCase):

    def setUp(self):
        self.player = MpvPlayer()
        self.player.volume = 0

    def tearDown(self):
        self.player.stop()
        self.player.shutdown()

    @skipIf(cannot_play_audio, '')
    def test_play(self):
        self.player.play(MP3_URL)
        self.player.stop()

    @skipIf(cannot_play_audio, '')
    def test_duration(self):
        # This may failed?
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.assertIsNotNone(self.player.duration)

    @skipIf(cannot_play_audio, '')
    def test_seek(self):
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.position = 100

    @skipIf(cannot_play_audio, '')
    def test_play_pause_toggle_resume_stop(self):
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.toggle()
        self.assertEqual(self.player.state, State.paused)
        self.player.resume()
        self.assertEqual(self.player.state, State.playing)
        self.player.pause()
        self.assertEqual(self.player.state, State.paused)
        self.player.stop()
        self.assertEqual(self.player.state, State.stopped)

    @skipIf(cannot_play_audio, '')
    def test_set_volume(self):
        cb = mock.Mock()
        self.player.volume_changed.connect(cb)
        self.player.volume = 30
        self.assertEqual(self.player.volume, 30)
        cb.assert_called_once_with(30)

    @mock.patch('fuocore.mpvplayer._mpv_set_option_string')
    def test_play_media_with_http_headers(self, mock_set_option_string):
        media = Media('http://xxx', http_headers={'referer': 'http://xxx'})
        self.player.play(media)
        assert mock_set_option_string.called
        self.player.stop()
Beispiel #8
0
 def setUp(self):
     self.player = MpvPlayer()
Beispiel #9
0
class TestPlayer(TestCase):

    def setUp(self):
        self.player = MpvPlayer()
        self.player.volume = 0
        self.player.initialize()

    def tearDown(self):
        self.player.stop()
        self.player.shutdown()

    @skipIf(cannot_play_audio, '')
    def test_play(self):
        self.player.play(MP3_URL)
        self.player.stop()

    @skipIf(cannot_play_audio, '')
    def test_duration(self):
        # This may failed?
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.assertIsNotNone(self.player.duration)

    @skipIf(cannot_play_audio, '')
    def test_seek(self):
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.position = 100

    @skipIf(cannot_play_audio, '')
    def test_replay(self):
        song = FakeValidSongModel()
        self.player.play_song(song)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.position = 100
        self.player.replay()
        time.sleep(MPV_SLEEP_SECOND)
        self.assertTrue(self.player.position < 10)

    @skipIf(cannot_play_audio, '')
    def test_play_pause_toggle_resume_stop(self):
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.toggle()
        self.assertEqual(self.player.state, State.paused)
        self.player.resume()
        self.assertEqual(self.player.state, State.playing)
        self.player.pause()
        self.assertEqual(self.player.state, State.paused)
        self.player.stop()
        self.assertEqual(self.player.state, State.stopped)

    @skipIf(cannot_play_audio, '')
    def test_set_volume(self):
        self.player.volume = 30
        self.assertEqual(self.player.volume, 30)

    @mock.patch('fuocore.mpvplayer._mpv_set_option_string')
    def test_play_media_with_http_headers(self, mock_set_option_string):
        media = Media('http://xxx', http_headers={'referer': 'http://xxx'})
        self.player.play(media)
        assert mock_set_option_string.called
        self.player.stop()
Beispiel #10
0
 def setUp(self):
     self.player = MpvPlayer()
     self.playlist = self.player.playlist
     self.player.initialize()
Beispiel #11
0
class TestPlayer(TestCase):
    def setUp(self):
        self.player = MpvPlayer()
        self.player.initialize()

    def tearDown(self):
        self.player.shutdown()

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_play(self):
        self.player.play(MP3_URL)
        self.player.stop()

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_duration(self):
        # This may failed?
        self.player.play(MP3_URL)
        time.sleep(0.1)
        self.assertIsNotNone(self.player.duration)

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_seek(self):
        self.player.play(MP3_URL)
        time.sleep(0.1)
        self.player.position = 100