2021-05-25 20:53:09 +02:00
|
|
|
import re
|
2020-03-07 10:45:39 +01:00
|
|
|
from datetime import timedelta
|
|
|
|
from pathlib import Path
|
2020-04-15 18:11:45 +02:00
|
|
|
from typing import Optional
|
|
|
|
|
2021-07-07 17:27:21 +02:00
|
|
|
from app import cache
|
2020-04-15 18:11:45 +02:00
|
|
|
from data import single_speaker
|
2020-03-07 10:45:39 +01:00
|
|
|
|
|
|
|
srtdir = Path("./data/subtitles/")
|
|
|
|
|
|
|
|
|
|
|
|
def td_to_milliseconds(td: timedelta) -> int:
|
|
|
|
return int(td.total_seconds() * 1000)
|
|
|
|
|
|
|
|
|
|
|
|
def milliseconds_to_td(ms: int) -> timedelta:
|
|
|
|
return timedelta(milliseconds=ms)
|
|
|
|
|
|
|
|
|
2020-04-15 18:11:45 +02:00
|
|
|
def episode_speaker(series_title: str, episode: int) -> Optional[str]:
|
2021-07-04 22:24:51 +02:00
|
|
|
try:
|
|
|
|
series = single_speaker[series_title]
|
|
|
|
except KeyError:
|
|
|
|
return "?"
|
2020-04-15 18:11:45 +02:00
|
|
|
if episode in series:
|
|
|
|
return series[episode]
|
|
|
|
return None
|
2020-08-08 15:18:14 +02:00
|
|
|
|
|
|
|
|
2021-05-25 20:53:09 +02:00
|
|
|
title_regex = re.compile(r"Ep(?:is|si)ode (\d+)")
|
|
|
|
|
|
|
|
|
|
|
|
def title_to_episodenumber(title: str, video_number: int) -> int:
|
|
|
|
print(title)
|
|
|
|
try:
|
|
|
|
match = title_regex.search(title)
|
|
|
|
if not match:
|
|
|
|
if "Hit Points for Level 12" in title:
|
|
|
|
return 99
|
|
|
|
elif "Hit Points for Level 15" in title:
|
|
|
|
return 136
|
|
|
|
else:
|
|
|
|
raise ValueError("No episode number found in title")
|
|
|
|
return int(match.group(1))
|
|
|
|
except ValueError:
|
|
|
|
if title == "Campaign 1": # one-shots at the end of campaign 1
|
|
|
|
return video_number - 3
|
2021-07-04 22:24:51 +02:00
|
|
|
elif "Exandria" in title:
|
|
|
|
return 1
|
2021-05-25 20:53:09 +02:00
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
2020-08-08 15:18:14 +02:00
|
|
|
def pretty_title(title: str) -> str:
|
|
|
|
if "|" in title:
|
|
|
|
return title.split("|")[0].strip()
|
|
|
|
if "Handbooker Helper:" in title:
|
|
|
|
return title.replace("Handbooker Helper:", "").strip()
|
|
|
|
if "Critical Role RPG Show" in title:
|
|
|
|
return title.split("-")[0].strip()
|
|
|
|
else:
|
|
|
|
return title.strip()
|
2021-07-07 17:27:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
def clear_cache() -> None:
|
|
|
|
cache.clear()
|