Ejemplo n.º 1
0
def initiateFLAC(filename, directory, thumbnails, options):
    audio = FLAC(str(directory) + "/" + str(filename))
    # verify artist information is present before preceeding
    if ' - ' not in filename and str(audio['artist'][0]) == '':
        messagebox.showinfo("No artist information found, aborting procedure")
        return False, False, False

    # transcribe formal tagnames into informal counterpart
    formalTagDict = {
        'artist': 'Artist',
        'album': 'Album',
        'albumartist': 'Album_Artist',
        'bpm': 'BPM',
        'comment': 'Comment',
        'compilation': 'Compilation',
        'copyright': 'Copyright',
        'discnumber': 'Discnumber',
        'genre': 'Genre',
        'initialkey': 'Key',
        'date': 'Release_Date',
        'title': 'Title',
        'replaygain_track_gain': 'ReplayGain',
    }
    # transcribe informal tagnames into formal counterpart
    informalTagDict = {v: k for k, v in formalTagDict.items()}
    fileParameters = []
    for tag in audio:
        # delete extraneous tags if the tag is not in the list of selected tags and the delete unselected tags option is activated
        if (tag not in formalTagDict
                or formalTagDict[tag] not in options["Selected Tags (L)"]
            ) and options["Delete Unselected Tags (B)"].get() == True:
            audio[tag] = ""
            audio.pop(tag)
            audio.save()
        else:
            fileParameters.append(tag)
    for tag in options["Selected Tags (L)"]:
        if tag in informalTagDict:
            tag = informalTagDict[tag]
            # add tags of interest if missing
            if tag not in fileParameters:
                try:
                    audio[tag] = ""
                    audio.save()
                except:
                    messagebox.showinfo(
                        "Permission Error",
                        "Unable to save tags, file may be open somewhere")
                    return False, False, False

    # check for discrepancies between tags and filename
    # check both artist and title tags
    if ' - ' in filename:
        artist = filename.split(' - ')[0]
        title = filename[filename.index(filename.split(' - ')[1]):filename.
                         rfind('.')]
        if artist != str(audio['artist'][0]) or title != str(
                audio['title'][0]):
            # save artist and title to tag if both are empty
            if str(audio['artist'][0]) == '' and str(audio['title'][0]) == '':
                audio['artist'] = artist
                audio['title'] = title
                audio.save()
            else:
                audio, filename = compareArtistAndTitle(
                    audio, artist, title, filename, directory, options)
    # only check title tag
    else:
        title = filename[:filename.rfind('.')]
        if title != str(audio['title'][0]):
            # save title to tag if tag is empty
            if str(audio['title'][0]) == '':
                audio['title'] = title
                audio.save()
            else:
                audio, filename = compareTitle(audio, title, filename,
                                               directory, options)

    # handle naming format and typo check
    namingConvention = options['Audio naming format (S)'].get()
    artist = str(audio['artist'][0])
    audio, filename = handleStaticNamingConvention(audio, filename, artist,
                                                   title, directory,
                                                   namingConvention)
    if options["Scan Filename and Tags (B)"].get(
    ) == True and type(audio) != bool:
        audio, filename, options = extractArtistAndTitle(
            audio, filename, directory, options, namingConvention)
    if type(audio) != bool:
        # save thumbnail to list
        images = audio.pictures
        # append thumbnail image to list if artwork exists
        if len(images) > 0:
            stream = BytesIO(images[0].data)
            image = Image.open(stream).convert("RGBA")
            thumbnails = saveThumbnail(image, thumbnails)
            stream.close()
        else:
            thumbnails = saveThumbnail("NA", thumbnails)
    return audio, filename, informalTagDict, thumbnails, options
Ejemplo n.º 2
0
from mutagen.flac import FLAC
orig_audio = FLAC("Tartaglia.flac")
orig_audio.pop("synopsis")
orig_audio.pop("purl")
orig_audio.pop("description")
orig_audio.pop("encoder")
orig_audio["artist"] = "Yu-Peng Chen"
orig_audio["title"] = "Tartaglia"
print(orig_audio)

orig_audio.save("Tartaglia.flac")