-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopytags.py
executable file
·64 lines (47 loc) · 1.3 KB
/
copytags.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from mutagen.id3 import ID3
from os.path import getsize, walk, isfile
import pprint
global ppr
ppr = None
def pp(what):
global ppr
if ppr is None: ppr = pprint.PrettyPrinter(indent=2)
ppr.pprint(what)
#_from = 'Kid A (2000)/02 - Kid A.mp3'
#_to = 'v3/Kid A (2000)/02 - Kid A.mp3'
bash = """#!/bin/bash
path=$@
quality=v3
dir=$(dirname "$path")
file=$(basename "$path")
mkdir -p "$quality/$dir"
if [ ! -f "$quality/$path" ]; then
echo converting $file
in=$( cygpath -w "$path")
out=$( cygpath -w "$quality/$path")
lame -S --mp3input -V3 "$in" "$out"
else
echo SKIP $path
fi
"""
# the above script transcodes everything in the current folder
# to a fubfolder named '$quality'
# run like so:
# find -type f -name \*3 \! -path './v3/*' -exec ./transcode.sh {} \;
if not isfile('transcode.sh'):
with open('transcode.sh','wb') as bs:
bs.write(bash)
def visit(arg, dirname, fnames):
if dirname.startswith(arg): return
print 'dir<%s>' % dirname
for fn in fnames:
if not fn.endswith('mp3'): return
frm = '%s\\%s' %( dirname, fn)
to = '%s\\%s' %( arg, frm)
copy_tag(frm, to)
def copy_tag(original=None, destination=None):
orig = ID3(original)
copy = ID3()
copy.update(orig)
copy.save(destination)
#walk('.', visit, '.\\v3')