add by folder
This commit is contained in:
parent
8a6502bf45
commit
6c6a3151ca
|
@ -9,6 +9,7 @@ class GenHTMLArgs():
|
|||
dest: str
|
||||
title: str
|
||||
description: str
|
||||
by_folder: bool
|
||||
|
||||
def add_genhtml_command(subparsers):
|
||||
genhtml_parser = subparsers.add_parser('genhtml')
|
||||
|
@ -28,6 +29,9 @@ def add_genhtml_command(subparsers):
|
|||
'description',
|
||||
type=str,
|
||||
help='description')
|
||||
genhtml_parser.add_argument(
|
||||
'--by-folder',
|
||||
action='store_true')
|
||||
|
||||
def get_genhtml_args(args) -> GenHTMLArgs:
|
||||
command_args = GenHTMLArgs()
|
||||
|
@ -35,15 +39,18 @@ def get_genhtml_args(args) -> GenHTMLArgs:
|
|||
command_args.dest = args.dest
|
||||
command_args.title = args.title
|
||||
command_args.description = args.description
|
||||
command_args.by_folder = args.by_folder
|
||||
return command_args
|
||||
|
||||
def make_table_for_files(files: list[File]) -> str:
|
||||
def make_table_for_files(files: list[File], by_folder: bool = False) -> str:
|
||||
html_content = ""
|
||||
html_content += """
|
||||
path_head = "<th>Path</th>" if not by_folder else ""
|
||||
|
||||
html_content += f"""
|
||||
<table class="pure-table pure-table-horizontal">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Path</th>
|
||||
{path_head}
|
||||
<th>Title</th>
|
||||
<th>Artist</th>
|
||||
<th>Format</th>
|
||||
|
@ -52,15 +59,18 @@ def make_table_for_files(files: list[File]) -> str:
|
|||
<tbody>
|
||||
"""
|
||||
isOdd = True
|
||||
print(files)
|
||||
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)
|
||||
path_data = f"<td>{data_path}</td>" if not by_folder else ""
|
||||
|
||||
html_content += f"""
|
||||
<tr class="{tdClass}">
|
||||
<td>{data_path}</td>
|
||||
{path_data}
|
||||
<td>{data_title}</td>
|
||||
<td>{data_artist}</td>
|
||||
<td>{data_extension}</td>
|
||||
|
@ -71,8 +81,7 @@ def make_table_for_files(files: list[File]) -> str:
|
|||
</tbody>
|
||||
</table>
|
||||
"""
|
||||
|
||||
|
||||
return html_content
|
||||
|
||||
class GenHTMLCommand():
|
||||
def __init__(self, args: GenHTMLArgs):
|
||||
|
@ -105,7 +114,19 @@ class GenHTMLCommand():
|
|||
<body>
|
||||
"""
|
||||
|
||||
html_content += make_table_for_files(files)
|
||||
if self.args.by_folder:
|
||||
files_per_folder: dict[str, list[File]] = {}
|
||||
for file in files:
|
||||
if not file.path_from_src in files_per_folder.keys():
|
||||
files_per_folder[file.path_from_src] = []
|
||||
files_per_folder[file.path_from_src].append(file)
|
||||
for folder in files_per_folder.keys():
|
||||
folder_name = folder
|
||||
folder_files = files_per_folder[folder_name]
|
||||
html_content += f"<h1>{folder_name}</h1>"
|
||||
html_content += make_table_for_files(folder_files, True)
|
||||
else:
|
||||
html_content += make_table_for_files(files)
|
||||
|
||||
html_content += """
|
||||
</body>
|
||||
|
|
Loading…
Reference in a new issue