~metalune/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Fix subtitles proxying, every URL is unique and beautiful

southerntofu
Details
Message ID
<20210729012108.2858268-1-southerntofu@thunix.net>
DKIM signature
missing
Download raw message
Patch: +12 -3
---
 main.py     | 10 +++++++++-
 peertube.py |  5 +++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/main.py b/main.py
index 05b608d..764a640 100644
--- a/main.py
+++ b/main.py
@@ -410,7 +410,15 @@ async def video_channels__about(domain, name):
@app.route("/<string:domain>/videos/watch/<string:id>/<string:lang>.vtt")
async def subtitles(domain, id, lang):
    try:
        return peertube.video_captions_download(domain, id, lang)
        captions = peertube.video_captions(domain, id)
        print(captions)
        for entry in captions["data"]:
            if entry["language"]["id"] == lang: return peertube.video_captions_download(domain, entry["captionPath"].split('/')[-1])
        return await render_template(
            "error.html",
            error_number = "404",
            error_reason = "This video has no subtitles/captions inthe requested language"
        ), 404
    except Exception as e:
        return await render_template(
            "error.html",
diff --git a/peertube.py b/peertube.py
index 186c473..d938ac9 100644
--- a/peertube.py
+++ b/peertube.py
@@ -26,10 +26,11 @@ 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):
def video_captions_download(domain, caption_id):
    # 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"
    # TODO: What if the captionPath doesn't follow this format on an instance? Should we really proxy ANYTHING returned by API?
    url = "https://" + domain + "/lazy-static/video-captions/" + caption_id
    return requests.get(url).text

def search(domain, term, start=0, count=10):
-- 
2.30.2
Details
Message ID
<CD6NH4EHHYYG.2YQSOLM91LIOD@thinkpad>
In-Reply-To
<20210729012108.2858268-1-southerntofu@thunix.net> (view parent)
DKIM signature
pass
Download raw message
Thank you a lot!
Reply to thread Export thread (mbox)