-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag_albs
executable file
·43 lines (35 loc) · 1.13 KB
/
tag_albs
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
#!/usr/bin/env python3
"""
Tag well-named albums (with the format %track%-%artist% - %title%)
"""
from subprocess import call
import re
import os
def info_from_fn(fn):
fn = fn.split('.')[0]
track, artist, title = fn.split('-')
artist = artist[:-1]
title = title[1:]
return track, artist, title
def tag(path):
# assert two digit number, and %%-%artist - %title.%ext
fn = path.split('/')[-1]
regexp = '^[0-9]{2}-.+ - .+\..+'
pattern = re.compile(regexp)
if not pattern.match(fn):
print(fn)
raise Exception("Filename {} does not match".format(fn))
tr, ar, ti = info_from_fn(fn)
call(["operon", "set", "artist", ar, path])
call(["operon", "set", "title", ti, path])
call(["operon", "set", "tracknumber", tr, path])
def list_files(root="./", suffixes=["flac", "opus", "mp3"]):
for root, dirs, files in os.walk(root):
for name in files:
newpth = os.path.join(root, name)
for suffix in suffixes:
if(newpth.endswith("." + suffix)):
yield newpth
if __name__ == '__main__':
for fn in list_files():
tag(fn)