def test_artist_ne_none_is_true(self): # Arrange artist1 = None artist2 = pylast.Artist("Test Artist", self.network) # Act / Assert assert artist1 != artist2
def test_artist_ne_none_is_true(self): # Arrange artist1 = None artist2 = pylast.Artist("Test Artist", self.network) # Act / Assert self.assertNotEqual(artist1, artist2)
def test_artist_eq_none_is_false(self): # Arrange artist1 = None artist2 = pylast.Artist("Test Artist", self.network) # Act / Assert self.assertFalse(artist1 == artist2)
def getBio(artistName): artist = pylast.Artist(artistName, lastfm) if artist: bio = artist.get_bio_content(language="en") if bio: return BeautifulSoup(bio, "lxml").text return None
def get_artist_albums(artist_title, limit, last_fm): try: return pylast.Artist(artist_title, last_fm).get_top_albums(limit=limit) except Exception as e: click.secho(f"get_artist_albums: {artist_title}\nError: {e}", fg='red') time.sleep(20) return get_artist_albums(artist_title, limit, last_fm)
def check_artist(artist): artist_object = pylast.Artist(artist, network) corrected_artist_name = artist_object.get_correction() if not corrected_artist_name: print('No suggested artist.') return artist if (artist == corrected_artist_name): # No change, return immediately and don't waste server hits return artist corrected_artist_object = pylast.Artist(corrected_artist_name, network) if (artist_object != corrected_artist_object): response = input(f"Should artist {artist} be {corrected_artist_name}? (y/N)").lower() if (response == "y"): artist = corrected_artist_name elif (artist != corrected_artist_name): print("Suggested artist name correction does not affect scrobble, ignoring.") return artist
def get_artist_icon(self, artist, image_size=pylast.COVER_SMALL): """ Get artist icon supported sizes: small, medium, large """ artist = self.get_corrected_artist(artist) aobj = pylast.Artist(artist, self.network) return aobj.get_cover_image(image_size)
def test_artist_get_correction(self): # Arrange artist = pylast.Artist("guns and roses", self.network) # Act corrected_artist_name = artist.get_correction() # Assert assert corrected_artist_name == "Guns N' Roses"
def test_repr(self): # Arrange artist = pylast.Artist("Test Artist", self.network) # Act representation = repr(artist) # Assert assert representation.startswith("pylast.Artist('Test Artist',")
def test_get_userplaycount(self): # Arrange artist = pylast.Artist("John Lennon", self.network, username=self.username) # Act playcount = artist.get_userplaycount() # Assert self.assertGreaterEqual(playcount, 0)
def test_get_userplaycount(self): # Arrange artist = pylast.Artist("John Lennon", self.network, username=self.username) # Act playcount = artist.get_userplaycount() # Assert assert playcount >= 0 # whilst xfail: # pragma: no cover
def test_bio_summary(self): # Arrange artist = pylast.Artist("Test Artist", self.network) # Act bio = artist.get_bio_summary(language="en") # Assert self.assertIsNotNone(bio) self.assertGreaterEqual(len(bio), 1)
def test_bio_published_date(self): # Arrange artist = pylast.Artist("Test Artist", self.network) # Act bio = artist.get_bio_published_date() # Assert self.assertIsNotNone(bio) self.assertGreaterEqual(len(bio), 1)
def test_bio_content_none(self): # Arrange # An artist with no biography, with "<content/>" in the API XML artist = pylast.Artist("Mr Sizef + Unquote", self.network) # Act bio = artist.get_bio_content() # Assert assert bio is None
def test_bio_summary(self): # Arrange artist = pylast.Artist("Test Artist", self.network) # Act bio = artist.get_bio_summary(language="en") # Assert assert bio is not None assert len(bio) >= 1
def get_similar_artists(self, artist, limit=10): """ Get similar artists """ artist = self.get_corrected_artist(artist) result = [] aobj = pylast.Artist(artist, self.network) for artist in aobj.get_similar(): result.append(artist.item.name) return result[:limit]
def test_bio_published_date(self): # Arrange artist = pylast.Artist("Test Artist", self.network) # Act bio = artist.get_bio_published_date() # Assert assert bio is not None assert len(bio) >= 1
def get_top_tracks(self, artist): """ Get top tracks by artist """ artist = self.get_corrected_artist(artist) aobj = pylast.Artist(artist, self.network) tracks = self.trackarize(aobj.get_top_tracks()) return [ item for item in tracks if not TrackNormalizer.is_locally_blacklisted(item) ]
def get_top_albums(self, artist): """ Get top albums for provided artist """ album_list = [] artist = self.get_corrected_artist(artist) aobj = pylast.Artist(artist, self.network) albums = aobj.get_top_albums() for album in albums: album_list.append(album.item.title) return album_list
def get_artist_tags(self, artist, limit=10): """ Get artist tags """ tags = [] artist = self.get_corrected_artist(artist) aobj = pylast.Artist(artist, self.network) # make sure this is sorted for tag in sorted(aobj.get_top_tags(), key=lambda item: int(item.weight), reverse=True): tags.append(tag.item.get_name().lower()) return tags[:limit]
def test_unlove(self): # Arrange artist = pylast.Artist("Test Artist", self.network) title = "test title" track = pylast.Track(artist, title, self.network) lastfm_user = self.network.get_user(self.username) track.love() # Act track.unlove() # Assert loved = lastfm_user.get_loved_tracks(limit=1) if len(loved): # OK to be empty but if not: self.assertNotEqual(str(loved.track.artist), "Test Artist") self.assertNotEqual(str(loved.track.title), "test title")
def test_unlove(self): # Arrange artist = pylast.Artist("Test Artist", self.network) title = "test title" track = pylast.Track(artist, title, self.network) lastfm_user = self.network.get_user(self.username) track.love() # Act track.unlove() time.sleep(1) # Delay, for Last.fm latency. TODO Can this be removed later? # Assert loved = lastfm_user.get_loved_tracks(limit=1) if len(loved): # OK to be empty but if not: assert str(loved[0].track.artist) != "Test Artist" assert str(loved[0].track.title) != "test title"
def main(api_data, user_file, ones=10): # Connect to Last.fm API # For usage of the pylast package, type help(pylast) after importing password_hash = pylast.md5(api_data['password']) network = pylast.LastFMNetwork( api_key=api_data['key'], api_secret=api_data['shared_secret'], username=api_data['username'], password_hash=password_hash) # Open up a tab separated file representing a user with open(user_file, 'r') as datafile: tsvin = csv.reader(datafile, delimiter='\t') already_done = [] writeback_dict = {} for dataline in tsvin: # dataline = [userid, artistid, artistname, trackid, trackname] try: # Find artist of track -> top tags of artist artist = pylast.Artist(dataline[3], network) # Skip artists we've already gotten the tags from if artist not in already_done: already_done.append(artist) # Get top tags ts = artist.get_top_tags() # Store and count tags for tag in ts: t = tag[0].name if t in writeback_dict: writeback_dict[t] += 1 else: writeback_dict[t] = 1 except Exception as e: # Skip if we encouter an error continue # Only keep values larger than the specified number of occurrences writeback_dict = {k: v for k, v in writeback_dict.items() if v > ones} # Save the final dict write_to_file(writeback_dict, user_file) print("Done!")
# -*- coding: utf-8 -*- import mock import pytest import six import pylast def mock_network(): return mock.Mock(_get_ws_auth=mock.Mock(return_value=("", "", ""))) @pytest.mark.parametrize( "artist", [ u"\xe9lafdasfdsafdsa", u"ééééééé", pylast.Artist(u"B\xe9l", mock_network()), "fdasfdsafsaf not unicode", ], ) def test_get_cache_key(artist): request = pylast._Request(mock_network(), "some_method", params={"artist": artist}) request._get_cache_key() @pytest.mark.parametrize("obj", [pylast.Artist(u"B\xe9l", mock_network())]) def test_cast_and_hash(obj): assert type(six.text_type(obj)) is six.text_type assert isinstance(hash(obj), int)
def get_artist(name): return pylast.Artist(name, network)
# -*- coding: utf-8 -*- import mock import pytest import six import pylast def mock_network(): return mock.Mock(_get_ws_auth=mock.Mock(return_value=("", "", ""))) @pytest.mark.parametrize('artist', [ u'\xe9lafdasfdsafdsa', u'ééééééé', pylast.Artist(u'B\xe9l', mock_network()), 'fdasfdsafsaf not unicode', ]) def test_get_cache_key(artist): request = pylast._Request(mock_network(), 'some_method', params={'artist': artist}) request._get_cache_key() @pytest.mark.parametrize('obj', [pylast.Artist(u'B\xe9l', mock_network())]) def test_cast_and_hash(obj): assert type(six.text_type(obj)) is six.text_type assert isinstance(hash(obj), int)
def get_artist_tracks(artist_name): network = get_network() artist = pylast.Artist(artist_name, network) return artist.get_top_tracks()
def get_artist_bio(artistName): artist = pylast.Artist(artistName, network) return artist.get_bio_content()
#Your usename and password username = '******' password_hash = pylast.md5('password') #Access LastFm network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET, username=username, password_hash=password_hash) #Authentication user = network.get_authenticated_user(); #Get current song in lastfm song = user.get_now_playing() #Get name of song artist = network.get_artist(song) artist1 = pylast.Artist(song.artist, artist.network) #Search the lyrics in genius by the song's name song = genius.search_song(song) #Take the artists bio from lastfm bio = artist1.get_bio_summary(language='en') #And print everything, for some reason artist.name give the artist and song name print('\n',artist.name, '\n') print(song.lyrics, '\n\n') print('SUMMARY','\n\n',bio)