Skip to content

Commit

Permalink
add hmac_key to all latest_version endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
unixfox committed Aug 25, 2023
1 parent cd9ca36 commit b935c2b
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions patches/009-restrict-playback.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 6a52c472e4c15e0561fd66a0a9363c82bd5437ce Mon Sep 17 00:00:00 2001
From fa9097ebf4caaae262adfe5548062752644bef0e Mon Sep 17 00:00:00 2001
From: Emilien Devos <[email protected]>
Date: Sat, 8 Oct 2022 13:34:52 +0200
Subject: [PATCH 1/1] enforce playback from main website
Expand All @@ -7,12 +7,12 @@ Subject: [PATCH 1/1] enforce playback from main website
assets/js/player.js | 4 ++--
assets/js/watch.js | 3 +++
src/invidious/routes/api/v1/videos.cr | 16 ++++++++++++++++
src/invidious/views/components/player.ecr | 15 +++++++++------
src/invidious/views/components/player.ecr | 19 +++++++++++--------
src/invidious/views/watch.ecr | 1 +
5 files changed, 31 insertions(+), 8 deletions(-)
5 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/assets/js/player.js b/assets/js/player.js
index ee678663..2c2bedcb 100644
index bb53ac24..43bd902f 100644
--- a/assets/js/player.js
+++ b/assets/js/player.js
@@ -372,7 +372,7 @@ if (!video_data.params.listen && video_data.params.quality === 'dash') {
Expand All @@ -34,7 +34,7 @@ index ee678663..2c2bedcb 100644
timeout: 60000
}, {
diff --git a/assets/js/watch.js b/assets/js/watch.js
index cff84e4d..a60a7b2d 100644
index 36506abd..babc66a0 100644
--- a/assets/js/watch.js
+++ b/assets/js/watch.js
@@ -167,6 +167,7 @@ function get_reddit_comments() {
Expand Down Expand Up @@ -62,10 +62,10 @@ index cff84e4d..a60a7b2d 100644
if (load_replies) url += '&action=action_get_comment_replies';

diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr
index a6b2eb4e..e4f82fac 100644
index af4fc806..f1bd2dd6 100644
--- a/src/invidious/routes/api/v1/videos.cr
+++ b/src/invidious/routes/api/v1/videos.cr
@@ -24,6 +24,10 @@ module Invidious::Routes::API::V1::Videos
@@ -27,6 +27,10 @@ module Invidious::Routes::API::V1::Videos
id = env.params.url["id"]
region = env.params.query["region"]? || env.params.body["region"]?

Expand All @@ -76,7 +76,7 @@ index a6b2eb4e..e4f82fac 100644
if id.nil? || id.size != 11 || !id.matches?(/^[\w-]+$/)
return error_json(400, "Invalid video ID")
end
@@ -160,6 +164,10 @@ module Invidious::Routes::API::V1::Videos
@@ -173,6 +177,10 @@ module Invidious::Routes::API::V1::Videos
id = env.params.url["id"]
region = env.params.query["region"]?

Expand All @@ -87,7 +87,7 @@ index a6b2eb4e..e4f82fac 100644
begin
video = get_video(id, region: region)
rescue ex : NotFoundException
@@ -232,6 +240,10 @@ module Invidious::Routes::API::V1::Videos
@@ -245,6 +253,10 @@ module Invidious::Routes::API::V1::Videos
source = env.params.query["source"]?
source ||= "archive"

Expand All @@ -98,7 +98,7 @@ index a6b2eb4e..e4f82fac 100644
if !id.match(/[a-zA-Z0-9_-]{11}/)
haltf env, 400
end
@@ -301,6 +313,10 @@ module Invidious::Routes::API::V1::Videos
@@ -314,6 +326,10 @@ module Invidious::Routes::API::V1::Videos

id = env.params.url["id"]

Expand All @@ -110,7 +110,7 @@ index a6b2eb4e..e4f82fac 100644
source ||= "youtube"

diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecr
index c3c02df0..ff4dc000 100644
index c3c02df0..0e673803 100644
--- a/src/invidious/views/components/player.ecr
+++ b/src/invidious/views/components/player.ecr
@@ -1,10 +1,11 @@
Expand All @@ -126,17 +126,20 @@ index c3c02df0..ff4dc000 100644
<% else %>
<% if params.listen %>
<% # default to 128k m4a stream
@@ -21,6 +22,7 @@
@@ -20,6 +21,7 @@

audio_streams.each_with_index do |fmt, i|
src_url = "/latest_version?id=#{video.id}&itag=#{fmt["itag"]}"
+ src_url += "&hmac_key=#{hmac_key}"
src_url += "&local=true" if params.local
+ src_url += "&hmac_key=#{hmac_key}" if params.local

bitrate = fmt["bitrate"]
mimetype = HTML.escape(fmt["mimeType"].as_s)
@@ -29,12 +31,12 @@
@@ -27,14 +29,14 @@

selected = (i == best_m4a_stream_index)
%>
<source src="<%= src_url %>" type='<%= mimetype %>' label="<%= bitrate %>k" selected="<%= selected %>">
- <source src="<%= src_url %>" type='<%= mimetype %>' label="<%= bitrate %>k" selected="<%= selected %>">
+ <source src="<%= src_url %>&hmac_key=<%= hmac_key %>" type='<%= mimetype %>' label="<%= bitrate %>k" selected="<%= selected %>">
<% if !params.local && !CONFIG.disabled?("local") %>
- <source src="<%= src_url %>&local=true" type='<%= mimetype %>' hidequalityoption="true">
+ <source src="<%= src_url %>&local=true&hmac_key=<%= hmac_key %>" type='<%= mimetype %>' hidequalityoption="true">
Expand All @@ -149,17 +152,20 @@ index c3c02df0..ff4dc000 100644
<% end %>

<%
@@ -43,6 +45,7 @@
@@ -42,6 +44,7 @@
fmt_stream.sort_by! {|f| params.quality == f["quality"] ? 0 : 1 }
fmt_stream.each_with_index do |fmt, i|
src_url = "/latest_version?id=#{video.id}&itag=#{fmt["itag"]}"
+ src_url += "&hmac_key=#{hmac_key}"
src_url += "&local=true" if params.local
+ src_url += "&hmac_key=#{hmac_key}" if params.local

quality = fmt["quality"]
mimetype = HTML.escape(fmt["mimeType"].as_s)
@@ -51,17 +54,17 @@
@@ -49,19 +52,19 @@

selected = params.quality ? (params.quality == quality) : (i == 0)
%>
<source src="<%= src_url %>" type="<%= mimetype %>" label="<%= quality %>" selected="<%= selected %>">
- <source src="<%= src_url %>" type="<%= mimetype %>" label="<%= quality %>" selected="<%= selected %>">
+ <source src="<%= src_url %>&hmac_key=<%= hmac_key %>" type="<%= mimetype %>" label="<%= quality %>" selected="<%= selected %>">
<% if !params.local && !CONFIG.disabled?("local") %>
- <source src="<%= src_url %>&local=true" type="<%= mimetype %>" hidequalityoption="true">
+ <source src="<%= src_url %>&local=true&hmac_key=<%= hmac_key %>" type="<%= mimetype %>" hidequalityoption="true">
Expand All @@ -179,7 +185,7 @@ index c3c02df0..ff4dc000 100644
<% end %>
</video>
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index a6f2e524..8c5b7f29 100644
index 498d57a1..86a0dd41 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -64,6 +64,7 @@ we're going to need to do it here in order to allow for translations.
Expand All @@ -191,4 +197,5 @@ index a6f2e524..8c5b7f29 100644
}.to_pretty_json
%>
--
2.25.1
2.41.0

0 comments on commit b935c2b

Please sign in to comment.