Created
December 11, 2014 10:00
-
-
Save amitkot/cd00c9847ea655bb73cc to your computer and use it in GitHub Desktop.
A Script for changing ID3 title to filename
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
#!/usr/bin/env python | |
""" A Script for changing ID3 title to filename | |
This script was used to prepare a directory containing many files in sub | |
directories, for import using beets (https://github.com/sampsyo/beets). | |
""" | |
import fnmatch | |
import os | |
import re | |
from mutagen.id3 import ID3, TIT2 | |
def change_title(name): | |
f = ID3(name) | |
new_title = re.sub(r'^.*/(\d.*)$', r'\1', f.filename) | |
f.add(TIT2(encoding=3, text=new_title.decode('utf-8'))) | |
f.save() | |
print('-> {}'.format(new_title)) | |
matches = [] | |
for root, dirnames, filenames in os.walk('.'): | |
for filename in fnmatch.filter(filenames, '*.mp3'): | |
matches.append(os.path.join(root, filename)) | |
for name in matches: | |
change_title(name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment