Skip to content

Commit

Permalink
update enforce playback + add patch PR 4928
Browse files Browse the repository at this point in the history
  • Loading branch information
unixfox committed Sep 19, 2024
1 parent 5cfc28a commit 545e755
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 12 deletions.
24 changes: 12 additions & 12 deletions patches/009-restrict-playback.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 91908d4b3ff25cca88d56f21f6e5efdd3d83282e Mon Sep 17 00:00:00 2001
From e2f4770db8669a7ebf7165e0ca3a0054578bdca5 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 Down Expand Up @@ -33,10 +33,10 @@ index 35ffa96e..412a9f7b 100644
'&continuation=' + continuation;

diff --git a/assets/js/player.js b/assets/js/player.js
index bb53ac24..43bd902f 100644
index d32062c6..6e9eabcb 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') {
@@ -423,7 +423,7 @@ if (!video_data.params.listen && video_data.params.quality === 'dash') {
}

player.vttThumbnails({
Expand All @@ -45,7 +45,7 @@ index bb53ac24..43bd902f 100644
showTimestamp: true
});

@@ -398,7 +398,7 @@ if (!video_data.params.listen && video_data.params.annotations) {
@@ -449,7 +449,7 @@ if (!video_data.params.listen && video_data.params.annotations) {
}
});

Expand All @@ -67,10 +67,10 @@ index 26ad138f..0242f31b 100644

var onNon200 = function (xhr) { comments.innerHTML = fallback; };
diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr
index 449c9f9b..82fc9b0f 100644
index 368304ac..76a1d8f3 100644
--- a/src/invidious/routes/api/v1/videos.cr
+++ b/src/invidious/routes/api/v1/videos.cr
@@ -27,6 +27,10 @@ module Invidious::Routes::API::V1::Videos
@@ -29,6 +29,10 @@ module Invidious::Routes::API::V1::Videos
id = env.params.url["id"]
region = env.params.query["region"]? || env.params.body["region"]?

Expand All @@ -81,7 +81,7 @@ index 449c9f9b..82fc9b0f 100644
if id.nil? || id.size != 11 || !id.matches?(/^[\w-]+$/)
return error_json(400, "Invalid video ID")
end
@@ -170,6 +174,10 @@ module Invidious::Routes::API::V1::Videos
@@ -181,6 +185,10 @@ module Invidious::Routes::API::V1::Videos
id = env.params.url["id"]
region = env.params.query["region"]?

Expand All @@ -92,7 +92,7 @@ index 449c9f9b..82fc9b0f 100644
begin
video = get_video(id, region: region)
rescue ex : NotFoundException
@@ -234,6 +242,10 @@ module Invidious::Routes::API::V1::Videos
@@ -257,6 +265,10 @@ module Invidious::Routes::API::V1::Videos
source = env.params.query["source"]?
source ||= "archive"

Expand All @@ -103,7 +103,7 @@ index 449c9f9b..82fc9b0f 100644
if !id.match(/[a-zA-Z0-9_-]{11}/)
haltf env, 400
end
@@ -303,6 +315,10 @@ module Invidious::Routes::API::V1::Videos
@@ -326,6 +338,10 @@ module Invidious::Routes::API::V1::Videos

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

Expand Down Expand Up @@ -171,17 +171,17 @@ index c3c02df0..d046c791 100644
<% end %>
</video>
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index 62a154a4..cf6d8981 100644
index 45c58a16..bc922cda 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.
"premiere_timestamp" => video.premiere_timestamp.try &.to_unix,
"vr" => video.is_vr,
"vr" => video.vr?,
"projection_type" => video.projection_type,
+ "hmac_key" => OpenSSL::HMAC.hexdigest(:sha1, HMAC_KEY, video.id),
"local_disabled" => CONFIG.disabled?("local"),
"support_reddit" => true
}.to_pretty_json
--
2.42.0
2.46.1

116 changes: 116 additions & 0 deletions patches/022-4928.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
From 4f680f9a4f53ad07c6993d5ea82d14d53a1038a9 Mon Sep 17 00:00:00 2001
From: Emilien Devos <[email protected]>
Date: Thu, 19 Sep 2024 23:24:15 +0200
Subject: [PATCH] use WEB_CREATOR when po_token with WEB_EMBEDDED_PLAYER as a
fallback

---
src/invidious/videos/parser.cr | 26 ++++++++++++++++++-------
src/invidious/yt_backend/youtube_api.cr | 12 +++++++++++-
2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr
index 95fa3d799..ea75a2279 100644
--- a/src/invidious/videos/parser.cr
+++ b/src/invidious/videos/parser.cr
@@ -53,6 +53,10 @@ end
def extract_video_info(video_id : String)
# Init client config for the API
client_config = YoutubeAPI::ClientConfig.new
+ # Use the WEB_CREATOR when po_token is configured because it fully only works on this client
+ if CONFIG.po_token
+ client_config.client_type = YoutubeAPI::ClientType::WebCreator
+ end

# Fetch data from the player endpoint
player_response = YoutubeAPI.player(video_id: video_id, params: "2AMB", client_config: client_config)
@@ -102,6 +106,14 @@ def extract_video_info(video_id : String)

new_player_response = nil

+ # Second try in case WEB_EMBEDDED_PLAYER doesn't work with po_token.
+ # Only trigger if reason found and po_token configured.
+ # TvHtml5ScreenEmbed now requires sig helper for it to work but doesn't work with po_token.
+ if reason && CONFIG.po_token
+ client_config.client_type = YoutubeAPI::ClientType::WebEmbeddedPlayer
+ new_player_response = try_fetch_streaming_data(video_id, client_config)
+ end
+
# Don't use Android client if po_token is passed because po_token doesn't
# work for Android client.
if reason.nil? && CONFIG.po_token.nil?
@@ -114,10 +126,9 @@ def extract_video_info(video_id : String)
end

# Last hope
- # Only trigger if reason found and po_token or didn't work wth Android client.
- # TvHtml5ScreenEmbed now requires sig helper for it to work but po_token is not required
- # if the IP address is not blocked.
- if CONFIG.po_token && reason || CONFIG.po_token.nil? && new_player_response.nil?
+ # Only trigger if reason found or didn't work wth Android client.
+ # TvHtml5ScreenEmbed now requires sig helper for it to work but doesn't work with po_token.
+ if reason && CONFIG.po_token.nil?
client_config.client_type = YoutubeAPI::ClientType::TvHtml5ScreenEmbed
new_player_response = try_fetch_streaming_data(video_id, client_config)
end
@@ -185,10 +196,11 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
end

video_details = player_response.dig?("videoDetails")
- microformat = player_response.dig?("microformat", "playerMicroformatRenderer")
+ if !(microformat = player_response.dig?("microformat", "playerMicroformatRenderer"))
+ microformat = {} of String => JSON::Any
+ end

raise BrokenTubeException.new("videoDetails") if !video_details
- raise BrokenTubeException.new("microformat") if !microformat

# Basic video infos

@@ -225,7 +237,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
.try &.as_a.map &.as_s || [] of String

allow_ratings = video_details["allowRatings"]?.try &.as_bool
- family_friendly = microformat["isFamilySafe"].try &.as_bool
+ family_friendly = microformat["isFamilySafe"]?.try &.as_bool
is_listed = video_details["isCrawlable"]?.try &.as_bool
is_upcoming = video_details["isUpcoming"]?.try &.as_bool

diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr
index d66bf7aa2..99ec6e63a 100644
--- a/src/invidious/yt_backend/youtube_api.cr
+++ b/src/invidious/yt_backend/youtube_api.cr
@@ -29,6 +29,7 @@ module YoutubeAPI
WebEmbeddedPlayer
WebMobile
WebScreenEmbed
+ WebCreator

Android
AndroidEmbeddedPlayer
@@ -80,6 +81,14 @@ module YoutubeAPI
os_version: WINDOWS_VERSION,
platform: "DESKTOP",
},
+ ClientType::WebCreator => {
+ name: "WEB_CREATOR",
+ name_proto: "62",
+ version: "1.20220918",
+ os_name: "Windows",
+ os_version: WINDOWS_VERSION,
+ platform: "DESKTOP",
+ },

# Android

@@ -291,8 +300,9 @@ module YoutubeAPI
end

if client_config.screen == "EMBED"
+ # embedUrl https://www.google.com allow loading almost all video that are configured not embeddable
client_context["thirdParty"] = {
- "embedUrl" => "https://www.youtube.com/embed/#{video_id}",
+ "embedUrl" => "https://www.google.com/",
} of String => String | Int64
end

0 comments on commit 545e755

Please sign in to comment.