Skip to content

Commit 7d83f1c

Browse files
alexmarasNorkzYT
authored andcommitted
feat: route to invidious companion on downloads (iv-org#5224)
1 parent ebc4bdb commit 7d83f1c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/invidious/frontend/watch_page.cr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ module Invidious::Frontend::WatchPage
2323
return "<p id=\"download\">#{translate(locale, "Download is disabled")}</p>"
2424
end
2525

26+
url = "/download"
27+
if (CONFIG.invidious_companion.present?)
28+
invidious_companion = CONFIG.invidious_companion.sample
29+
url = "#{invidious_companion.public_url}/download?check=#{invidious_companion_encrypt(video.id)}"
30+
end
31+
2632
return String.build(4000) do |str|
2733
str << "<form"
2834
str << " class=\"pure-form pure-form-stacked\""
29-
str << " action='/download'"
35+
str << " action='#{url}'"
3036
str << " method='post'"
3137
str << " rel='noopener'"
3238
str << " target='_blank'>"

src/invidious/routes/watch.cr

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ module Invidious::Routes::Watch
293293
if CONFIG.disabled?("downloads")
294294
return error_template(403, "Administrator has disabled this endpoint.")
295295
end
296+
if CONFIG.invidious_companion.present?
297+
return error_template(403, "Downloads should be routed through Companion when present")
298+
end
296299

297300
title = env.params.body["title"]? || ""
298301
video_id = env.params.body["id"]? || ""
@@ -328,13 +331,7 @@ module Invidious::Routes::Watch
328331
env.params.query["title"] = filename
329332
env.params.query["local"] = "true"
330333

331-
if (CONFIG.invidious_companion.present?)
332-
video = get_video(video_id)
333-
invidious_companion = CONFIG.invidious_companion.sample
334-
return env.redirect "#{invidious_companion.public_url}/latest_version?#{env.params.query}"
335-
else
336-
return Invidious::Routes::VideoPlayback.latest_version(env)
337-
end
334+
return Invidious::Routes::VideoPlayback.latest_version(env)
338335
else
339336
return error_template(400, "Invalid label or itag")
340337
end

0 commit comments

Comments
 (0)