Пример #1
0
 def get_artist(self, id):
     print(f'calling Spotify to get artist with id of {id}')
     spotify_artist = self.sp.artist(id)
     artist = Artist()
     artist.id = spotify_artist['id']
     artist.name = spotify_artist['name']
     artist.genres = spotify_artist['genres']
     return artist
Пример #2
0
 def get_artist(self, id, name=None):
     """
     Returns an Artist for the passed ID, associated with this API object. You'll need to call Artist.update_data()
     if the artist hasn't already been cached. This is done on demand to reduce unnecessary API calls.
     """
     id = int(id)
     if id in self.cached_artists.keys():
         artist = self.cached_artists[id]
     else:
         artist = Artist(id, self)
     if name:
         artist.name = name
     return artist
Пример #3
0
 def get_artist(self, id, name=None):
     """
     Returns an Artist for the passed ID, associated with this API object. You'll need to call Artist.update_data()
     if the artist hasn't already been cached. This is done on demand to reduce unnecessary API calls.
     """
     id = int(id)
     if id in self.cached_artists.keys():
         artist = self.cached_artists[id]
     else:
         artist = Artist(id, self)
     if name:
         artist.name = name
     return artist
Пример #4
0
    def search_by_artist(self, criteria):
        print(f'searching Spotify by artist with criteria of {criteria}')

        results = self.sp.search(q=criteria, limit=1, type="artist")

        total_found = results['artists']['total']

        if total_found <= 0:
            print(f'No artists found for {criteria}')
            raise KeyError(f'No artists found for {criteria}')

        if total_found > 1:
            print(
                f'Too many artists found for {criteria}.  Found {total_found}')
            raise IndexError(
                f'Too many artists found for {criteria}.  Found {total_found}')

        for i, a in enumerate(results['artists']['items']):
            artist = Artist()
            artist.id = a['id']
            artist.name = a['name']
            artist.genres = a['genres']
            return artist
Пример #5
0
    def start(self):
        print(f'Beginning file system crawling process....')
        finished = []
        all_artists = os.listdir(self.base_path)
        for artist_name in all_artists:
            print(f'Processing artist: {artist_name}')
            artist_path = os.path.join(self.base_path, artist_name)
            if os.path.isdir(artist_path):
                # we have found a folder corresponding to an artist
                artist = Artist(path=artist_path)
                artist.name = artist_name
                all_material = os.listdir(artist_path)
                for item in all_material:
                    item_path = os.path.join(artist_path, item)
                    if os.path.isdir(item_path):
                        # we have found a folder corresponding to an album
                        album = Album(path=item_path)
                        album.artist = artist.name
                        album.title = item
                        artist.albums.append(album)
                        album_contents = os.listdir(item_path)
                        for content in album_contents:
                            content_path = os.path.join(item_path, content)
                            if os.path.isdir(content_path):
                                disc_contents = os.listdir(content_path)
                                for disc_item in disc_contents:
                                    disc_item_path = os.path.join(
                                        content_path, disc_item)
                                    if os.path.isdir(disc_item_path):
                                        print(
                                            f'{disc_item}: Processing a directory at this level is currently unsupported'
                                        )
                                    else:
                                        if content.endswith(
                                                ".mp3") or content.endswith(
                                                    ".wma"):
                                            track = Track(path=content_path)
                                            track.artist = artist.name
                                            track.title = util.clean_file_name(
                                                content)
                                            track.number = util.get_track_number_from_file_name(
                                                content)
                                            # get disc number from folder name
                                            track.disc_number = 1
                                            #  a disc object needs created and the track added to the disc
                                            # album.tracks.append(track)
                                        else:
                                            print(
                                                f'{content}: Processing a file type other than mp3 at this level is currently unsupported'
                                            )
                                # TODO: This must be a multi-disc set
                                print(
                                    f'{content} is actually another directory')
                            else:
                                if content.endswith(
                                        ".mp3") or content.endswith(".wma"):
                                    track = Track(path=content_path)
                                    track.artist = artist.name
                                    track.title = util.clean_file_name(content)
                                    track.number = util.get_track_number_from_file_name(
                                        content)
                                    album.tracks.append(track)
                                else:
                                    print(
                                        f'{content}: Processing a file type other than mp3 at this level is currently unsupported'
                                    )
                    else:
                        # we have potentially found a track that isn't associated with an album
                        if item.endswith(".mp3"):
                            track = Track(path=item_path)
                            track.artist = artist.name
                            track.title = util.clean_file_name(item)
                            track.number = util.get_track_number_from_file_name(
                                item)
                            artist.songs.append(track)
                        else:
                            print(
                                f'{item}: Processing a file type other than mp3 at this level is currently unsupported'
                            )
                finished.append(artist)
            else:
                print(
                    f'{artist_name}: Processing a file at this level in the file system is currently unsupported'
                )

        for artist in finished:
            print(artist.pretty_print(include_paths=True))