def main():
    args = parser.parse_args()
    new_foldername = copy_dir(args.foldername)
    file_lists = get_music(new_foldername=new_foldername)
    mp3_lists = file_lists['mp3']
    prev_separator = None
    for _path in mp3_lists.keys():
        for _mp3_file in mp3_lists[_path]:
            # update the metadata for the mp3
            _audiofile = eyed3.load(_mp3_file)
            # check that the title exists
            guess = guess_title(_mp3_file, mp3_lists[_path], prev_separator)
            if _audiofile.tag is None:
                _audiofile.initTag()
            prev_separator = guess['separator']
            if _audiofile.tag.title is None or args.ignore:
                print("file: "+_mp3_file+" is missing the title, guess is: "+
                      guess['title'])
                _audiofile.tag.title = check_mappings(guess['title'])
            else:
                guess['title'] = _audiofile.tag.title
            if _audiofile.tag.album is None or args.ignore:
                album = guess_album(_path, guess['artist'])
                print("file: "+_mp3_file+" is missing the album, guess is: "+
                      album)
                _audiofile.tag.album = check_mappings(album)
            if _audiofile.tag.artist is None or args.ignore:
                print("file: "+_mp3_file+" is missing the artist, guess is: "
                      +guess['artist'])
                _audiofile.tag.artist = check_mappings(guess['artist'])
            else:
                _audiofile.tag.artist = check_mappings(_audiofile.tag.artist)
            _audiofile.tag.save()
Exemple #2
0
def main():
    args = parser.parse_args()
    args.foldername = os.path.expanduser(args.foldername)
    new_foldername = args.foldername
    # keep a list of all cues and flacs
    file_lists = get_music(new_foldername=new_foldername)
    music_filenames = file_lists['mp3']
    # now, for each file, get the mp3 tags and get the date created
    music_dataframe = []
    for music_file in music_filenames:
        try:
            tag = TinyTag.get(music_file)
        except Exception as e:
            print e
            next
        if tag.artist is not None:
            artist = tag.artist.encode('ascii', 'ignore')
        if tag.album is not None:
            album = tag.album.encode('ascii', 'ignore')
        if tag.title is not None:
            title = tag.title.encode('ascii', 'ignore')
        date_changed = os.path.getmtime(music_file)
        music_dataframe.append({'artist':artist,'album':album,'title':title,'date':date_changed})


    music_dataframe = DataFrame(music_dataframe)
    music_dataframe.to_csv("mp3_tags.csv")
def main():
    args = parser.parse_args()
    #new_foldername = copy_dir(args.foldername)
    new_foldername = args.foldername
    file_lists = get_music(new_foldername=new_foldername)
    mp3_lists = file_lists['mp3']
    path_images = file_lists['images']
    total_tracks = 0
    prev_separator = None
    for _path in mp3_lists.keys():
        for _mp3_file in mp3_lists[_path]:
            save_track = False
            total_tracks += 1
            print(_mp3_file)

            # update the metadata for the mp3
            guess = guess_title(_mp3_file, mp3_lists[_path],
                        prev_separator, verbose=True)
            # remove whitespace and
            for key in guess.keys():
                guess[key] = guess[key].strip().title()
            print(guess)
            prev_separator = guess['separator']
            _audiofile = eyed3.load(_mp3_file)
            if _audiofile.tag.title is None:
                print "file: "+_mp3_file+" is missing the title, guess is: \""+guess['title']+"\""
                response = raw_input("Accept new title? (y/n)")
                if response == 'y':
                    _audiofile.tag.title = unicode(guess['title'])
                    save_track = True
            if _audiofile.tag.album is None:
                album = guess['album']
                #album = guess_album(_mp3_file, artist=guess['artist'],
                #                    title=guess['title'])
                print "file: "+_mp3_file+" is missing the album, guess is: \""+album+"\""
                response = raw_input("Accept new album? (y/n)")
                if response == 'y':
                    _audiofile.tag.album = unicode(album)
                    save_track = True
            if _audiofile.tag.artist is None:
                 print "file: "+_mp3_file+" is missing the artist, guess is: \""+guess['artist']+"\""
                 response = raw_input("Accept new artist? (y/n)")
                 if response == 'y':
                    _audiofile.tag.artist = unicode(guess['artist'])
                    save_track = True
            if len(_audiofile.tag.images) == 0:
                print "file: "+_mp3_file+" missing images"
                if _path in path_images:
                    response = raw_input("Use image: "+str(path_images[_path])+" ("
                                                                  "y/n)?")
                    if response == 'y':
                        _image_path = os.path.join(_path, path_images[_path])
                        jpgfile = open(_image_path, "rb")
                        _audiofile.tag.images.set(0x03, jpgfile.read(), 'image/jpeg')
                        jpgfile.close()
                        save_track = True
            if save_track:
                _audiofile.tag.save(filename=_mp3_file,version=eyed3.id3.ID3_V2_4)
    print "total tracks: "+str(total_tracks)
def main():
    args = parser.parse_args()
    if args.destination is not None:
        file_lists = get_music(new_foldername=args.foldername)
        mp3_lists = file_lists['mp3']
        reorganize_music(args.destination, mp3_lists)
    else:
        print("Please specify a destination folder")
Exemple #5
0
def main():
    args = parser.parse_args()
    if not hasattr(args, 'online'):
        args.online = False
    if args.copy:
        new_foldername = copy_dir(args.foldername)
    else:
        new_foldername = args.foldername
    file_lists = get_music(new_foldername=new_foldername)
    mp3_lists = file_lists['mp3']
    path_images = file_lists['images']
    seen_covers = {}
    web_search = args.online
    print(web_search)
    for _path in mp3_lists.keys():
        current_track = 1
        for _mp3_file in mp3_lists[_path]:

            # update the metadata for the mp3
            _audiofile = eyed3.load(_mp3_file)
            if _audiofile.tag.artist is None or _audiofile.tag.album is None:
                print("Could not find tags on track ", _mp3_file, " aborting.")
                continue
            if len(_audiofile.tag.images) > 0 and not args.ignore:
                continue

            cover_key = _audiofile.tag.artist+"_"+_audiofile.tag.album
            if _audiofile.tag is None:
                print "initializing tag"
                # the track likely has no tags
                _audiofile.tag = eyed3.id3.tag.Tag()

            if _path in path_images.keys():
                _image_path = os.path.join(_path, path_images[_path])
                jpgfile = open(_image_path, "rb")
                _audiofile.tag.images.set(0x03, jpgfile.read(), 'image/jpeg')
                jpgfile.close()
                _audiofile.tag.save(filename=_mp3_file,
                                    version=eyed3.id3.ID3_V2_4)
            else:
                if cover_key not in seen_covers.keys() and web_search:
                    print "cover key not in seen covers, going to search the web"
                    web_image = get_image(_audiofile.tag.album,
                                          _audiofile.tag.artist,
                                                  web_search)
                    if web_image is None:
                        print "search failed for: ("+cover_key+")"
                        continue
                    try:
                        if isinstance(web_image, list):
                            for _item in web_image:
                                if check_image(_item, cover_key):
                                    seen_covers[cover_key] = _item
                                    break
                        if isinstance(web_image, basestring):
                            if check_image(web_image, cover_key):
                                seen_covers[cover_key] = web_image
                    except Exception as e:
                        print "Critical failure on: "+cover_key
                        print(e)
                        seen_covers[cover_key] = 'invalid'
                        continue
                if not cover_key in seen_covers.keys():
                    seen_covers[cover_key] = 'invalid'

                if seen_covers[cover_key] != "invalid":
                    jpgfile = open(seen_covers[cover_key], "rb")
                    img = Image.open(jpgfile)
                    img = img.resize((400, 400))
                    img.save(seen_covers[cover_key])
                    jpgfile.close()

                    jpgfile = open(seen_covers[cover_key], "rb")


                    mime = guess_type(seen_covers[cover_key])[0]
                    _audiofile.tag.images.set(0x03,  jpgfile.read(), mime)
                    jpgfile.close()
                    _audiofile.tag.save(filename=_mp3_file,version=eyed3.id3.ID3_V2_4)
            current_track += 1
Exemple #6
0
def rank(args):
    args.foldername = expanduser(args.foldername)
    new_foldername = args.foldername
    # keep a list of all cues and flacs
    file_lists = get_music(new_foldername=new_foldername)
    band_ages = {}
    band_count = {}
    for files in file_lists['mp3'].keys():
        for file in file_lists['mp3'][files]:
            _created_time = stat(file).st_mtime
            _audiofile = load(file)
            _artist = _audiofile.tag.artist.strip().lower()
            # that one funky st vincent tag
            if _artist.find('st. vincent') == 0:
                _artist = 'st. vincent'
            if _artist in band_alternates.keys():
                _artist = band_alternates[_artist]
            if _artist not in band_ages.keys():
                band_ages[_artist] = _created_time
            elif _created_time < band_ages[_artist]:
                band_ages[_artist] = _created_time
            if _artist not in band_count.keys():
                band_count[_artist] = 1
            else:
                band_count[_artist] += 1

    ages_ranking_list = sorted(band_ages.items(), key=itemgetter(1))#.reverse()
    ages_ranking = {}
    ofh = open("rankings.csv", "w+")
    ofh.write("\nAges Ranking\n")
    ofh.write("Rank\tBand\n")
    rank = 1
    prev_val = ages_ranking_list[0][1]
    for i in range(len(ages_ranking_list)):
        print(abs(ages_ranking_list[i][1] - prev_val))
        if abs(ages_ranking_list[i][1] - prev_val) > 86400:
            rank += 1
            prev_val = ages_ranking_list[0][1]
        ofh.write(str(rank)+" "+ages_ranking_list[i][0].encode('utf8', 'replace').title()+"\n")
        ages_ranking[ages_ranking_list[i][0]] = rank

    count_ranking_list = sorted(band_count.items(), key=itemgetter(1))
    count_ranking_list.reverse()
    count_ranking = {}
    ofh.write("\nCount Ranking\n")
    ofh.write("Rank\tBand\tCount\n")
    rank = 1
    prev_val = count_ranking_list[0][1]
    for i in range(len(count_ranking_list)):
        if count_ranking_list[i][1] != prev_val:
            rank += 1
            prev_val = count_ranking_list[0][1]
        ofh.write(str(rank)+"\t"+count_ranking_list[i][0].encode('utf8', 'replace').title()+"\t"+str(count_ranking_list[i][1])+"\n")
        count_ranking[count_ranking_list[i][0]] = rank

    combined_rank = {}
    for key in band_ages.keys():
        combined_rank[key] = 0.5*ages_ranking[key] + count_ranking[key]
    combined_ranking_list = sorted(combined_rank.items(), key=itemgetter(1))
    ofh.write("\nCombined Ranking\n")
    ofh.write("Rank\tBand\tCombined Rank\n")
    for i in range(len(combined_ranking_list)):
        ofh.write(str(i)+" "+combined_ranking_list[i][0].encode('utf8', 'replace').title()+"\t"+str(combined_ranking_list[i][1])+"\n")

    ofh.close()