Remove dead Last.fm library methods
This commit is contained in:
parent
3e097b98fc
commit
f419c39ef0
|
@ -2433,86 +2433,8 @@ class Library(_BaseObject):
|
|||
|
||||
def get_user(self):
|
||||
"""Returns the user who owns this library."""
|
||||
|
||||
return self.user
|
||||
|
||||
def add_album(self, album):
|
||||
"""Add an album to this library."""
|
||||
|
||||
params = self._get_params()
|
||||
params["artist"] = album.get_artist().get_name()
|
||||
params["album"] = album.get_name()
|
||||
|
||||
self._request("library.addAlbum", False, params)
|
||||
|
||||
def remove_album(self, album):
|
||||
"""Remove an album from this library."""
|
||||
|
||||
params = self._get_params()
|
||||
params["artist"] = album.get_artist().get_name()
|
||||
params["album"] = album.get_name()
|
||||
|
||||
self._request(self.ws_prefix + ".removeAlbum", False, params)
|
||||
|
||||
def add_artist(self, artist):
|
||||
"""Add an artist to this library."""
|
||||
|
||||
params = self._get_params()
|
||||
if type(artist) == str:
|
||||
params["artist"] = artist
|
||||
else:
|
||||
params["artist"] = artist.get_name()
|
||||
|
||||
self._request(self.ws_prefix + ".addArtist", False, params)
|
||||
|
||||
def remove_artist(self, artist):
|
||||
"""Remove an artist from this library."""
|
||||
|
||||
params = self._get_params()
|
||||
if type(artist) == str:
|
||||
params["artist"] = artist
|
||||
else:
|
||||
params["artist"] = artist.get_name()
|
||||
|
||||
self._request(self.ws_prefix + ".removeArtist", False, params)
|
||||
|
||||
def add_track(self, track):
|
||||
"""Add a track to this library."""
|
||||
|
||||
params = self._get_params()
|
||||
params["track"] = track.get_title()
|
||||
|
||||
self._request(self.ws_prefix + ".addTrack", False, params)
|
||||
|
||||
def get_albums(self, artist=None, limit=50, cacheable=True):
|
||||
"""
|
||||
Returns a sequence of Album objects
|
||||
If no artist is specified, it will return all, sorted by decreasing
|
||||
play count.
|
||||
If limit==None it will return all (may take a while)
|
||||
"""
|
||||
|
||||
params = self._get_params()
|
||||
if artist:
|
||||
params["artist"] = artist
|
||||
|
||||
seq = []
|
||||
for node in _collect_nodes(
|
||||
limit,
|
||||
self,
|
||||
self.ws_prefix + ".getAlbums",
|
||||
cacheable,
|
||||
params):
|
||||
name = _extract(node, "name")
|
||||
artist = _extract(node, "name", 1)
|
||||
playcount = _number(_extract(node, "playcount"))
|
||||
tagcount = _number(_extract(node, "tagcount"))
|
||||
|
||||
seq.append(LibraryItem(
|
||||
Album(artist, name, self.network), playcount, tagcount))
|
||||
|
||||
return seq
|
||||
|
||||
def get_artists(self, limit=50, cacheable=True):
|
||||
"""
|
||||
Returns a sequence of Album objects
|
||||
|
@ -2535,50 +2457,6 @@ class Library(_BaseObject):
|
|||
|
||||
return seq
|
||||
|
||||
def get_tracks(self, artist=None, album=None, limit=50, cacheable=True):
|
||||
"""
|
||||
Returns a sequence of Album objects
|
||||
If limit==None it will return all (may take a while)
|
||||
"""
|
||||
|
||||
params = self._get_params()
|
||||
if artist:
|
||||
params["artist"] = artist
|
||||
if album:
|
||||
params["album"] = album
|
||||
|
||||
seq = []
|
||||
for node in _collect_nodes(
|
||||
limit,
|
||||
self,
|
||||
self.ws_prefix + ".getTracks",
|
||||
cacheable,
|
||||
params):
|
||||
name = _extract(node, "name")
|
||||
artist = _extract(node, "name", 1)
|
||||
playcount = _number(_extract(node, "playcount"))
|
||||
tagcount = _number(_extract(node, "tagcount"))
|
||||
|
||||
seq.append(LibraryItem(
|
||||
Track(artist, name, self.network), playcount, tagcount))
|
||||
|
||||
return seq
|
||||
|
||||
def remove_scrobble(self, artist, title, timestamp):
|
||||
"""Remove a scrobble from a user's Last.fm library. Parameters:
|
||||
artist (Required) : The artist that composed the track
|
||||
title (Required) : The name of the track
|
||||
timestamp (Required) : The unix timestamp of the scrobble
|
||||
that you wish to remove
|
||||
"""
|
||||
|
||||
params = self._get_params()
|
||||
params["artist"] = artist
|
||||
params["track"] = title
|
||||
params["timestamp"] = timestamp
|
||||
|
||||
self._request(self.ws_prefix + ".removeScrobble", False, params)
|
||||
|
||||
|
||||
class Playlist(_BaseObject):
|
||||
"""A Last.fm user playlist."""
|
||||
|
|
|
@ -74,97 +74,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertEqual(str(last_scrobble.track.title), str(title))
|
||||
self.assertEqual(str(last_scrobble.timestamp), str(timestamp))
|
||||
|
||||
def test_unscrobble(self):
|
||||
# Arrange
|
||||
artist = "Test Artist 2"
|
||||
title = "Test Title 2"
|
||||
timestamp = self.unix_timestamp()
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
self.network.scrobble(artist=artist, title=title, timestamp=timestamp)
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act
|
||||
library.remove_scrobble(
|
||||
artist=artist, title=title, timestamp=timestamp)
|
||||
|
||||
# Assert
|
||||
# limit=2 to ignore now-playing:
|
||||
last_scrobble = lastfm_user.get_recent_tracks(limit=2)[0]
|
||||
self.assertNotEqual(str(last_scrobble.timestamp), str(timestamp))
|
||||
|
||||
def test_add_album(self):
|
||||
# Arrange
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
album = self.network.get_album("Test Artist", "Test Album")
|
||||
|
||||
# Act
|
||||
library.add_album(album)
|
||||
|
||||
# Assert
|
||||
my_albums = library.get_albums()
|
||||
for my_album in my_albums:
|
||||
value = (album == my_album[0])
|
||||
if value:
|
||||
break
|
||||
self.assertTrue(value)
|
||||
|
||||
def test_remove_album(self):
|
||||
# Arrange
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
# Pick an artist with plenty of albums
|
||||
artist = self.network.get_top_artists(limit=1)[0].item
|
||||
albums = artist.get_top_albums()
|
||||
# Pick a random one to avoid problems running concurrent tests
|
||||
album = choice(albums)[0]
|
||||
library.add_album(album)
|
||||
|
||||
# Act
|
||||
library.remove_album(album)
|
||||
|
||||
# Assert
|
||||
my_albums = library.get_albums()
|
||||
for my_album in my_albums:
|
||||
value = (album == my_album[0])
|
||||
if value:
|
||||
break
|
||||
self.assertFalse(value)
|
||||
|
||||
def test_add_artist(self):
|
||||
# Arrange
|
||||
artist = "Test Artist 2"
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
|
||||
# Act
|
||||
library.add_artist(artist)
|
||||
|
||||
# Assert
|
||||
artists = library.get_artists()
|
||||
for artist in artists:
|
||||
value = (str(artist[0]) == "Test Artist 2")
|
||||
if value:
|
||||
break
|
||||
self.assertTrue(value)
|
||||
|
||||
def test_remove_artist(self):
|
||||
# Arrange
|
||||
# Get plenty of artists
|
||||
artists = self.network.get_top_artists()
|
||||
# Pick a random one to avoid problems running concurrent tests
|
||||
my_artist = choice(artists).item
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
library.add_artist(my_artist)
|
||||
|
||||
# Act
|
||||
library.remove_artist(my_artist)
|
||||
|
||||
# Assert
|
||||
artists = library.get_artists()
|
||||
for artist in artists:
|
||||
value = (artist[0] == my_artist)
|
||||
if value:
|
||||
break
|
||||
self.assertFalse(value)
|
||||
|
||||
def test_get_venue(self):
|
||||
# Arrange
|
||||
venue_name = "Last.fm Office"
|
||||
|
@ -259,26 +168,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertNotEqual(str(loved.track.artist), "Test Artist")
|
||||
self.assertNotEqual(str(loved.track.title), "test title")
|
||||
|
||||
def test_get_100_albums(self):
|
||||
# Arrange
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
|
||||
# Act
|
||||
albums = library.get_albums(limit=100)
|
||||
|
||||
# Assert
|
||||
self.assertGreaterEqual(len(albums), 0)
|
||||
|
||||
def test_get_limitless_albums(self):
|
||||
# Arrange
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
|
||||
# Act
|
||||
albums = library.get_albums(limit=None)
|
||||
|
||||
# Assert
|
||||
self.assertGreaterEqual(len(albums), 0)
|
||||
|
||||
def test_user_equals_none(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
|
Loading…
Reference in a new issue