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()