forked from cromize/beatport_tracktagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracktagger.py
executable file
·104 lines (85 loc) · 3.25 KB
/
tracktagger.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
import argparse
import urllib3
import core
import sys
from os.path import isfile
from track import Track
from lxml import html
# TODO: add check for validity of tags in files
# TODO: print tracks that errored at the end
# TODO: make musical key retrieval work
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def argsParserInit():
parser = argparse.ArgumentParser(description="tag audio files with Beatport ID easily.")
parser.add_argument('-s', '--sync', action='store_true', help='get info from Beatport')
parser.add_argument('-t', '--tag-files', action='store_true', help='update tags in audio files')
parser.add_argument('-c', '--clean-tags', action='store_true', help='clean tags in audio files')
parser.add_argument('-v', '--verbose', action='store_true', help='verbose output')
parser.add_argument('-a', '--artwork', action='store_true', help='update track artwork')
parser.add_argument('-r', '--recursive', action='store_true', help='run recursive')
parser.add_argument('-z', '--fuzzy', action='store_true', help='try to fuzzy match')
parser.add_argument('-i', '--input', help='specify input', default='')
parser.add_argument('-f', '--force', action='store_true', help='force tag overwrite')
parser.add_argument('--save-db', help='save tags to database', default='local.db')
parser.add_argument('--load-db', help='load tags from database', default='local.db')
return parser
if __name__ == "__main__":
print('*** welcome beatport_tagger ***')
# main db
db = core.Database()
# input parser
input_parser = argsParserInit()
args = input_parser.parse_args()
# args check
if len(sys.argv) <= 1:
input_parser.print_help()
sys.exit(0)
# load existing db
if isfile(args.load_db):
print('\n** database found! loading data')
db.loadJSON(args.load_db)
print(f'** number of tracks in db: {len(db.db)}' )
# scan for flac and mp3 files
work_files = core.scanFiletype(args.input, args.recursive)
# clean file tags
if args.clean_tags:
print("\n** cleaning tags")
for idx, f in enumerate(work_files):
print(f'{idx+1}/{len(work_files)} - {f}')
Track.cleanTags(f)
sys.exit(0)
# query beatport id using fuzzy name matching
if args.fuzzy:
print("\n** getting Beatport ID using fuzzy matching")
db.track_count = len(work_files)
core.spawnWorkers(core.doFuzzyMatch, work_files, db)
db.saveJSON(args.save_db)
elif args.sync:
# get tags from beatport
work_files = db.scanBeatportID(work_files)
print('\n** getting tags from beatport')
core.spawnWorkers(core.addTrackToDB, work_files, db)
db.saveJSON(args.save_db)
# assign available paths
work_files = db.assignPath(work_files)
# tag audio files
if args.tag_files:
print('\n** updating audio tags')
i = 0
for k, v in db.db.items():
# for scanned files only
if "file_path" in v.__dict__:
print(f'{i+1}/{db.track_count} - {v.file_name}')
v.fileTagsUpdate(args.force)
i += 1
# save artwork
if args.artwork:
print("\n** saving artwork")
i = 0
for k, v in db.db.items():
if "file_path" in v.__dict__:
print(f'{i+1}/{db.track_count} - {v.file_name}')
v.saveArtwork()
i += 1
print('\n** all done')