-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
58 lines (47 loc) · 1.66 KB
/
config.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
import datetime
from typing import List
from hololive import hololive
from string import Template
from yaml import safe_load, YAMLError
with open("config.yaml", 'r') as stream:
try:
tmp_config = safe_load(stream)
except YAMLError as exc:
print("invalid config")
raise exc
# Templating options in config.yaml
final_output_template = tmp_config['locations']['final']
def get_final_output_path_from_stream(stream: hololive.Stream) -> str:
return Template(final_output_template).substitute(
channel=stream.channel_id,
id=stream.id,
title=stream.title.replace('/', '-'),
ext="mkv",
topic=stream.topic_id or "topic_not_set",
channel_org=stream.channel_org,
channel_name=stream.channel_name.replace("/", "-").replace("\\", "-"),
channel_id=stream.channel_id,
date=(stream.available_at or datetime.datetime.now()).strftime("%Y%m%d")
)
class holodex_search:
org: str
channel_id: str
topics: List[str]
def __init__(self, org: str, channel_id: str, topics: List[str]):
self.org = org
self.channel_id = channel_id
self.topics = topics
# Parse a list of "{org}:{channel_id}:{topics}" into a list of holodex_search instances
holodex_searches: List[holodex_search] = []
for target in tmp_config["youtube_targets"]:
target_parts = target.split(":")
org = target_parts[0]
channel_id = target_parts[1]
topics = target_parts[2].split(",")
if org == "*":
org = None
if channel_id == "*":
channel_id = None
if "*" in topics:
topics = [None]
holodex_searches.append(holodex_search(org, channel_id, topics))