tangled
alpha
login
or
join now
tilde.link
/
tm
0
fork
atom
TrackMania old videos archive
tm.tilde.link
0
fork
atom
overview
issues
pulls
pipelines
build/nav
tilde.link
3 years ago
9cf9eb8e
89e92e11
+106
1 changed file
expand all
collapse all
unified
split
build.py
+106
build.py
reviewed
···
1
1
+
#! /usr/bin/env python3
2
2
+
3
3
+
import os
4
4
+
import subprocess
5
5
+
6
6
+
SECTIONS = {
7
7
+
'drift': 'Drift',
8
8
+
'fs': 'FreeStyle',
9
9
+
'k': 'K projects',
10
10
+
'lol': 'LOL',
11
11
+
'pf': 'Press Forward',
12
12
+
'ta': 'Time Attack',
13
13
+
'trial': 'Trial',
14
14
+
}
15
15
+
16
16
+
17
17
+
def card(name, web, raw):
18
18
+
return f'''\
19
19
+
<div class="card">
20
20
+
<video controls>
21
21
+
<source src="{web}" />
22
22
+
</video>
23
23
+
<br />
24
24
+
<a href="{raw}">{name}</a>
25
25
+
</div>
26
26
+
'''
27
27
+
28
28
+
29
29
+
def a(href, text, active=False):
30
30
+
html = ['<a']
31
31
+
if active:
32
32
+
html.append(' class="active"')
33
33
+
html.append(f' href="{href}">{text}</a>')
34
34
+
return str().join(html)
35
35
+
36
36
+
37
37
+
def nav(sections, active):
38
38
+
html = ['<nav>']
39
39
+
for _, section in sorted(sections.items()):
40
40
+
id = section['id']
41
41
+
html.append(a(f"#{id}", section['label'], id == active))
42
42
+
html.append('</nav>')
43
43
+
return str().join(html)
44
44
+
45
45
+
46
46
+
def body(sections):
47
47
+
html = []
48
48
+
for section in sections.values():
49
49
+
html.append(f'<section id="{section["id"]}">')
50
50
+
html.append(section['content'])
51
51
+
html.append('</section>')
52
52
+
return str().join(html)
53
53
+
54
54
+
55
55
+
def html(body):
56
56
+
return f'''\
57
57
+
<!DOCTYPE html><html><head>
58
58
+
<!----------------------------------------------------------------------------->
59
59
+
60
60
+
<meta charset="UTF-8" />
61
61
+
<link rel="stylesheet" href="index.css" />
62
62
+
<title>TrackMania vidz</title>
63
63
+
64
64
+
<!----------------------------------------------------------------------------->
65
65
+
</head></body>
66
66
+
<!----------------------------------------------------------------------------->
67
67
+
68
68
+
{body}
69
69
+
70
70
+
<!----------------------------------------------------------------------------->
71
71
+
</body></html>
72
72
+
'''
73
73
+
74
74
+
75
75
+
def main():
76
76
+
file = os.path.realpath(__file__)
77
77
+
root = os.path.dirname(file)
78
78
+
raw_root = os.path.join(root, 'raw')
79
79
+
web_root = os.path.join(root, 'web')
80
80
+
_, categories, _ = next(os.walk(raw_root))
81
81
+
sections = {}
82
82
+
for category in categories:
83
83
+
section = {
84
84
+
'id': category,
85
85
+
'label': SECTIONS.get(category, category),
86
86
+
}
87
87
+
content = []
88
88
+
raw_category = os.path.join(raw_root, category)
89
89
+
for directory, directories, files in os.walk(raw_category):
90
90
+
for file in files:
91
91
+
relative = os.path.relpath(directory, raw_root)
92
92
+
name, _ = os.path.splitext(file)
93
93
+
raw_file = os.path.join('raw', relative, file)
94
94
+
web_file = os.path.join('web', relative, f'{name}.mp4')
95
95
+
content.append(card(name, web_file, raw_file))
96
96
+
section['content'] = os.linesep.join(content)
97
97
+
sections[category] = section
98
98
+
for id, section in sections.items():
99
99
+
section['content'] = nav(sections, id) + section['content']
100
100
+
index = os.path.join(root, 'index.html')
101
101
+
with open(index, 'w') as i:
102
102
+
i.write(html(body(sections)))
103
103
+
104
104
+
105
105
+
if __name__ == '__main__':
106
106
+
main()