-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_generator.py
More file actions
154 lines (120 loc) · 4.58 KB
/
Copy pathhtml_generator.py
File metadata and controls
154 lines (120 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import os
from html_colors import return_css_color_names
from json_tools import load_config_data, parse_config_data
config_file = "config.json"
# generate tr styles
def create_tr_styles(n_divs):
div_html = """<style>
"""
color_list = return_css_color_names()
for i in range(n_divs):
div_html_dummy = f"""tr.color_{i+1} td{{
background-color: {color_list[i]};
padding-top: 10px;
text-align:center;
}}
tr.color_player_{i+1} td{{
background-color: {color_list[i]};
padding-bottom: 10px;
text-align:center;
}}
"""
div_html += div_html_dummy
div_html += """
</style>
</head>"""
return div_html
def generate_audio_players(audio_file_list, mode, current_class):
player_html = ""
player_html += f"<tr class=color_player_{current_class}>"
for idx, soundtrack in enumerate(audio_file_list):
file_path = os.path.join("..", mode, soundtrack)
player_audio = f"""<td>
<audio controls>
<source src="{file_path}" type="audio/mpeg">
</audio>
</td>
"""
player_html += player_audio
player_html += "</tr>"
return player_html
def create_title_row(audio_file_list, current_class):
html_output = f"<tr class=color_{current_class}>"
for audio_file in audio_file_list:
html_output += f"<td>{audio_file.split('.')[0]}</td>"
html_output += "</tr>"
return html_output
def create_div(input_html, id):
return f'<div class="div-{id}">' + input_html + "</div>"
def generate_html_start():
return """<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
"""
def generate_html_title(pages_dict, current_sample_set):
header_text = (f"<h1 class='text-center'>{pages_dict[current_sample_set]}</h1><div class='container'>"
"<header class='d-flex justify-content-center py-3'>"
"<ul class='nav nav-pills'>")
for k, v in pages_dict.items():
if k == current_sample_set:
header_text += f"<li class='nav-item'><a href='{v}.html' class='nav-link active' aria-current='page'>{k} - {v}</a></li>"
else:
header_text += f"<li class='nav-item'><a href='{v}.html' class='nav-link'>{k} - {v}</a></li>"
header_text += "</div>"
return header_text
def generate_html_end():
return """</table></div></body>
</html>"""
def create_output_file(file_name, content):
with open(f"html_output/{file_name}", "w") as file:
file.write(content)
def generate_soundtrack_players():
chunks = [soundtrack_list[x : x + 4] for x in range(0, len(soundtrack_list), 4)]
soundtrack_html = ""
for chunk in chunks:
soundtrack_html += create_title_row(chunk, 1)
soundtrack_html += generate_audio_players(chunk, "playlists", 1)
return soundtrack_html
def generate_samples_html():
samples_html = ""
for idx in range(int(len(samples_list) / 8)):
samples_group = []
current_div = 2
for jdx in range(8):
samples_group.append(samples_list[idx * 8 + jdx])
if not all(
[True if sample == "dummy.wav" else False for sample in samples_group]
):
# generate html for group of samples, in groups of 4
chunks = [samples_group[x : x + 4] for x in range(0, len(samples_group), 4)]
for chunk in chunks:
samples_html += create_title_row(chunk, current_div)
samples_html += generate_audio_players(chunk, "audio", current_div)
current_div += 1
return samples_html
current_sample_set = 1
config_data = load_config_data(config_file)
samples_list, soundtrack_list, pages_dict, page_name = parse_config_data(
config_data, current_sample_set
)
for page_num, page_name in pages_dict.items():
samples_list, soundtrack_list, pages_dict, page_name = parse_config_data(
config_data, page_num
)
html_output = (
generate_html_start()
+ create_tr_styles(5)
+ "<body> <div class='container'>"
+ generate_html_title(pages_dict, page_num)
+ "<table>"
+ generate_soundtrack_players()
+ generate_samples_html()
+ generate_html_end()
)
create_output_file(f"{page_name}.html", html_output)
# TODO: Output all files to new folder - HTML and linked audio files
# TODO: Add day name into output process (for folder and page titles)