#!/usr/bin/env python3
import argparse, os, subprocess, sys
def html_body(lyrics: list) -> str:
html_body = str();
is_in_stanza = False;
lines_in_stanza = 0;
for line in lyrics:
if not is_in_stanza: # Open new stanza
html_body += f'{"":>6}
\n';
is_in_stanza = True
lines_in_stanza = 0
if line == '\n' and lines_in_stanza > 0: # Close stanza
html_body += f'{"":>6}
""" + """
"""
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Quickly create an html file from lyrics');
parser.add_argument('-t', '--title', metavar='', type=ascii);
parser.add_argument('-u', '--url', metavar='', type=ascii);
parser.add_argument('-i', '--icon', metavar='', type=ascii);
parser.add_argument('-d', '--download', metavar='', type=ascii,
help='Download mp3 from url');
parser.add_argument('file', type=ascii, nargs='?',
help='Read lyrics from file');
args = parser.parse_args();
if args.file is not None or not sys.stdin.isatty():
title = args.title[1:-1] if args.title is not None else '';
url = args.url[1:-1] if args.url is not None else '';
icon = args.icon[1:-1] if args.icon is not None else '';
# Read lyrics lines
if args.file is not None:
lyrics_file = open(args.file[1:-1], 'r');
lyrics = lyrics_file.readlines();
else:
lyrics = sys.stdin.readlines();
body = html_body(lyrics);
html = html_from_template(title, icon, body, url);
sys.stdout.write(html);
sys.exit(0);
else:
parser.print_help();
sys.exit(1);