def setSortTags(path): ext = os.path.splitext(path)[1].lower() meta = None try: if ext == '.mp3': meta = MP3(path) elif ext == '.m4a': meta = MP4(path) elif ext == '.flac': meta = FLAC(path) else: return except: logging.warning('unknown file type:{0}'.format(path)) pass if meta: tagsToProcess = ('ALBUM', 'ALBUMARTIST', 'ARTIST', 'TITLE') save = False try: for tag in tagsToProcess: processed = checkTagMakeSort(path, meta, tag) if (processed): save = True if save: meta.save() except Exception as e: logging.warning('Save tag for {0} failure'.format(path)) logging.exception(e) pass
def setSortTags(path): ext = os.path.splitext(path)[1].lower() meta = None try: if ext == '.mp3': meta = MP3(path) elif ext == '.m4a': meta = MP4(path) elif ext == '.flac': meta = FLAC(path) else: return except: pass if meta: tagsToProcess = ('ALBUM', 'ALBUMARTIST', 'ARTIST', 'TITLE') save = False try: for tag in tagsToProcess: processed = checkTagMakeSort(path, meta, tag) if (processed): save = True if save: meta.save() except: pass
def __init__(self, path): try: self.tags = MP4(path) except MP4StreamInfoError: self.artist = None self.title = None self.shorten_lyrics = None self.message = f"Not a mp4 file: {path}" return self.artist = self.tags.get("\xa9ART", [None])[0] self.title = self.tags.get("\xa9nam", [None])[0] self.genre = self.tags.get("\xa9gen", [None])[0] if not self.artist or not self.title: self.shorten_lyrics = None self.message = f"Incomplete track: {path}" return if "\xa9lyr" in self.tags: lyrics = self.tags['\xa9lyr'][0][:20] self.shorten_lyrics = lyrics.replace('\n', ' ') self.message = f"Lyrics are already embeded: {self.shorten_lyrics}" else: # default value self.shorten_lyrics = None self.message = "Lyrics not found."
def getTag(file, tag1, tag2, tag3): tag = '' if ".flac" in file: flacFile = FLAC(file) # tag - common one tag = flacFile[tag1][0] if ".mp3" in file: mp3File = MP3(file) # tag - common one tag = mp3File[tag1][0] if ".m4a" in file: m4aFile = MP4(file) # tag - common one tag = m4aFile[tag1][0] if ".ape" in file: apeFile = APEv2(file) # tag - starts with a capital tag = apeFile[tag2][0] if ".ogg" in file: oggFile = OggVorbis(file) # tag - CAPS tag = oggFile.tags[tag3][0] return tag
def process_engine(PATH): child_folders = os.listdir(PATH) # Nest into each folder looking for mp4 files for folder_name in child_folders: # Nest into grandchildren for mp4 files and rename that grandchildren = os.listdir(PATH + folder_name) for grandchild in grandchildren: # Check that we are aren't processing files more than once try: if (process_name(grandchild) != grandchild): # Setup work grandchild_path = PATH + folder_name + '\\' #get grandchild path file_extension = os.path.splitext(grandchild)[1] # Remove trash files if file_extension == ".txt": os.remove(grandchild_path + grandchild + ".txt") if file_extension == ".exe": os.remove(grandchild_path + grandchild + ".exe") # If file_extension is an mp4 if file_extension == ".mp4": os.rename( grandchild_path + grandchild, grandchild_path + process_name(grandchild) + file_extension) print("Renaming {grandchild} now".format( grandchild=grandchild)) # Erase all metadata curr_video = MP4(grandchild_path + process_name(grandchild) + file_extension) for metadata in curr_video.tags: curr_video.tags[metadata] = "" curr_video.save() # Handle mkv case, mkvs do not need a metadata change # Might hit edge case late elif file_extension == ".mkv": os.rename( grandchild_path + grandchild, grandchild_path + process_name(grandchild) + file_extension) # Handle Avi case, no f*****g clue if this needs a metadata change elif file_extension == '.avi': os.rename( grandchild_path + grandchild, grandchild_path + process_name(grandchild) + file_extension) except: continue # Open log file log_file = open("log.txt", "a") if (process_name(folder_name) != folder_name): try: os.rename(PATH + folder_name, PATH + process_name(folder_name)) print("Rename success: {folder}".format(folder=folder_name)) shutil.move(PATH + process_name(folder_name), PLEX_PATH) # Get time current_time = datetime.now() log_file.write( "Succesfully completed {folder} at {current_time} \n". format(folder=folder_name, current_time=current_time)) print("Move success: {folder}".format(folder=folder_name)) except: print("Move unsuccesfull") continue
def _generate_metadata_records_from_m4a(path): d = dict(MP4(path).tags, **{"PATH_SRC": [path], "PATH_DST": [path]}) return d
def create_lyrics_in_mp4(path, lyrics, force=False): tags = MP4(path) if '\xa9lyr' in tags and not force: return tags['\xa9lyr'] = lyrics tags.save()