Esempio n. 1
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
Esempio n. 2
0
def get_track_on_album(track, album):
    """
    Returns a single track object off album.
    """
    for song in itunespy.search_track(track):
        if song.collection_name.lower() == album.lower():
            return song
Esempio n. 3
0
File: tag.py Progetto: RYSKZ/SongCat
def tag_song(filename):
    print("\nCurrent file: " + os.path.basename(filename))

    if "-q" in OPTIONS:
        query = [input("Search query: ")]
    else:
        query = guess_title(filename)
        sys.stdout.write("Searching track: " + '"' +
                         capitalize_string(query[0]))

        if len(query) > 1:
            sys.stdout.write(" - ")
            artists = query[1:]

            if len(artists) > 2:
                for index, artist in enumerate(artists):
                    sys.stdout.write(artist)

                    if index == len(artists) - 2:
                        sys.stdout.write(" & ")
                    elif index != len(artists) - 1:
                        sys.stdout.write(", ")
            else:
                sys.stdout.write(artists[0])

        print('"')
    itunespy.search_track(" ".join(query))
    response = "y"

    try:
        itunespy.search_track(" ".join(query))
        response = "y"

        while response == "y":
            tags = get_tags(filename, [" ".join(query)])
            print_tags(tags)
            response = write_tags(filename, tags)

            if response == "y":
                OPTIONS.append("-q")
                OPTIONS.append("-l")
    except LookupError:
        print("\nNo results found for the song :(")
        print(
            "Please manually provide a search query, if that doesn't work out either, try changing the search terms."
        )
Esempio n. 4
0
def get_track(track, artist):
    """
    Returns a single track object from the itunespy module.
    """
    songs = itunespy.search_track(track)
    for song in songs:
        if song.artist_name.lower() == artist.lower():
            return song
Esempio n. 5
0
def get_from_itunes(SONG_NAME):
    """Try to download the metadata using itunespy."""
    # Try to get the song data from itunes
    try:
        SONG_INFO = itunespy.search_track(SONG_NAME)
        return SONG_INFO
    except Exception:
        pass
    def process_function(query):
        print('>>>>>')
        print(query)
        #global queryStr
        main_class.queryStr = query
        translator = Translator()
        main_class.queryStr = translator.translate(main_class.queryStr).text
        main_class.terminal_function()

        #find max score page
        with open('savers/store.json') as json_data:
            score = json.load(json_data)
        sorted_score = sorted(score, key=score.get, reverse=True)
        '''
        docFiles = [f for f in os.listdir('./corpus') if f.endswith(".txt")]
        docFiles.sort()
        '''
        for i in sorted_score[:10]:
            print(i)

        #end of find max

        linkNumber_list = sorted_score[:10]
        docList = []
        #docList.clear()
        f = open("songname.txt")
        data = f.read()
        data = data.split("\n")
        print(linkNumber_list)
        for linkNum in linkNumber_list:
            docList.append(data[int(linkNum) + 2])
        newlist = []
        for list in docList:
            list = list.split("==")[1]
            s = ""
            s = list + "   Release Date   : " + "" + (
                itunespy.search_track(list)[0].release_date).split(
                    "T"
                )[0] + "   Artist Name:    " + (
                    itunespy.search_track(list)[0].artist_name)
            #s=list+":" + "" + (itunespy.search_track(list)[0].release_date).split("T")[0]+ ":" + (itunespy.search_track(list)[0].artist_name)

            newlist.append(s)
            print(s)
        return newlist
Esempio n. 7
0
def get_from_itunes(SONG_NAME):
    """Try to download the metadata using itunespy."""
    # Try to get the song data from itunes
    try:
        SONG_INFO = itunespy.search_track(SONG_NAME)
        return SONG_INFO
    except Exception as e:
        _logger_provider_error(e, 'iTunes')
        return None
Esempio n. 8
0
def getsonglength(query, artist):
    try:
        if "(" in query:
            index = query.find("(")
            tracks = itunespy.search_track(query[:index])
            info = tracks[0].get_track_time_minutes()
            return info
        else:
            tracks = itunespy.search_track(query)
            info = tracks[0].get_track_time_minutes()
            return info
    except:
        print(
            "There is an error, you need to retype the song name. Song name: "
            + query + " by " + artist)
        user = input("Retype song name:")
        tracks = itunespy.search_track(user)
        info = tracks[0].get_track_time_minutes()
        return info
def query_itunes(song_properties):  # perhaps the param should be named youtube_video_title
    """Download video metadata using itunespy."""
    try:
        song_itunes = itunespy.search_track(song_properties)
        # Before returning convert all the track_time values to minutes.
        for song in song_itunes:
            song.track_time = round(song.track_time / 60000, 2)
        return song_itunes
    except Exception as error:
        return
Esempio n. 10
0
def get_from_itunes(SONG_NAME):
    """Try to download the metadata using itunespy."""
    # Try to get the song data from itunes
    try:
        # Get the country from the config
        country = defaults.DEFAULT.ITUNES_COUNTRY
        SONG_INFO = itunespy.search_track(SONG_NAME, country=country)
        return SONG_INFO
    except Exception as e:
        _logger_provider_error(e, 'iTunes')
        return None
Esempio n. 11
0
def get_from_itunes(SONG_NAME):
    """Try to download the metadata using itunespy."""
    # Try to get the song data from itunes
    try:
        SONG_INFO = itunespy.search_track(SONG_NAME)
        # Before returning convert all the track_time values to minutes.
        for song in SONG_INFO:
            song.track_time = round(song.track_time / 60000, 2)
        return SONG_INFO
    except Exception:
        pass
def get_artwork(search_query, track_name):
    track = False
    try:
        track = itunespy.search_track(search_query)
    except:
        return
    if track:
        # print(track[0].get_artwork_url())
        artwork_url = track[0].get_artwork_url()
        urllib.request.urlretrieve(artwork_url, "%s.jpg" % search_query)  # Writing same as audio file
        write_artwork(search_query, track_name)
Esempio n. 13
0
File: tag.py Progetto: RYSKZ/SongCat
def get_tags(filename, query):
    option = 0

    if "-l" in OPTIONS or "-A" not in OPTIONS:
        results = itunespy.search_track(" ".join(query), limit=10)

        for index, result in enumerate(results):
            sys.stdout.write(
                f"\n{index + 1}.Title: {result.track_name}, Album: {result.collection_name}, Artists: {result.artist_name}"
            )

            if index == 0:
                print(" <- Default")
            else:
                print("")

        option = input("\nEnter selection: ") or 1

        option = int(option) - 1

        if option < 0 or option > len(results):
            option = 0

    track = itunespy.search_track(" ".join(query))[option]

    tags = {
        "title": track.track_name,
        "album_title": track.collection_name,
        "artists": [track.artist_name],
        "release_date": track.parsed_release_date.strftime("%d-%m-%Y"),
        "track_number": f"{track.track_number}/{track.track_count}",
        "total_tracks": track.track_count,
        "genre": track.primary_genre_name,
        "album_artist": track.artist_name,
        "disc_number": f"{track.disc_number}/{track.disc_count}",
        "duration": track.track_time,
    }

    return correct_tags(filename, tags)
Esempio n. 14
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()
Esempio n. 15
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()
Esempio n. 16
0
def itunes_search(song, artist):
    '''
    Check if iTunes has a higher definition album cover and
    return the url if found
    '''

    try:
        matches = itunespy.search_track(song)
    except LookupError:
        return None

    for match in matches:
        if match.artist_name == artist:
            return match.artwork_url_100.replace('100x100b', '5000x5000b')
Esempio n. 17
0
def get_metadata(title: str):
    logger.debug("Getting metadata for %s.", title)
    try:
        # hopefully in the "artist - track" format
        if " - " in title:
            artist_name, track_name = title.split(" - ", 1)
            return Bunch(artist_name=artist_name.strip(),
                         track_name=track_name.strip())
        # if not, searching tags on itunes
        else:
            return itunespy.search_track(title)[0]
    except Exception as e:
        logger.error("Error finding tags for %s : %s.", title, e)
        return None
Esempio n. 18
0
def main():
    audio_name = input(
        "Input file name with file type/ALL/EXIT (DO NOT add .mp3 at the end of the file): \n"
    )
    filename = ''
    if audio_name != "ALL":
        aString = audioSearch(audio_name + ".mp3")
        if " - " in audio_name:
            artist_name, audio_title = audio_name.split(" - ")
            if " [" in audio_title:
                audio_title = audio_title.split(" [")[0]
            elif "[" in audio_title:
                audio_title = audio_title.split("[")[0]
            elif " (" in audio_title:
                audio_title = audio_title.split(" (")[0]
            elif "(" in audio_title:
                audio_title = audio_title.split("(")[0]
        elif "-" in audio_name:
            artist_name, audio_title = audio_name.split("-")
            if " [" in audio_title:
                audio_title = audio_title.split(" [")[0]
            elif "[" in audio_title:
                audio_title = audio_title.split("[")[0]
            elif " (" in audio_title:
                audio_title = audio_title.split(" (")[0]
            elif "(" in audio_title:
                audio_title = audio_title.split("(")[0]
        else:
            audio_title = audio_name
            track = itunespy.search_track(audio_title)
            artist_name = track[0].artist_name
        print(audio_title + artist_name)
        if aString == "find":
            print("Could not find file, checking videos for closest match")
            vidURL = yturl(audio_title, artist_name)
            filename = vidDL(vidURL)
        album_title = findAlbum(audio_title, artist_name)
        # Find Album Art
        aString = audioSearch(audio_name + ".mp3")
        textTags(filename, artist_name, album_title, audio_title)
    elif audio_name == "ALL":
        print("To Be Added")
    elif audio_name == "EXIT":
        print(
            "program ended, restart the console if you wish to proceed again")
        return
    else:
        print("invalid input")
        main()
Esempio n. 19
0
def getData(SONG_NAME):
    # Try to get the song data from itunes
    try:
        SONG_INFO = itunespy.search_track(SONG_NAME)
        return SONG_INFO
    except LookupError:
        PREPEND(2)
        print('Song not found!')
        return False
    except TimeoutError:
        PREPEND(2)
        print('Search timed out. Are you connected to internet?\a')
        return False
    else:
        PREPEND(2)
        print('Unknown Error!\a')
        return False
Esempio n. 20
0
def findAlbum(title, artist):
    tracks = itunespy.search_track(title)
    i = 1
    for x in tracks:
        if x.artist_name == artist:
            return x.collection_name