Example #1
0
    def test_bad_tracks_filtered(self, web_artist_mock, web_track_mock):
        refs = list(
            translator.web_to_track_refs([{}, web_track_mock, web_artist_mock])
        )

        assert len(refs) == 1

        assert refs[0].type == models.Ref.TRACK
        assert refs[0].uri == "spotify:track:abc"
Example #2
0
    def test_returns_top_list_tracks(self, web_track_mock):
        web_tracks = [web_track_mock] * 3
        refs = list(translator.web_to_track_refs(web_tracks))

        assert refs == [refs[0], refs[0], refs[0]]

        assert refs[0].type == models.Ref.TRACK
        assert refs[0].uri == "spotify:track:abc"
        assert refs[0].name == "ABC 123"
Example #3
0
    def test_dont_check_playable(self, web_track_mock):
        del web_track_mock["is_playable"]
        refs = list(
            translator.web_to_track_refs([web_track_mock], check_playable=False)
        )

        assert len(refs) == 1

        assert refs[0].type == models.Ref.TRACK
        assert refs[0].uri == "spotify:track:abc"
Example #4
0
def _browse_toplist_user(web_client, variant):
    if not web_client.logged_in:
        return []

    if variant in ("tracks", "artists"):
        items = web_client.get_one(f"me/top/{variant}").get("items", [])
        if variant == "tracks":
            return list(
                translator.web_to_track_refs(items, check_playable=False))
        else:
            return list(translator.web_to_artist_refs(items))
    else:
        return []
Example #5
0
def _browse_your_music(web_client, variant):
    if not web_client.logged_in:
        return []

    if variant in ("tracks", "albums"):
        items = web_client.get_one(
            f"me/{variant}",
            params={
                "market": "from_token"
            },
        ).get("items", [])
        if variant == "tracks":
            return list(translator.web_to_track_refs(items))
        else:
            return list(translator.web_to_album_refs(items))
    else:
        return []
Example #6
0
def _browse_toplist_user(web_client, variant):
    if not web_client.logged_in:
        return []

    if variant in ("tracks", "artists"):
        items = flatten([
            page.get("items", []) for page in web_client.get_all(
                f"me/top/{variant}",
                params={"limit": 50},
            ) if page
        ])
        if variant == "tracks":
            return list(
                translator.web_to_track_refs(items, check_playable=False))
        else:
            return list(translator.web_to_artist_refs(items))
    else:
        return []
Example #7
0
def _browse_your_music(web_client, variant):
    if not web_client.logged_in:
        return []

    if variant in ("tracks", "albums"):
        items = flatten([
            page.get("items", []) for page in web_client.get_all(
                f"me/{variant}",
                params={
                    "market": "from_token",
                    "limit": 50
                },
            ) if page
        ])
        if variant == "tracks":
            return list(translator.web_to_track_refs(items))
        else:
            return list(translator.web_to_album_refs(items))
    else:
        return []
Example #8
0
def _browse_your_music(web_client, variant):
    if not web_client.logged_in:
        return []

    if variant in ("tracks", "albums"):
        items = flatten([
            page.get("items", []) for page in web_client.get_all(
                f"me/{variant}",
                params={
                    "market": "from_token",
                    "limit": 50
                },
            ) if page
        ])
        if variant == "tracks":
            # TODO: without check_playable=False this will hide unplayable
            # tracks; this will bite us when implementing library editing.
            return list(translator.web_to_track_refs(items))
        else:
            return list(translator.web_to_album_refs(items))
    else:
        return []
Example #9
0
    def test_check_playable_default(self, web_track_mock):
        del web_track_mock["is_playable"]
        refs = list(translator.web_to_track_refs([web_track_mock]))

        assert refs == []