Ejemplo n.º 1
0
def getArtist(result, search_name):
    artist = itunespy.search_artist(search_name)[0]
    name_temp = []
    album_temp = []
    song_temp = []
    year_temp = []
    image_temp = []
    genre_temp = []
    album = artist.get_albums()
    for i in range(len(album)):
        temp = []
        album_temp.append(album[i].collection_name)
        year_temp.append(album[i].release_date[0:10])
        image_temp.append(album[i].artwork_url_100)
        genre_temp.append(album[i].primary_genre_name)
        name_temp.append(album[i].artist_name)

        for track in album[i].get_tracks():
            temp.append(track.track_name)
        song_temp.append(temp)

    for i in range(len(album)):
        data = {}
        data['name'] = name_temp[i]
        data['album'] = album_temp[i]
        data['year'] = year_temp[i]
        data['image'] = image_temp[i]
        data['genre'] = genre_temp[i]
        data['song'] = []
        for j in range(len(song_temp[i])):
            data['song'].append(song_temp[i][j])
        result['artist'].append(ast.literal_eval(json.dumps(data)))
Ejemplo n.º 2
0
def get_artist(artist):
    """
    Returns a list of track objects all made
    by artist.
    """
    results = []
    artists = itunespy.search_artist(artist)
    albums = artists[0].get_albums()
    for album in albums:
        for song in album.get_tracks():
            results.append(song)
    return results
Ejemplo n.º 3
0
def getSongData(track, artist):
    if track and artist:
        for s in itunespy.search_track(track):
            if s.artist_name.lower() == artist.lower():
                return s
    elif track:
        return itunespy.search_track(track)
    elif artist:
        songs = []
        artists = itunespy.search_artist(artist)[0]
        for album in artists.get_albums():
            for s in album.get_tracks():
                songs.append(s)
        return songs
    return
Ejemplo n.º 4
0
 def artist_albums(self):
     artist = itunespy.search_artist(self.query)  # Returns a list
     albums = artist[0].get_albums()  # Get albums from the first result
     display = ''
     for album in albums:
         album_name = album.collection_name
         artist = album.artist_name
         img = album.artwork_url_100
         r_date = album.release_date.split('T')[0]
         length = album.get_album_time()
         # border-style: solid;
         #   border-color: coral;
         display += f'<div>' \
                       f'<img src="{img}" alt="image" style="float:left; height:100px"> ' \
                       f'<div style="float:left; height:100px; width:500px; background-color:black; color:white; ' \
                    f'border-style: solid; border-color: white;">' \
                       f'<span style="font-size:20px;">{album_name} by {artist} </span>' \
                       f'<p style="font-size:15px;">Released on {r_date}</p>' \
                       f'<p style="font-size:15px;">Runtime of {length} minutes</p></div></div>'
     say = f'find displayed albums for {self.query}'
     return {'display': display, 'say': say}
Ejemplo n.º 5
0
def get_itunes_data(data, exit_fail=True):
    """
  Attempts to retrieve song data from the iTunes API
  Args:
    data: A dict of values provided by the user
    exit_fail: A bool specifying if the program should exit if no match
  Returns:
    A dict of song data retrieved from the iTunes API, if a match is found
  Raises:
    LookupError: If a match isn't found using the iTunes API
  """
    try:
        if data['track_name'] and data['artist_name']:
            for song in itunespy.search_track(data['track_name']):
                if data['artist_name'].lower() == song.artist_name.lower():
                    if 'collection_name' not in data.keys():
                        return song
                    elif data['collection_name'].lower(
                    ) in song.collection_name.lower():
                        return song
        elif data['track_name']:
            return itunespy.search_track(data['track_name'])
        elif data['artist_name']:
            songs = []
            artists = itunespy.search_artist(data['artist_name'])[0]
            for album in artists.get_albums():
                for song in album.get_tracks():
                    songs.append(song)
            return songs
        # Attempt to find a close match if no exact matches
        song = itunespy.search(' '.join(
            [data['track_name'], data['artist_name'],
             data['collection_name']]))[0]
        if song:
            return song
    except LookupError as err:
        if exit_fail:
            logging.warning(Fore.RED + '✘ ' + Style.RESET_ALL + ' %s', err)
            sys.exit()
Ejemplo n.º 6
0
def getiTunesData(track, artist, exit_fail=True):
    try:
        if track and artist:
            for song in itunespy.search_track(track):
                if song.artist_name.lower() == artist.lower():
                    return song
        elif track:
            return itunespy.search_track(track)
        elif artist:
            songs = []
            artists = itunespy.search_artist(artist)[0]
            for album in artists.get_albums():
                for song in album.get_tracks():
                    songs.append(song)
            return songs
        # Attempt to find a close match if no exact matches
        song = itunespy.search(' '.join([track, artist]))[0]
        if song:
            return song
    except LookupError as err:
        if exit_fail:
            logging.warning(' ✘ %s', err)
            sys.exit()
Ejemplo n.º 7
0
def input_data():
    """
    None -> array, array

    Return user's input and check if such data exist.

    :return: artists and genres arrays
    """
    artists_list = DynamicArray()
    genres_list = DynamicArray()
    print("Enter at least one artist")
    while True:
        artist_inp = input("Enter artist's name or Enter to finish: ")
        try:
            if len(artist_inp) > 0 or len(artists_list) == 0:
                artist = itunespy.search_artist(artist_inp)
                artists_list.append(artist)
            else:
                break
        except LookupError:
            print(
                "There is no such artist in iTunes database. Try someone else."
            )
            continue

    while True:
        answer = input(
            "Would you like to know genres of your artists?(yes/no) ")
        if answer.lower() == "no":
            break
        elif answer.lower() == "yes":
            genres_set = set()
            for i in artists_list:
                for a in i[0].get_albums():
                    genres_set.add(a.primary_genre_name)

            genres_set = sorted(list(genres_set))
            print("\nGenres of your artists:\n")
            for g in genres_set:
                print(g)
            print("\n")
            break
        else:
            print("Invalid answer!")
            continue

    while True:
        genre = input("Enter genre or Enter to finish: ")
        if len(genre) > 0 or len(genres_list) == 0:
            if len(genre) == 0:
                continue
            ch = False
            for art in artists_list:
                albums = art[0].get_albums()
                for album in albums:
                    if album.primary_genre_name == genre:
                        ch = True
            if not ch:
                print(
                    "Your artist does not work in this genre. Try another one."
                )
                continue
            genres_list.append(genre)
        elif len(genre) == 0:
            break

    return artists_list, genres_list