mirror of
https://codeberg.org/SimpleWeb/SimpleerTube.git
synced 2024-11-22 08:31:31 +00:00
Propose subtitles in the native video player
This commit is contained in:
parent
8e473b7948
commit
ee6b30b0c0
15
main.py
15
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("/<string:domain>/videos/watch/<string:id>/")
|
||||
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("/<string:domain>/videos/watch/<string:id>/<string:lang>.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]
|
||||
|
|
10
peertube.py
10
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)
|
||||
|
|
|
@ -22,7 +22,8 @@ By:
|
|||
<b>Resolutions:</b>
|
||||
{% else %}
|
||||
<video height="300" style="max-width: 100%" controls>
|
||||
<source src="{{ video.video }}">
|
||||
<source src="{{ video.video }}">{% for track in video.captions.data %}
|
||||
<track kind="subtitles" srclang="{{ track.language.id }}" label="{{ track.language.label }}" src="/{{ domain }}/videos/watch/{{ video.uuid }}/{{ track.language.id }}.vtt">{% endfor %}
|
||||
</video>
|
||||
<br>
|
||||
<b>Resolutions:</b>
|
||||
|
|
Loading…
Reference in a new issue