# HG changeset patch # User Brian Neal # Date 1640655353 21600 # Node ID 83dd2db291f77f09906d93843d1a690604b3dc80 # Parent cb712b2c34afd593489b083f48ef227d1d3ce8b2 Added tool to tag MP3 comp files. diff -r cb712b2c34af -r 83dd2db291f7 tools/sg101mp3comptool.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/sg101mp3comptool.py Mon Dec 27 19:35:53 2021 -0600 @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# Copyright (C) 2021 by Brian Neal. + +"""This file contains the main routine for the SG101 MP3 Comp Tool.""" + +import argparse +import eyed3 +import json +import os.path +import re + + +DESC = """SG101 MP3 Comp Tool""" +TITLE_RE = re.compile(r'^(\d+)\s+-\s+(.+)"(.+)"$') + +def process_mp3(mp3, args): + title = mp3['fields']['title'] + m = TITLE_RE.match(title) + track_num = int(m[1]) + artist = m[2].strip() + title = m[3] + filename = mp3['fields']['file'].split('/')[-1] + filepath = os.path.join(args.mp3_dir, filename) + + mp3file = eyed3.load(filepath) + mp3file.tag.clear() + mp3file.tag.title = title + mp3file.tag.artist = artist + mp3file.tag.album = args.album + mp3file.tag.recording_date = args.recording_date + mp3file.tag.track_num = track_num + mp3file.tag.genre = 'Instrumental Rock' + mp3file.tag.save() + + +def main(argv=None): + parser = argparse.ArgumentParser(description=DESC) + parser.add_argument('json', metavar='JSON', + help='JSON file to control the tagging process') + parser.add_argument('-d', '--mp3-dir', default='.', + help='directory to find MP3 files') + parser.add_argument('-a', '--album', + default='SurfGuitar101.com 2021 MP3 Compilation', + help='album name tag value') + parser.add_argument('-r', '--recording-date', default='2021', + help='recording date tag value') + + args = parser.parse_args(args=argv) + + with open(args.json, 'r') as fp: + mp3data = json.load(fp) + + for mp3 in mp3data: + process_mp3(mp3, args) + +if __name__ == '__main__': + main()