add a html generator for listings
This commit is contained in:
parent
881bd70f8d
commit
6551de89e8
|
@ -2,6 +2,8 @@
|
|||
|
||||
import argparse
|
||||
|
||||
from musicutil.commands.genhtml_command import GenHTMLCommand, add_genhtml_command, get_genhtml_args
|
||||
|
||||
from .commands.process_command import ProcessCommand, add_process_command, get_process_args
|
||||
from .commands.copy_command import CopyCommand, add_copy_command, get_copy_args
|
||||
from .commands.transcode_command import TranscodeCommand, add_transcode_command, get_transcode_args
|
||||
|
@ -13,6 +15,7 @@ subparsers = parser.add_subparsers(dest="subparser_name")
|
|||
add_copy_command(subparsers)
|
||||
add_process_command(subparsers)
|
||||
add_transcode_command(subparsers)
|
||||
add_genhtml_command(subparsers)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -22,3 +25,5 @@ elif args.subparser_name == "copy":
|
|||
CopyCommand(get_copy_args(args)).run()
|
||||
elif args.subparser_name == "transcode":
|
||||
TranscodeCommand(get_transcode_args(args)).run()
|
||||
elif args.subparser_name == "genhtml":
|
||||
GenHTMLCommand(get_genhtml_args(args)).run()
|
||||
|
|
103
musicutil/commands/genhtml_command.py
Normal file
103
musicutil/commands/genhtml_command.py
Normal file
|
@ -0,0 +1,103 @@
|
|||
from musicutil.utils.load_tag_information import load_tag_information
|
||||
from musicutil.utils.scan_for_music import scan_for_music
|
||||
|
||||
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"""
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="https://unpkg.com/purecss@2.0.6/build/pure-min.css" integrity="sha384-Uu6IeWbM+gzNVXJcM9XV3SohHtmWE+3VGi496jvgX1jyvDTXfdK+rfZc8C1Aehk5" crossorigin="anonymous">
|
||||
<title>{self.args.title}</title>
|
||||
<meta property="og:title" content="{self.args.title}" />
|
||||
<meta property="og:description" content="{self.args.description}" />
|
||||
</head>
|
||||
<body>
|
||||
"""
|
||||
html_content += """
|
||||
<table class="pure-table pure-table-horizontal">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Path</th>
|
||||
<th>Title</th>
|
||||
<th>Artist</th>
|
||||
<th>Format</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
"""
|
||||
isOdd = True
|
||||
for file in files:
|
||||
tdClass = "pure-table-odd" if isOdd else "pure-table-even"
|
||||
|
||||
html_content += f"""
|
||||
<tr class="{tdClass}">
|
||||
<td>{file.path_from_src}</td>
|
||||
<td>{file.tags.title}</td>
|
||||
<td>{file.tags.artist}</td>
|
||||
<td>{file.extension}</td>
|
||||
</tr>
|
||||
"""
|
||||
isOdd = not isOdd
|
||||
html_content += """
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
print("Writing HTML...")
|
||||
with open(self.args.dest, "w+") as html_file:
|
||||
html_file.write(html_content)
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue