Mercurial > public > sg101
comparison tools/sg101mp3comptool.py @ 1189:83dd2db291f7
Added tool to tag MP3 comp files.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 27 Dec 2021 19:35:53 -0600 |
parents | |
children | ce5a5c9cd9d8 |
comparison
equal
deleted
inserted
replaced
1188:cb712b2c34af | 1189:83dd2db291f7 |
---|---|
1 #!/usr/bin/env python | |
2 # Copyright (C) 2021 by Brian Neal. | |
3 | |
4 """This file contains the main routine for the SG101 MP3 Comp Tool.""" | |
5 | |
6 import argparse | |
7 import eyed3 | |
8 import json | |
9 import os.path | |
10 import re | |
11 | |
12 | |
13 DESC = """SG101 MP3 Comp Tool""" | |
14 TITLE_RE = re.compile(r'^(\d+)\s+-\s+(.+)"(.+)"$') | |
15 | |
16 def process_mp3(mp3, args): | |
17 title = mp3['fields']['title'] | |
18 m = TITLE_RE.match(title) | |
19 track_num = int(m[1]) | |
20 artist = m[2].strip() | |
21 title = m[3] | |
22 filename = mp3['fields']['file'].split('/')[-1] | |
23 filepath = os.path.join(args.mp3_dir, filename) | |
24 | |
25 mp3file = eyed3.load(filepath) | |
26 mp3file.tag.clear() | |
27 mp3file.tag.title = title | |
28 mp3file.tag.artist = artist | |
29 mp3file.tag.album = args.album | |
30 mp3file.tag.recording_date = args.recording_date | |
31 mp3file.tag.track_num = track_num | |
32 mp3file.tag.genre = 'Instrumental Rock' | |
33 mp3file.tag.save() | |
34 | |
35 | |
36 def main(argv=None): | |
37 parser = argparse.ArgumentParser(description=DESC) | |
38 parser.add_argument('json', metavar='JSON', | |
39 help='JSON file to control the tagging process') | |
40 parser.add_argument('-d', '--mp3-dir', default='.', | |
41 help='directory to find MP3 files') | |
42 parser.add_argument('-a', '--album', | |
43 default='SurfGuitar101.com 2021 MP3 Compilation', | |
44 help='album name tag value') | |
45 parser.add_argument('-r', '--recording-date', default='2021', | |
46 help='recording date tag value') | |
47 | |
48 args = parser.parse_args(args=argv) | |
49 | |
50 with open(args.json, 'r') as fp: | |
51 mp3data = json.load(fp) | |
52 | |
53 for mp3 in mp3data: | |
54 process_mp3(mp3, args) | |
55 | |
56 if __name__ == '__main__': | |
57 main() |