from musicutil.utils.load_tag_information import load_tag_information from musicutil.utils.scan_for_music import scan_for_music from html import escape as escape_html class GenHTMLArgs(): src: str dest: str title: str description: str def add_genhtml_command(subparsers): genhtml_parser = subparsers.add_parser('genhtml') genhtml_parser.add_argument( 'src', type=str, help='src base music directory') genhtml_parser.add_argument( 'dest', type=str, help='dest html file') genhtml_parser.add_argument( 'title', type=str, help='title') genhtml_parser.add_argument( 'description', type=str, help='description') def get_genhtml_args(args) -> GenHTMLArgs: command_args = GenHTMLArgs() command_args.src = args.src command_args.dest = args.dest command_args.title = args.title command_args.description = args.description return command_args class GenHTMLCommand(): def __init__(self, args: GenHTMLArgs): self.args = args def run(self): print("Generating HTML...") print("Scanning For Music...") files = scan_for_music(self.args.src) print("Loading Tag Information") for file in files: tags = load_tag_information(file) file.tags = tags files.sort(key=lambda file: file.tags.artist) files.sort(key=lambda file: file.tags.title) files.sort(key=lambda file: file.path_from_src) html_content = "" html_content += f""" {self.args.title} """ html_content += """ """ isOdd = True for file in files: tdClass = "pure-table-odd" if isOdd else "pure-table-even" data_path = escape_html(file.path_from_src) data_title = escape_html(file.tags.title) data_artist = escape_html(file.tags.artist) data_extension = escape_html(file.extension) html_content += f""" """ isOdd = not isOdd html_content += """
Path Title Artist Format
{data_path} {data_title} {data_artist} {data_extension}
""" print("Writing HTML...") with open(self.args.dest, "w+") as html_file: html_file.write(html_content)