def run_diagnostics(transport: Transport):
    server = Server(transport=transport,
                    debug=LMS_SETTINGS.DEBUG,
                    cur_player_id=LMS_SETTINGS.DEFAULT_PLAYER,
                    user=LMS_SETTINGS.USERNAME,
                    password=LMS_SETTINGS.PASSWORD)
    assert server.genres
    assert server.playlists
    cur_play_details = server.get_track_details()
    if cur_play_details:
        print("Currently playing: \n >> %s" %
              "\n >> ".join("%s: %s" % (k, ", ".join(v))
                            for k, v in cur_play_details.items()))
    else:
        print("Nothing currently in playlist")

    d = server.get_track_details(offset=+1)
    print("Up next: %s >> %s >> %s" % (d.get(
        'genre', ["Unknown genre"])[0], people_from(
            d, ["Unknown people"])[0], d.get('title', ['Unknown track'])[0]))
    del server
Esempio n. 2
0
def run_diagnostics(sslw):
    server = Server(debug=DEBUG_LMS,
                    ssl_wrap=sslw,
                    cur_player_id=DEFAULT_PLAYER,
                    user=SERVER_USERNAME,
                    password=SERVER_PASSWORD)
    assert server.genres
    assert server.playlists
    assert server.favorites
    cur_play_details = server.get_track_details().values()
    if cur_play_details:
        print("Currently playing: %s" % " >> ".join(cur_play_details))
    else:
        print("Nothing currently in playlist")

    status = server.get_status()
    print("Up next: %s >> %s >> %s" % (status.get(
        'genre', "Unknown genre"), status.get(
            'title', 'Unknown track'), status.get('artist', 'Unknown artist')))
Esempio n. 3
0
def run_diagnostics(transport: Transport):
    server = Server(transport=transport,
                    debug=LMS_SETTINGS.DEBUG,
                    cur_player_id=LMS_SETTINGS.DEFAULT_PLAYER,
                    user=LMS_SETTINGS.USERNAME,
                    password=LMS_SETTINGS.PASSWORD)
    assert server.genres
    assert server.playlists
    cur_play_details = server.get_track_details().values()
    if cur_play_details:
        print("Currently playing: %s" %
              " >> ".join(cur_play_details))
    else:
        print("Nothing currently in playlist")

    status = server.get_status()
    print("Up next: %s >> %s >> %s" % (status.get('genre', "Unknown genre"),
                                       status.get('title', 'Unknown track'),
                                       status.get('artist', 'Unknown artist')))
    del server
Esempio n. 4
0
class TestServerWithFakeTransport(TestCase):
    def setUp(self):
        self.transport = FakeTransport().start()
        self.server = Server(transport=self.transport)

    def test_debug(self):
        Server(self.transport, debug=True)

    def test_unknown_default_player(self):
        transport = FakeTransport(fake_id="foo").start()
        self.server = Server(transport=transport, cur_player_id="GONE")
        assert self.server.cur_player_id == "foo"

    def test_status(self):
        assert self.server.get_milliseconds() == FAKE_LENGTH * 1000

    def test_str(self):
        assert 'localhost:0' in str(self.server)

    def test_login(self):
        self.server = Server(transport=self.transport,
                             user='******',
                             password='******')
        assert self.server.user == 'admin'

    def test_groups(self):
        raw = """"something%3Afoobar playerid%3Aecho6fd1 uuid%3A
            ip%3A127.0.0.1%3A39365
            name%3ALavf%20from%20echo6fd1 seq_no%3A0 model%3Ahttp power%3A1
            isplaying%3A0 canpoweroff%3A0 connected%3A0 isplayer%3A1
            sn%20player%20count%3A0
            other%20player%20count%3A0""".replace('\n', '')
        groups = self.server._groups(raw, 'playerid', ['connected'])
        expected = {
            'playerid': 'echo6fd1',
            'uuid': None,
            'ip': '127.0.0.1:39365',
            'name': 'Lavf from echo6fd1',
            'seq_no': 0,
            'model': 'http',
            'power': True,
            'isplaying': False,
            'canpoweroff': False,
            'connected': False,
            'isplayer': True
        }
        assert next(groups) == expected

    def test_groups_multiple(self):
        raw = """BLAH
        playerindex%3A0 playerid%3A00%3A04%3A20%3A17%3A6f%3Ad1
        uuid%3A968b401ba4791d3fadd152bbac2f1dab ip%3A192.168.1.35%3A23238
        name%3AUpstairs%20Music seq_no%3A0 model%3Areceiver
        modelname%3ASqueezebox%20Receiver power%3A0 isplaying%3A0
        displaytype%3Anone isplayer%3A1 canpoweroff%3A1 connected%3A1
        firmware%3A77
        playerindex%3A2 playerid%3A40%3A16%3A7e%3Aad%3A87%3A07 uuid%3A
        ip%3A192.168.1.37%3A54652 name%3AStudy seq_no%3A0 model%3Asqueezelite
        modelname%3ASqueezeLite power%3A0 isplaying%3A0
        displaytype%3Anone isplayer%3A1 canpoweroff%3A1 connected%3A1
        firmware%3Av1.8 sn%20player%20count%3A0 other%20player%20count%3A0
""".replace('\n', '')
        groups = self.server._groups(raw, 'playerid')
        players = list(groups)
        assert len(players) == 2
        first = players[0]
        assert first['playerid'] == "00:04:20:17:6f:d1"
        assert players[1]['name'] == "Study"
        for data in groups:
            assert 'playerid' in data

    def test_groups_dodgy(self):
        raw = "blah bar%3Abaz"
        groups = list(self.server._groups(raw, start_key="id"))
        assert not groups

    def test_groups_status(self):
        data = next(self.server._groups(A_REAL_STATUS))
        assert data['player_name'] == 'Study'
        assert data['playlist_cur_index'] == 20
        assert data['artist'] == 'Jamie Cullum'
        assert isinstance(data['can_seek'], bool)

    def test_faves(self):
        assert len(self.server.favorites) == 2

    def test_playlists(self):
        assert len(self.server.playlists) == 0

    def test_genres(self):
        assert len(self.server.genres) == 0

    def test_change_volume(self):
        self.server.change_volume(3)
        assert "mixer volume +3" in self.transport.all_input

    def test_change_volume_zero(self):
        self.server.change_volume(0)
        assert "mixer volume" not in self.transport.all_input

    def test_track_details(self):
        details = self.server.get_track_details()
        assert ["Jamie Cullum"] == details['artist']

    def test_disconnected_transport(self):
        self.transport.is_connected = False
        with raises(SqueezeboxException) as e:
            self.server._request(["foo"])
        assert "Can't do 'foo'" in str(e)

    def test_disconnected_transport_player_request(self):
        self.transport.is_connected = False
        with raises(SqueezeboxException) as e:
            self.server.player_request("foo", player_id=A_PLAYER_ID)
        assert "Can't do 'foo'" in str(e)