From a014d9b1b999679bab06403abfbeff311da47880 Mon Sep 17 00:00:00 2001 From: choj Date: Wed, 17 Jun 2020 16:00:53 +0200 Subject: [PATCH] v2 initial python script --- labelize.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 labelize.py diff --git a/labelize.py b/labelize.py new file mode 100644 index 0000000..7a10e04 --- /dev/null +++ b/labelize.py @@ -0,0 +1,80 @@ +import eyed3 +import os +import sys +import shutil +import yaml +from mako.template import Template + + +# TracksDir class definition +class Album: + def __init__(self, track_files): + self.trackFiles = track_files + + +# script usage function +def usage(): + print('USAGE : labelize.py [inputDirectory] [outputDirectory]') + + +# script beginning +arguments = len(sys.argv) - 1 +if arguments != 2: + usage() + sys.exit(2) + +input_directory = sys.argv[1] +output_directory = sys.argv[2] + + +def copy_directory(src, dest): + try: + shutil.copytree(src, dest) + except shutil.Error as e: + print('Directory not copied. Error: %s' % e) + except OSError as e: + print('Directory not copied. Error: %s' % e) + + +# removes existing build directory if exists +if os.path.isdir(output_directory): + shutil.rmtree(output_directory) +# +# copies source files in the build directory +copy_directory(input_directory, output_directory + '/audio') + +# copies assets in the build directory +copy_directory('assets', output_directory + '/assets') + + +with open('labelize.yaml') as f: + data = yaml.load(f, Loader=yaml.FullLoader) + title = data['band'] + cover_img = data['images']['cover'] + contact_img = data['images']['contact'] + +shutil.copyfile(input_directory + '/' + cover_img, output_directory + '/assets/images/cover.png'); +shutil.copyfile(input_directory + '/' + contact_img, output_directory + '/assets/images/contact.png'); + +track_files = [] +for root, dirs, files in os.walk(input_directory): + for f in sorted(files): + if f.lower().endswith(('.mp3', '.wav', '.ogg')): + track_files.append(f) + print(f) + + # td = TracksDir(trackFiles) + # f = open(output_directory + "/index.html", "w+") + # f.write(td.to_html()) + # f.close() +my_template = Template(filename='template.html') +f = open(output_directory + "/index.html", "w+") + +# Write template data to the file created +f.write(my_template.render( + title=title, + tracks=track_files, + albums_section=data['albums_section'])) + +# Close file +f.close()