Created
July 5, 2012 12:52
-
-
Save jokull/3053520 to your computer and use it in GitHub Desktop.
Write id3v2 track from `01 - Whatever.mp3`
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 | |
# encoding=utf-8 | |
import sys | |
import os | |
import re | |
import subprocess | |
from clint.textui import prompt | |
from clint.textui.core import puts, puts_err | |
from clint.textui.colored import blue, yellow, red | |
filename_re = re.compile(r'^(\d+)(?:[\ |\.|-|_]+)(.+)\.mp3$') | |
def main(dir): | |
_tracks = dict() | |
_count = 0 | |
for filename in os.listdir(dir): | |
match = re.match(filename_re, filename) | |
if match is None: | |
continue | |
track, name = match.groups() | |
track = track.lstrip('0') | |
if track in _tracks: | |
if not prompt.yn(yellow("Track {} already tagged. \n Tag {} with duplicate track?".format(track, name))): | |
continue | |
status = subprocess.Popen(['mid3v2', '-T', track, os.path.join(dir, filename)]).wait() | |
if status != 0: | |
puts_err(red("✕ {}".format(name))) | |
else: | |
_tracks[track] = name | |
_count += 1 | |
puts("✓ {} to {}".format(track, name)) | |
puts("") | |
puts(blue("Tagged {} files".format(_count))) | |
puts("") | |
if __name__ == '__main__': | |
args = (".") | |
if len(sys.argv) > 1: | |
args = sys.argv[1:] | |
try: | |
main(*args) | |
except KeyboardInterrupt: | |
sys.exit("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment