示例#1
0
    def test_album_ne_none_is_true(self):
        # Arrange
        album1 = None
        album2 = pylast.Album("Test Artist", "Test Album", self.network)

        # Act / Assert
        assert album1 != album2
示例#2
0
    def test_album_ne_none_is_true(self):
        # Arrange
        album1 = None
        album2 = pylast.Album("Test Artist", "Test Album", self.network)

        # Act / Assert
        self.assertNotEqual(album1, album2)
示例#3
0
    def test_album_eq_none_is_false(self):
        # Arrange
        album1 = None
        album2 = pylast.Album("Test Artist", "Test Album", self.network)

        # Act / Assert
        self.assertFalse(album1 == album2)
示例#4
0
    def test_album_wiki_summary(self):
        # Arrange
        album = pylast.Album("Test Artist", "Test Album", self.network)

        # Act
        wiki = album.get_wiki_summary()

        # Assert
        self.assertIsNotNone(wiki)
        self.assertGreaterEqual(len(wiki), 1)
示例#5
0
    def test_album_wiki_summary(self):
        # Arrange
        album = pylast.Album("Test Artist", "Test Album", self.network)

        # Act
        wiki = album.get_wiki_summary()

        # Assert
        assert wiki is not None
        assert len(wiki) >= 1
示例#6
0
 def get_tracks_for_album(self, artist, album):
     """
     Get top tracks for artist + album
     """
     result = []
     artist = self.get_corrected_artist(artist)
     tracks = pylast.Album(artist, album.title(), self.network).get_tracks()
     for track in tracks:
         pretty_track = track.artist.name + ' - ' + track.title
         if not TrackNormalizer.is_locally_blacklisted(pretty_track):
             result.append(pretty_track)
     return result
示例#7
0
    def test_album_tracks(self):
        # Arrange
        album = pylast.Album("Test Artist", "Test", self.network)

        # Act
        tracks = album.get_tracks()
        url = tracks[0].get_url()

        # Assert
        assert isinstance(tracks, list)
        assert isinstance(tracks[0], pylast.Track)
        assert len(tracks) == 1
        assert url.startswith("https://www.last.fm/music/test")
示例#8
0
def get_album_tracks(artist_title, album_title, last_fm):
    try:
        return pylast.Album(artist_title, album_title, last_fm).get_tracks()
    except pylast.WSError as e:
        if "Album not found" in e.details:
            return None
    except pylast.MalformedResponseError as e:
        click.secho(f"get_album_tracks: {artist_title} - {album_title}\nError: {e}", fg='red')
        return None
    except Exception as e:
        click.secho(f"get_album_tracks: {artist_title} - {album_title}\nError: {e}", fg='red')
        time.sleep(20)
        return get_album_tracks(artist_title, album_title, last_fm)
示例#9
0
    def test_album_tracks(self):
        # Arrange
        album = pylast.Album("Test Artist", "Test Release", self.network)

        # Act
        tracks = album.get_tracks()
        url = tracks[0].get_url()

        # Assert
        self.assertIsInstance(tracks, list)
        self.assertIsInstance(tracks[0], pylast.Track)
        self.assertEqual(len(tracks), 4)
        self.assertTrue(url.startswith("https://www.last.fm/music/test"))
示例#10
0
def get_static_album(api_data, pikfile):
    # 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)

    # Get the information from lastfm servers
    try:
        default_album = pylast.Album("Metallica", "Death Magnetic", network)
        albumTTags = default_album.get_top_tags(limit=250)

        # Make a vector from the album
        albumVec = tgal.get_album_vector(albumTTags, pikfile)
        return (str(default_album), albumVec)

    except Exception as e:
        print("Something went wrong. Maybe the input arguments are \
        incompatible. The error message is:")
        print(e)
示例#11
0
    def get_album_image(self, **kwargs):
        if not len(kwargs['artist']):
            return None
        title = ''
        if 'album_art' in kwargs.keys() and len(kwargs['album_art']) > 0:
            self.album_art = kwargs['album_art']
            # this is a dirty hack for a local ip address
            if '192.168' not in self.album_art:
                return kwargs['album_art']

        if 'title' in kwargs.keys():
            if ' (' in kwargs['title']:
                # this is usually a featuring, which lastfm doesn't like
                # so we strip off from that space to the end of the string
                title = kwargs['title'][:kwargs['title'].index(' (')]
            else:
                title = kwargs['title']
        else:
            return None

        # get the album information for this track
        album = pylast.Album(kwargs['artist'], title, self.network)
        try:
            coverImage = album.get_cover_image()
            self.album_art = coverImage
            if coverImage:
                return coverImage
        except pylast.WSError:
            coverImage = None
            print(
                "AlbumManager: can't find album details for %(title)s by %(artist)s from lastfm"
                % kwargs)
        except:
            # usually this is an add in our music stream
            print('AlbumManager: unknown lastfm failure')
            print(kwargs)
            traceback.print_exc()

        artist = self.network.get_artist(kwargs['artist'])
        # [[pylast.album, 125356], [album, ...]]
        album_list = artist.get_top_albums()

        #search for the right album title
        for album in album_list:
            if str(album[0].title).lower() in str(kwargs['album']).lower():
                print("AlbumManager: found album %s from the info given" %
                      album[0].title)
                self.album_art = album[0].get_cover_image()
                return self.album_art

        if len(album_list) > 0:
            print(
                'AlbumManager: unable to find a matching album cover, using %s'
                % album_list[0][0].title)
            self.album_art = album_list[0][0].get_cover_image()
            return self.album_art

        # if we still can't find it then just get a picture of the artist
        artist = network.get_artist(artist)
        self.album_art = artist.get_cover_image()

        return self.album_art