summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2019-01-27 20:35:32 -0600
committerOmar Roth <omarroth@hotmail.com>2019-01-27 20:36:40 -0600
commita9aae6b36c270643461a80b9987ed611077498af (patch)
tree604467831cec476c0b90d02a176d27119f972486 /src
parent96fb2118d58096bb280e7b2bb77d7af33215541b (diff)
downloadinvidious-a9aae6b36c270643461a80b9987ed611077498af.tar.gz
invidious-a9aae6b36c270643461a80b9987ed611077498af.tar.bz2
invidious-a9aae6b36c270643461a80b9987ed611077498af.zip
Add internal redirect for video URLs
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr25
-rw-r--r--src/invidious/views/components/player.ecr6
2 files changed, 28 insertions, 3 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 5bd20e13..b90e9913 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -3652,6 +3652,31 @@ get "/api/manifest/hls_playlist/*" do |env|
manifest
end
+# YouTube /videoplayback links expire after 6 hours,
+# so we have a mechanism here to redirect to the latest version
+get "/latest_version" do |env|
+ id = env.params.query["id"]?
+ itag = env.params.query["itag"]?
+
+ if !id || !itag
+ halt env, status_code: 400
+ end
+
+ video = get_video(id, PG_DB, proxies)
+
+ fmt_stream = video.fmt_stream(decrypt_function)
+ adaptive_fmts = video.adaptive_fmts(decrypt_function)
+
+ urls = (fmt_stream + adaptive_fmts).select { |fmt| fmt["itag"] == itag }
+ if urls.empty?
+ halt env, status_code: 404
+ elsif urls.size > 1
+ halt env, status_code: 409
+ end
+
+ env.redirect urls[0]["url"]
+end
+
options "/videoplayback" do |env|
env.response.headers["Access-Control-Allow-Origin"] = "*"
env.response.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS"
diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecr
index cb7c1276..f5e6f506 100644
--- a/src/invidious/views/components/player.ecr
+++ b/src/invidious/views/components/player.ecr
@@ -11,7 +11,7 @@
<% else %>
<% if params[:listen] %>
<% audio_streams.each_with_index do |fmt, i| %>
- <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["bitrate"] %>k" selected="<%= i == 0 ? true : false %>">
+ <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %>" type='<%= fmt["type"] %>' label="<%= fmt["bitrate"] %>k" selected="<%= i == 0 ? true : false %>">
<% end %>
<% else %>
<% if params[:quality] == "dash" %>
@@ -19,9 +19,9 @@
<% end %>
<% fmt_stream.each_with_index do |fmt, i| %>
<% if params[:quality] %>
- <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= params[:quality] == fmt["label"].split(" - ")[0] %>">
+ <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= params[:quality] == fmt["label"].split(" - ")[0] %>">
<% else %>
- <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= i == 0 ? true : false %>">
+ <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= i == 0 ? true : false %>">
<% end %>
<% end %>
<% end %>