def peek(songlist): artlist = [] # artist alblist = [] # album artist = album = "" for song in songlist: extension = os.path.splitext(song)[1].lower() if extension == ".flac": raw = flac(song) else: raw = eid3(song) try: album = raw.get('album')[0] album = parseName(album) except: album = "Unknown Value" if 'artist' in raw: artist = raw.get('artist')[0] elif 'performer' in raw: artist = raw.get('performer')[0] elif 'composer' in raw: artist = raw.get('composer')[0] try: artist = parseName(artist) except: artist = "Unknown Value" artlist.append(artist) alblist.append(album) if not checkEqual(artlist): artist = "VA" if not checkEqual(alblist): album = "Unknown Album" return artist, album
cmd = "audioconvert convert " + '"' + dir + '"' + " " + '"' + dir + '"' + " --output-format .mp3" print(cmd) os.system(cmd) #eventually need to change to all python for root, dirs, files in os.walk(".", topdown=False): for file in files: if file.endswith(".m4a"): # read metadata of m4a file newfile = os.path.join(root, file) print("Copying metadata for " + newfile) tagM4A = tt.get(os.path.join(root, file)) # copy metadata between m4a and mp3 tempName = newfile.removesuffix('.m4a') mp3file = tempName + '.mp3' tagMP3 = eid3(mp3file) # print eid3.valid_keys.keys() # key tags to copy tagMP3['title'] = tagM4A.title tagMP3['album'] = tagM4A.album #tagMP3['discnumber'] = tagM4A.disc #doesn't work for some reason. might have to do with NULL exception tagMP3['artist'] = tagM4A.artist tagMP3['albumartist'] = tagM4A.albumartist tagMP3['date'] = tagM4A.year tagMP3['genre'] = tagM4A.genre tagMP3['tracknumber'] = tagM4A.track tagMP3.save() print("done.")
def process(songlist): # mutagen returns a list of values instead of a raw string; be careful with it try: artist, album = peek(songlist) except: return if album == "Unknown Album": printToLog(False, "Different albums within the same folder") return for song in songlist: extension = os.path.splitext(song)[1].lower() if extension == ".flac": raw = flac(song) else: raw = eid3(song) # filename refactor try: track = raw.get('track')[0] title = raw.get('title')[0] if track < 10: track = "0" + track filename = track + " " + title + extension #TODO check if this ALWAYS triggers or something except: filename = os.path.basename(song) try: year = raw.get('date')[0] year = parseDate(year) except: year = "(Unknown Year)" # TODO regex filename # TODO fetch from discogs if artist == album == "Unknown Value" and year == "(Unknown Year)": printToLog(False, "Not enough information") return # create new destination directory # hierarchy : '/artist/(year) album/' ex: /Wisp/(2005) NRTHNDR/ artist_folder = os.path.join(dest_dir, artist) album_folder = os.path.join(artist_folder, year + " " + album) try: os.mkdir(artist_folder) except FileExistsError: pass try: os.mkdir(album_folder) except FileExistsError: pass try: dest = os.path.join(dest_dir, os.path.join(album_folder, filename)) move(song, dest) except FileExistsError: filename += ".bck" dest = os.path.join(dest_dir, os.path.join(album_folder, filename)) printToLog(False, "File already exists, moving as ", dest)