Пример #1
0
 def test_sync_with_chart(self, top_tracks_chart, *args):
     top_tracks_chart.return_value = ListModel(["a", "b", "c"])
     actual = LastService.get_tracks(
         type=PlaylistType.CHART.value, limit=10
     )
     self.assertEqual(["a", "b", "c"], actual)
     top_tracks_chart.assert_called_once_with(limit=10)
Пример #2
0
def fetch_tracks(*args):
    kwargs = dict(provider=Provider.lastfm)
    if args:
        kwargs["id"] = lambda x: x in args

    # So wrong, but yaspin doesn't support nested spinners
    LastService.get_tags()
    with spinner("Fetching track lists") as sp:
        for playlist in PlaylistManager.find(**kwargs):
            tracklist = LastService.get_tracks(
                type=playlist.type, **playlist.arguments
            )

            track_ids: List[str] = []
            for entry in tracklist:
                id = TrackManager.set(
                    dict(artist=entry.artist.name, name=entry.name)
                ).id

                if id not in track_ids:
                    track_ids.append(id)

            sp.write(
                "Playlist: {} - {} tracks".format(playlist.id, len(track_ids))
            )
            PlaylistManager.update(playlist, dict(tracks=track_ids))
Пример #3
0
 def test_sync_with_artist_chart(self, get_artist, get_top_tracks, *args):
     get_artist.return_value = Artist(name="queen")
     get_top_tracks.return_value = ListModel(["a", "b", "c"])
     actual = LastService.get_tracks(
         type=PlaylistType.ARTIST.value, limit=10, artist="queeen"
     )
     self.assertEqual(["a", "b", "c"], actual)
     get_artist.assert_called_once_with("queeen")
     get_top_tracks.assert_called_once_with(limit=10)
Пример #4
0
 def test_sync_with_tag_chart(self, get_tag, get_top_tracks, *args):
     get_tag.return_value = Tag(name="rock")
     get_top_tracks.return_value = ListModel(["a", "b", "c"])
     actual = LastService.get_tracks(
         type=PlaylistType.TAG.value, limit=10, tag="rock"
     )
     self.assertEqual(["a", "b", "c"], actual)
     get_tag.assert_called_once_with("rock")
     get_top_tracks.assert_called_once_with(limit=10)
Пример #5
0
 def test_sync_with_country_chart(self, top_tracks_by_country, *args):
     top_tracks_by_country.return_value = ListModel(["a", "b", "c"])
     actual = LastService.get_tracks(
         type=PlaylistType.COUNTRY.value, limit=10, country="greece"
     )
     self.assertEqual(["a", "b", "c"], actual)
     top_tracks_by_country.assert_called_once_with(
         limit=10, country="greece"
     )
Пример #6
0
    def test_sync_with_user_loved_tracks(self, get_user, loved_tracks, *args):
        get_user.return_value = self.get_user()
        loved_tracks.return_value = ListModel(["a", "b", "c"])

        actual = LastService.get_tracks(
            type=PlaylistType.USER_LOVED_TRACKS.value, limit=10, username="******"
        )
        self.assertEqual(["a", "b", "c"], actual)
        get_user.assert_called_once_with("foo")
        loved_tracks.assert_called_once_with(limit=10)
Пример #7
0
    def test_sync_with_user_top_tracks(self, get_user, top_tracks, *args):
        get_user.return_value = self.get_user()
        top_tracks.return_value = ListModel(["a", "b", "c"])

        actual = LastService.get_tracks(
            type=PlaylistType.USER_TOP_TRACKS.value, limit=10, username="******"
        )
        self.assertEqual(["a", "b", "c"], actual)
        get_user.assert_called_once_with("foo")
        top_tracks.assert_called_once_with(
            period=constants.Period.overall, limit=10
        )
Пример #8
0
    def test_sync_with_user_friends_tracks(self, get_user, friends, *args):
        get_user.return_value = self.get_user()
        friend = namedtuple("Friend", ["recent_track"])
        friends.return_value = [
            friend(recent_track=1),
            friend(recent_track=2),
            friend(recent_track=3),
        ]

        actual = LastService.get_tracks(
            type=PlaylistType.USER_FRIENDS_RECENT_TRACKS.value,
            limit=10,
            username="******",
        )
        self.assertEqual([1, 2, 3], actual)
        get_user.assert_called_once_with("foo")
        friends.assert_called_once_with(limit=10, recent_tracks=True)