-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.py
83 lines (63 loc) · 2.75 KB
/
util.py
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
# Small utility to convert the chapter marks into YAML markup
import re
# TODO: use a chapter file instead
INPUT = """00:00:00 Intro mit Hitze, Schulanfang und SUP
00:05:24 Musik: Black Bones - Captain Blood (CC-BY-NC-SA 3.0 US) <https://freemusicarchive.org/music/Black_Bones/Pirates_of_the_Coast/08_-_Black_Bones_-_Captain_Blood>
00:09:32 Update CE-Zeichen
00:15:14 Update SpaceSchalter
00:21:19 Was tun, bevor bzw. nachdem das eigene Smartphone geklaut wird?
00:43:13 Open Health HACKademy
00:53:53 Outro
00:54:58 Musik: Roman Meleshin - Delusion (CC-BY 3.0) <https://meleshin.bandcamp.com/track/delusion-electronic-creative-commons-by-license>"""
YAML_INPUT = """
chapters:
- start: '00:00:00.000'
title: 'Intro'
- start: '00:00:49.000'
title: 'Musik: Professor Kliq - Bust This Bust That'
href: 'https://freemusicarchive.org/music/Professor_Kliq/Bust_This_Bust_That/Bust_This_Bust_That'
- start: '00:05:03.000'
title: 'Aktuelles vom Chaostreff'
- start: '00:09:44.000'
title: 'Corona-Warn-App'
- start: '00:28:40.700'
title: 'Musik: Organism - Space Funk'
href: 'https://freemusicarchive.org/music/Organism/S27-X_II/Organism_-S27-X_II-_19_Space_Funk'
- start: '00:33:59.000'
title: 'Kurzmeldungen'
- start: '00:58:30.000'
title: 'Erdbeerschnitzel - Walkampfchampagne'
href: 'https://freemusicarchive.org/music/Erdbeerschnitzel/Pathetik_Party/02-Walkampfchampagne'
"""
def generate_yaml(content):
lines = content.splitlines()
for line in lines:
chapter_start, chapter_title = line.split(' ', 1)
# Extract hyperlink if present
href = ''
if matches := re.search(r' <([^ ]+)>$', chapter_title):
href = f"\n{' ' * 4}href: '{ matches.group(1) }'"
chapter_title = chapter_title[:matches.start()]
template = f""" - start: '{chapter_start}'\n{' ' * 4}title: '{chapter_title}'{href}"""
print(template)
def generate_chapter_file():
import yaml
content = yaml.safe_load(YAML_INPUT)
for chapter in content['chapters']:
template = f"{chapter['start']} {chapter['title']}"
if chapter.get('href'):
template += f" <{chapter['href']}>"
print(template)
#read_content_yaml()
def convert_to_audacity_chapters(chapter_file='chapters.txt'):
from datetime import datetime
with open(chapter_file) as f:
for line in f.readlines():
chapter_start, chapter_title = line.split(' ', 1)
t = datetime.strptime(chapter_start, '%H:%M:%S.%f')
td = t - datetime(1900, 1, 1)
print("{0:0.6f}\t{0:0.6f}\t{1:s}".format(td.total_seconds(), chapter_title), end='')
if __name__ == '__main__':
#generate_yaml(INPUT)
#generate_chapter_file()
convert_to_audacity_chapters()