Exemple #1
0
def compareTitle(audio, title, filename, directory, options):
    # compare file title and tag title
    fileTitleList = title.split(' ')
    tagTitleList = str(audio["TIT2"]).split(' ')
    if len(fileTitleList) == len(tagTitleList):
        for i in range(len(fileTitleList)):
            if fileTitleList[i] != tagTitleList[i]:
                if fileTitleList[i].lower() == tagTitleList[i].lower() and (fileTitleList[i].capitalize() in options["Always Capitalize (L)"] or fileTitleList[i].lower() in options["Never Capitalize (L)"]):
                    if fileTitleList[i].capitalize() in options["Always Capitalize (L)"]:
                        # capitalize both name and file tag
                        fileTitleList[i] = fileTitleList[i].capitalize()
                        title = " ".join(fileTitleList)
                        audio, filename = rename(directory, filename, str(audio["TPE1"]), title, filename[filename.rfind("."):], "Title")
                    elif fileTitleList[i].lower() in options["Never Capitalize (L)"]:
                        # lower both name and file tag
                        fileTitleList[i] = fileTitleList[i].lower()
                        title = " ".join(fileTitleList)
                        audio, filename = rename(directory, filename, str(audio["TPE1"]), title, filename[filename.rfind("."):], "Title")
                else:
                    input = handleTitleDiscrepancy(title, str(audio["TIT2"]))
                    if input == "file":
                        audio['TIT2'] = TIT2(encoding=3, text=title)
                        audio.save()
                    elif input == "tag":
                        extension = filename[filename.rfind('.'):]
                        audio, filename = rename(directory, filename, str(audio["TPE1"]), str(audio["TIT2"]), extension, "Title")
    else:
        input = handleTitleDiscrepancy(title, str(audio["title"][0]))
        if input == "file":
            audio["TIT2"] = TIT2(encoding=3, text=title)
            audio.save()
        elif input == "tag":
            extension = filename[filename.rfind('.'):]
            audio, filename = rename(directory, filename, str(audio["TPE1"]), str(audio["TIT2"]), extension, "Title")
    return audio, filename
Exemple #2
0
def compareArtistAndTitle(audio, artist, title, filename, directory, options):
    fileArtistList = artist.split(' ')
    tagArtistList = str(audio["artist"][0]).split(' ')
    if len(fileArtistList) == len(tagArtistList):
        for i in range(len(fileArtistList)):
            if fileArtistList[i] != tagArtistList[i]:
                if fileArtistList[i].lower() == tagArtistList[i].lower() and (
                        fileArtistList[i].capitalize()
                        in options["Always Capitalize (L)"]
                        or fileArtistList[i].lower()
                        in options["Never Capitalize (L)"]):
                    if fileArtistList[i].capitalize(
                    ) in options["Always Capitalize (L)"]:
                        # capitalize both name and file tag
                        fileArtistList[i] = fileArtistList[i].capitalize()
                        artist = " ".join(fileArtistList)
                        audio, filename = rename(
                            directory, filename, artist, title,
                            filename[filename.rfind("."):], "Artist - Title")
                    elif fileArtistList[i].lower(
                    ) in options["Never Capitalize (L)"]:
                        # lower both name and file tag
                        fileArtistList[i] = fileArtistList[i].lower()
                        artist = " ".join(fileArtistList)
                        audio, filename = rename(
                            directory, filename, artist, title,
                            filename[filename.rfind("."):], "Artist - Title")
                else:
                    input = handleArtistTitleDiscrepancy(
                        artist, str(audio["artist"][0]), title,
                        str(audio["title"][0]))
                    if input == "file":
                        audio['artist'] = artist
                        audio['title'] = title
                        audio.save()
                    elif input == "tag":
                        extension = filename[filename.rfind('.'):]
                        audio, filename = rename(directory, filename,
                                                 str(audio["artist"][0]),
                                                 str(audio["title"][0]),
                                                 extension, "Artist - Title")
                    break
    else:
        input = handleArtistTitleDiscrepancy(artist, str(audio["artist"][0]),
                                             title, str(audio["title"][0]))
        if input == "file":
            audio['artist'] = artist
            audio['title'] = title
            audio.save()
        elif input == "tag":
            extension = filename[filename.rfind('.'):]
            audio, filename = rename(directory, filename,
                                     str(audio["artist"][0]),
                                     str(audio["title"][0]), extension,
                                     "Artist - Title")
    # compare file title with tag title
    fileTitleList = title.split(' ')
    tagTitleList = str(audio["title"][0]).split(' ')
    if len(fileTitleList) == len(tagTitleList):
        for i in range(len(fileTitleList)):
            if fileTitleList[i] != tagTitleList[i]:
                if fileTitleList[i].lower() == tagTitleList[i].lower() and (
                        fileTitleList[i].capitalize()
                        in options["Always Capitalize (L)"]
                        or fileTitleList[i].lower()
                        in options["Never Capitalize (L)"]):
                    if fileTitleList[i].capitalize(
                    ) in options["Always Capitalize (L)"]:
                        # capitalize both name and file tag
                        fileTitleList[i] = fileTitleList[i].capitalize()
                        title = " ".join(fileTitleList)
                        audio, filename = rename(
                            directory, filename, artist, title,
                            filename[filename.rfind("."):], "Artist - Title")
                    elif fileTitleList[i].lower(
                    ) in options["Never Capitalize (L)"]:
                        # lower both name and file tag
                        fileTitleList[i] = fileTitleList[i].lower()
                        title = " ".join(fileTitleList)
                        audio, filename = rename(
                            directory, filename, artist, title,
                            filename[filename.rfind("."):], "Artist - Title")
                else:
                    input = handleArtistTitleDiscrepancy(
                        artist, str(audio["artist"][0]), title,
                        str(audio["title"][0]))
                    if input == "file":
                        audio['artist'] = artist
                        audio['title'] = title
                        audio.save()
                    elif input == "tag":
                        extension = filename[filename.rfind('.'):]
                        audio, filename = rename(directory, filename,
                                                 str(audio["artist"][0]),
                                                 str(audio["title"][0]),
                                                 extension, "Artist - Title")
                    break
    else:
        input = handleArtistTitleDiscrepancy(artist, str(audio["artist"][0]),
                                             title, str(audio["title"][0]))
        if input == "file":
            audio['artist'] = artist
            audio['title'] = title
            audio.save()
        elif input == "tag":
            extension = filename[filename.rfind('.'):]
            audio, filename = rename(directory, filename,
                                     str(audio["artist"][0]),
                                     str(audio["title"][0]), extension,
                                     "Artist - Title")
    return audio, filename