Editing Audio Tags editor script
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 24: | Line 24: | ||
song_attrs = [] # Dictionaries containing attributes to be inspected | song_attrs = [] # Dictionaries containing attributes to be inspected | ||
− | |||
− | |||
# Make sure mutagen uses the easy version, as | # Make sure mutagen uses the easy version, as | ||
# it uses the normal one by default | # it uses the normal one by default | ||
− | + | if os.path.splitext(sys.argv[1])[1] == ".mp3": | |
− | |||
import mutagen.easyid3 | import mutagen.easyid3 | ||
mut_init = mutagen.easyid3.EasyID3 | mut_init = mutagen.easyid3.EasyID3 | ||
− | |||
− | |||
− | |||
else: | else: | ||
mut_init = mutagen.File | mut_init = mutagen.File | ||
Line 43: | Line 37: | ||
for attr in attrs: | for attr in attrs: | ||
song_attrs[-1][attr] = songs[-1].get(attr, [''])[0] | song_attrs[-1][attr] = songs[-1].get(attr, [''])[0] | ||
− | if not song_attrs[-1][attr]: | + | if attr == 'artist' and not song_attrs[-1][attr]: |
− | + | del song_attrs[-1][attr] | |
− | + | _attr = 'albumartist' | |
− | + | song_attrs[-1][attr] = songs[-1].get(_attr, [''])[0] | |
− | + | if attr == 'title' and not song_attrs[-1][attr]: | |
− | + | del song_attrs[-1][attr] | |
− | + | song_attrs[-1][attr] = os.path.splitext(f)[0] | |
− | + | ||
with tempfile.NamedTemporaryFile('w+', suffix='.csv') as tmpf: | with tempfile.NamedTemporaryFile('w+', suffix='.csv') as tmpf: | ||
− | csvwriter = csv.writer(tmpf, quoting=csv.QUOTE_NONE, escapechar=escape | + | csvwriter = csv.writer(tmpf, quoting=csv.QUOTE_NONE, escapechar=escape) |
− | |||
csvwriter.writerows([row.values() for row in song_attrs]) | csvwriter.writerows([row.values() for row in song_attrs]) | ||
# Ensure that the file has been written to disk | # Ensure that the file has been written to disk | ||
Line 60: | Line 53: | ||
os.system("{} {}".format(editor, tmpf.name)) | os.system("{} {}".format(editor, tmpf.name)) | ||
tmpf.seek(0) | tmpf.seek(0) | ||
− | csvreader = csv.reader(tmpf, quoting=csv.QUOTE_NONE, | + | csvreader = csv.reader(tmpf, quoting=csv.QUOTE_NONE, escapechar=escape) |
− | |||
for song,row in zip(songs, csvreader): | for song,row in zip(songs, csvreader): | ||
new_song_metadata = dict(zip(attrs, row)) | new_song_metadata = dict(zip(attrs, row)) |