Skip to content

Commit

Permalink
Revert "use WEB_CREATOR when po_token with WEB_EMBED as a fallback (i…
Browse files Browse the repository at this point in the history
…v-org#4928)"

This reverts commit d9df90b.
  • Loading branch information
mooleshacat committed Oct 15, 2024
1 parent 70e4eb7 commit 07fe50b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
25 changes: 7 additions & 18 deletions src/invidious/videos/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ 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)
Expand Down Expand Up @@ -106,13 +102,6 @@ def extract_video_info(video_id : String)

new_player_response = nil

# Second try in case WEB_CREATOR doesn't work with po_token.
# Only trigger if reason found and po_token configured.
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?
Expand All @@ -125,9 +114,10 @@ def extract_video_info(video_id : String)
end

# Last hope
# 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?
# 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?
client_config.client_type = YoutubeAPI::ClientType::TvHtml5ScreenEmbed
new_player_response = try_fetch_streaming_data(video_id, client_config)
end
Expand Down Expand Up @@ -206,11 +196,10 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
end

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

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

# Basic video infos

Expand Down Expand Up @@ -247,7 +236,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

Expand Down
12 changes: 1 addition & 11 deletions src/invidious/yt_backend/youtube_api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module YoutubeAPI
WebEmbeddedPlayer
WebMobile
WebScreenEmbed
WebCreator

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

# Android

Expand Down Expand Up @@ -300,9 +291,8 @@ 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.google.com/",
"embedUrl" => "https://www.youtube.com/embed/#{video_id}",
} of String => String | Int64
end

Expand Down

0 comments on commit 07fe50b

Please sign in to comment.