2020-08-11 16:14:38 +02:00
|
|
|
from subprocess import run
|
|
|
|
import csv
|
|
|
|
import json
|
|
|
|
import time
|
|
|
|
|
2020-11-24 20:51:24 +01:00
|
|
|
ACRONYM = "sch"
|
2020-08-11 16:14:38 +02:00
|
|
|
|
|
|
|
FORMATS = {
|
|
|
|
"opus": ["-b:a", "48k"],
|
|
|
|
"m4a": [
|
|
|
|
"-b:a",
|
|
|
|
"48k",
|
|
|
|
"-f",
|
|
|
|
"ipod",
|
|
|
|
"-profile:a",
|
|
|
|
"aac_he",
|
|
|
|
"-disposition:v:0",
|
|
|
|
"attached_pic",
|
|
|
|
],
|
|
|
|
"oga": ["-b:a", "64k", "-c:a", "libvorbis"],
|
|
|
|
"mp3": ["-b:a", "72k", "-map", "0:0", "-map", "1:0"],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def path_to_episode(name, format):
|
|
|
|
if format in ["original", "txt", "md"]:
|
|
|
|
base = "content"
|
|
|
|
else:
|
|
|
|
base = "static/episodes"
|
|
|
|
|
|
|
|
if format == "original":
|
|
|
|
format = "opus"
|
|
|
|
|
|
|
|
return f"{base}/{name}.{format}"
|
|
|
|
|
|
|
|
|
|
|
|
def get_chapters(episode):
|
|
|
|
with open(path_to_episode(episode, "txt")) as f:
|
|
|
|
chapter_reader = csv.reader(f, delimiter="\t")
|
|
|
|
for chapter in chapter_reader:
|
|
|
|
yield {"start": float(chapter[0]), "title": chapter[2]}
|
|
|
|
|
|
|
|
|
|
|
|
def get_episode_info(name, format):
|
|
|
|
path = path_to_episode(name, format)
|
|
|
|
return json.loads(
|
|
|
|
run(
|
|
|
|
[
|
2021-11-30 19:17:20 +01:00
|
|
|
"ffprobe",
|
2020-08-11 16:14:38 +02:00
|
|
|
"-loglevel",
|
|
|
|
"error",
|
|
|
|
"-show_format",
|
|
|
|
"-print_format",
|
|
|
|
"json",
|
|
|
|
path,
|
|
|
|
],
|
|
|
|
capture_output=True,
|
|
|
|
).stdout
|
|
|
|
)["format"]
|
|
|
|
|
|
|
|
|
|
|
|
def sexagesimal(ts):
|
|
|
|
return time.strftime("%H:%M:%S", time.gmtime(ts)) + str(round(ts % 1, 3))[1:]
|