diff --git a/main.py b/main.py index 2d884a1..3c20fb9 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,7 @@ h2t.ignore_links = True class VideoWrapper: def __init__(self, a, quality): self.name = a["name"] + self.uuid = a["uuid"] self.channel = a["channel"] self.description = a["description"] self.thumbnailPath = a["thumbnailPath"] @@ -19,6 +20,7 @@ class VideoWrapper: self.category = a["category"] self.licence = a["licence"] self.language = a["language"] + self.captions = a["captions"] self.privacy = a["privacy"] self.tags = a["tags"] @@ -258,6 +260,7 @@ async def search(domain, term, page): @app.route("//videos/watch//") async def video(domain, id): data = peertube.video(domain, id) + data["captions"] = peertube.video_captions(domain, id) quality = request.args.get("quality") embed = request.args.get("embed") vid = VideoWrapper(data, quality) @@ -403,6 +406,18 @@ async def video_channels__about(domain, name): about = peertube.video_channel(domain, name) ) +# --- Subtitles/captions proxying --- +@app.route("//videos/watch//.vtt") +async def subtitles(domain, id, lang): + try: + return peertube.video_captions_download(domain, id, lang) + except Exception as e: + return await render_template( + "error.html", + error_number = "500", + error_reason = e + ), 500 + if __name__ == "__main__": if len(sys.argv) == 3: interface = sys.argv[1] diff --git a/peertube.py b/peertube.py index 5bbc03e..186c473 100644 --- a/peertube.py +++ b/peertube.py @@ -22,6 +22,16 @@ def video(domain, id): url = "https://" + domain + "/api/v1/videos/" + id return json.loads(requests.get(url).text) +def video_captions(domain, id): + url = "https://" + domain + "/api/v1/videos/" + id + "/captions" + return json.loads(requests.get(url).text) + +def video_captions_download(domain, id, lang): + # URL is hardcoded to prevent further proxying. URL may change with updates, see captions API + # eg. https://kolektiva.media/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/captions + url = "https://" + domain + "/lazy-static/video-captions/" + id + '-' + lang + ".vtt" + return requests.get(url).text + def search(domain, term, start=0, count=10): url = "https://" + domain + "/api/v1/search/videos?start=" + str(start) + "&count=" + str(count) + "&search=" + term + "&sort=-match&searchTarget=local" return json.loads(requests.get(url).text) diff --git a/templates/video.html b/templates/video.html index 80c6b90..d64f791 100644 --- a/templates/video.html +++ b/templates/video.html @@ -22,7 +22,8 @@ By: Resolutions: {% else %}
Resolutions: