-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate.music.files.py
67 lines (54 loc) · 2.18 KB
/
evaluate.music.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
60
61
62
63
64
65
66
67
import os
import sys
import logbook as logbook
from music import get_metadata_from_file
from track import Track
import lib.utils
def main():
path = lib.utils.get_path_from_config()
path = path.strip()
# streamlining down to a single file .... 5 was getting a little awkward
config_files = ['00_errors.txt']
for f in config_files:
lib.utils.remove_logfile(f)
for root, dirs, files in os.walk(path):
for file in files:
f = os.path.join(root, file)
_, filetype = os.path.splitext(f)
if filetype == '.flac' or filetype == '.mp3':
try:
track = get_metadata_from_file(f, filetype)
Track.extract_image(track)
except KeyError as e:
lib.utils.write_to_logfile('00_errors.txt', f'KEY ERROR: {e}', f'{f}')
else:
lib.utils.write_to_logfile('00_errors.txt', f'STRAY FILE:', f'{f}')
print(f'ttl_tracks_processed: {Track.ttl_files_processed}')
print(f'ttl_file_size: {Track.ttl_file_size:,}')
print(f'')
print(f'ttl_png_covers: {Track.ttl_png_covers}')
print(f'ttl_empty_covers: {Track.ttl_empty_covers}')
print(f'ttl_oversized_covers: {Track.ttl_oversized_covers}')
print(f'-- OVERSIZED --------------------------------')
Track.oversized_cover_list.sort()
print(f'{Track.oversized_cover_list}')
print(f'-- OVERSIZED --------------------------------')
print(f'\t{len(Track.oversized_cover_list)}')
print(f'-- EMPTY --------------------------------')
Track.empty_cover_list.sort()
print(f'{Track.empty_cover_list}')
print(f'-- EMPTY --------------------------------')
print(f'\t{len(Track.empty_cover_list)}')
print(f'----------------------------------')
def init_logging(filename: str = None):
level = logbook.TRACE
if filename:
logbook.TimedRotatingFileHandler(filename, level=level).push_application()
else:
logbook.StreamHandler(sys.stdout, level=level).push_application()
msg = 'Logging initialized.'
logger = logbook.Logger(f'Startup. Level: {level}')
logger.notice(msg)
if __name__ == '__main__':
init_logging()
main()