~cadence/tube-devel

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

[PATCH cloudtube v2 0/2] Implement video captions

~lomanic
Details
Message ID
<161697374641.24203.2301967341090028758-0@git.sr.ht>
DKIM signature
missing
Download raw message
Implement video captions

Lomanic (2):
  Refactor video.js so request resolution is not handled in rendering
    function
  Implement video captions

 api/captions.js | 24 ++++++++++++++++++++++++
 api/video.js    | 26 ++++++++++++++------------
 pug/video.pug   |  2 ++
 3 files changed, 40 insertions(+), 12 deletions(-)
 create mode 100644 api/captions.js

-- 
2.30.2

[PATCH cloudtube v2 1/2] Refactor video.js so request resolution is not handled in rendering function

~lomanic
Details
Message ID
<161697374641.24203.2301967341090028758-1@git.sr.ht>
In-Reply-To
<161697374641.24203.2301967341090028758-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
Patch: +9 -12
From: Lomanic <lomanic@hotmail.fr>

Also remove useless else's
---
 api/video.js | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/api/video.js b/api/video.js
index 9d63276..aa7e03c 100644
--- a/api/video.js
+++ b/api/video.js
@@ -71,10 +71,8 @@ function rewriteVideoDescription(descriptionHtml, id) {
	return descriptionHtml
}

async function renderVideo(videoPromise, {user, id, instanceOrigin}, locals = {}) {
async function renderVideo(video, {user, id, instanceOrigin}, locals = {}) {
	try {
		// resolve video
		const video = await videoPromise
		if (!video) throw new Error("The instance returned null.")
		if (video.error) throw new InstanceError(video.error, video.identifier)
		// process stream list ordering
@@ -167,17 +165,16 @@ module.exports = [
				if (!settings.local) {
					const instanceOrigin = settings.instance
					const outURL = `${instanceOrigin}/api/v1/videos/${id}`
					const videoPromise = request(outURL).then(res => res.json())
					return renderVideo(videoPromise, {user, id, instanceOrigin}, {mediaFragment})
				} else {
					return render(200, "pug/local-video.pug", {id})
					const video = await request(outURL).then(res => res.json())
					return renderVideo(video, {user, id, instanceOrigin}, {mediaFragment})
				}
			} else { // req.method === "POST"
				const video = JSON.parse(new URLSearchParams(body.toString()).get("video"))
				const videoPromise = Promise.resolve(video)
				const instanceOrigin = "http://localhost:3000"
				return renderVideo(videoPromise, {user, id, instanceOrigin}, {mediaFragment})
				return render(200, "pug/local-video.pug", {id})
			}
			// req.method === "POST"
			const vid = JSON.parse(new URLSearchParams(body.toString()).get("video"))
			const video = await Promise.resolve(vid)
			const instanceOrigin = "http://localhost:3000"
			return renderVideo(video, {user, id, instanceOrigin}, {mediaFragment})
		}
	}
]
-- 
2.30.2

[PATCH cloudtube v2 2/2] Implement video captions

~lomanic
Details
Message ID
<161697374641.24203.2301967341090028758-2@git.sr.ht>
In-Reply-To
<161697374641.24203.2301967341090028758-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
Patch: +31 -0
From: Lomanic <lomanic@hotmail.fr>

Proxy requests to NewLeaf/Invidious backend so captions are served on the
same domain
---
 api/captions.js | 24 ++++++++++++++++++++++++
 api/video.js    |  5 +++++
 pug/video.pug   |  2 ++
 3 files changed, 31 insertions(+)
 create mode 100644 api/captions.js

diff --git a/api/captions.js b/api/captions.js
new file mode 100644
index 0000000..c2f87c2
--- /dev/null
+++ b/api/captions.js
@@ -0,0 +1,24 @@
const fetch = require("node-fetch")
const {getUser} = require("../utils/getuser")
const constants = require("../utils/constants.js")

module.exports = [
	{
		route: `/captions/(${constants.regex.video_id})`, methods: ["GET"], code: async ({req, fill, url}) => {
			const videoID = fill[0]
			const lang = url.searchParams.get("lang") || ""
			const instanceOrigin = getUser(req).getSettingsOrDefaults().instance
			const fetchURL = new URL(`${instanceOrigin}/api/v1/captions/${videoID}`)
			for(const [key, value] of url.searchParams) {
				fetchURL.searchParams.set(key, value)
			}
			return fetch(fetchURL.toString()).then(res => {
				return {
					statusCode: res.status,
					contentType: res.headers.get("content-type"),
					stream: res.body
				}
			})
		}
	}
]
diff --git a/api/video.js b/api/video.js
index aa7e03c..6c1151f 100644
--- a/api/video.js
+++ b/api/video.js
@@ -98,6 +98,11 @@ async function renderVideo(video, {user, id, instanceOrigin}, locals = {}) {
		if (!video.second__viewCountText && video.viewCount) {
			video.second__viewCountText = converters.viewCountToText(video.viewCount)
		}
		// proxy captions via CloudTube
		for (const caption of video.captions) {
			const params = new URLSearchParams(caption.url.slice(caption.url.indexOf("?")))
			caption.url = `/captions/${video.videoId}?${params}`
		}
		video.descriptionHtml = rewriteVideoDescription(video.descriptionHtml, id)
		return render(200, "pug/video.pug", Object.assign(locals, {video, subscribed, instanceOrigin}))
	} catch (e) {
diff --git a/pug/video.pug b/pug/video.pug
index 2b09e10..9364106 100644
--- a/pug/video.pug
+++ b/pug/video.pug
@@ -23,6 +23,8 @@ block content
          if format
            video(controls preload="auto" width=format.second__width height=format.second__height data-itag=format.itag)#video.video
              source(src=format.url+mediaFragment type=format.type)
              each t in video.captions
                track(label=t.label kind="subtitles" srclang=t.languageCode src=t.url)
          else
            video(src="")#video.video
            .stream-notice The server provided no playback streams.
-- 
2.30.2

Re: [PATCH cloudtube v2 2/2] Implement video captions

Details
Message ID
<20210405013226.2d2ea480e8e1385d7ed5db62@disroot.org>
In-Reply-To
<161697374641.24203.2301967341090028758-2@git.sr.ht> (view parent)
DKIM signature
pass
Download raw message
Thanks, I got this all sorted and working. I hacked at your commits a
bit to fix up a couple of issues, change the route, and add
auto-caption stuff. Hope you don't mind!
Reply to thread Export thread (mbox)