Created
October 20, 2017 13:41
-
-
Save ViktorOgnev/6e1d0679445c607147b0c28f1647d309 to your computer and use it in GitHub Desktop.
Edit mp3 names via mutagen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
from mutagen import easyid3 | |
path = '/Users/name/Downloads/Book' | |
def compf(s: str) -> int: | |
num = next(re.finditer(r"\d+_\d+", s)).group() | |
track, disc = [int(i) for i in num.split('_')] | |
order = track + disc if disc == 46 else track + disc**2 | |
return order | |
def reorder_book(): | |
l = sorted(os.listdir(path), key=compf) | |
for i, name in enumerate(l): | |
dest = os.path.join(path, f'nudge_{i}.mp3') | |
src = os.path.join(path, name) | |
print(src, '->', dest) | |
os.rename(src, dest) | |
def edit_tags(): | |
for name in os.listdir(path): | |
mp3file = easyid3.EasyID3(os.path.join(path, name)) | |
mp3file['title'] = name | |
mp3file.save() | |
if __name__ == 'main': | |
reorder_book() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment