-
Notifications
You must be signed in to change notification settings - Fork 0
/
files.py
59 lines (42 loc) · 1.37 KB
/
files.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
import re
from os import listdir
from os.path import isfile, join
import tags
from api import get_album
def files(basepath):
return [f for f in listdir(basepath) if isfile(join(basepath, f))]
def print_tags(basepath):
for file in files(basepath):
filepath = basepath + file
try:
tags.print_tags(filepath)
except AttributeError:
pass
def tags_from_filename(basepath):
title_regex = "-_(.+)\\."
artist_regex = "^(.+)_-_"
renamed = 0
skipped = 0
for file in files(basepath):
filepath = basepath + file
title_re = re.findall(title_regex, file)
artist_re = re.findall(artist_regex, file)
if len(title_re) == 0 or len(artist_re) == 0:
skipped += 1
continue
title = title_re[0].replace('_', ' ')
artist = artist_re[0].replace('_', ' ')
try:
tags.set_tags(filepath, title=title, artist=artist)
renamed += 1
except BaseException:
skipped += 1
print('renamed', renamed, 'skipped', skipped)
def fill_album_from_tags(basepath):
for file in files(basepath):
filepath = basepath + file
artist, title = tags.get_tags(filepath)
album = get_album(artist, title)
if album:
print(artist, title, album)
tags.set_tags(filepath, album=album)