Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
def main():
    args = parser.parse_args()
    new_foldername = copy_dir(args.foldername)
    for root, dirs, files in os.walk(new_foldername):
        # keep a list of all cues and flacs
        flac_filenames = []
        cue_filenames = []
        thumbnail_filename = None
        for name in files:
            if fnmatch(name, "*.flac") or fnmatch(name, ".m4a") or fnmatch(
                    name, '.wma'):
                flac_filenames.append(os.path.join(root, name))
            if fnmatch(name, "*.cue"):
                cue_filenames.append(os.path.join(root, name))
            if fnmatch(name, "*.jpg"):
                thumbnail_filename = os.path.join(root, name)
        # we should now have exactly one flac and one cue file
        if len(flac_filenames) == 1 and len(cue_filenames) == 1:

            ps = subprocess.Popen(('cuebreakpoints', cue_filenames[0]),
                                  stdout=subprocess.PIPE)
            subprocess.check_output(('shnsplit', '-o', 'flac', flac_filenames[0], '-a',
                                     flac_filenames[0].replace(root,'').replace('.flac', ''), '-d', root),
                                    stdin=ps.stdout)
            ps.wait()
            # move the old flac file to the trash
            send2trash(flac_filenames[0])

        if len(cue_filenames)>0:
            cuesheet = CueSheet()
            cuesheet.setOutputFormat('%performer% - %title%\n%file%\n%tracks%', '%title%')
            with open(cue_filenames[0], "r") as f:
                cuesheet.setData(f.read())
            cuesheet.parse()
        else:
            cuesheet = None
        print root
        # convert the other flacs to mp3
        convert_files(root, cuesheet=cuesheet, thumbnail_filename=thumbnail_filename)
Ejemplo n.º 3
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