Compare commits

...

9 Commits

Author SHA1 Message Date
ChunkyProgrammer
91ef0ec56a
Merge 2d1437f6ff into 53e8a5d62d 2024-10-01 02:03:19 +00:00
ChunkyProgrammer
2d1437f6ff Use a find instead of an each loop 2024-09-30 22:03:13 -04:00
ChunkyProgrammer
7b6b914c7b Put temp.delete inside ensure block 2024-09-30 22:03:13 -04:00
ChunkyProgrammer
aee7a52b1f Ensure IO is properly closed when importing NewPipe subscriptions 2024-09-30 22:03:13 -04:00
TheFrenchGhosty
53e8a5d62d
Remove myself from CODEOWNERS on the config file (#4942) 2024-09-28 23:54:52 +02:00
Émilien (perso)
a021b93063
Update latest version WEB_CREATOR + fix comment web embed (#4930)
* Update to latest version WEB_CREATOR

* fix comment about using web embed as a fallback
2024-09-20 00:05:41 +00:00
Émilien (perso)
d9df90b5e3
use WEB_CREATOR when po_token with WEB_EMBED as a fallback (#4928)
* use WEB_CREATOR when po_token with WEB_EMBEDDED_PLAYER as a fallback

* remove unrelated comment

Co-authored-by: syeopite <70992037+syeopite@users.noreply.github.com>

---------

Co-authored-by: syeopite <70992037+syeopite@users.noreply.github.com>
2024-09-20 00:19:13 +02:00
Emilien Devos
cec3cfba77 Revert "use web screen embed for fixing potoken functionality (#4923)"
This reverts commit de918b9234.
The code doesn't work as expected. Reverting
2024-09-17 00:22:06 +02:00
Émilien (perso)
de918b9234
use web screen embed for fixing potoken functionality (#4923)
* use web screen embed for fixing potoken functionality

* use web screen embed only for getting streamingData + disable tv screen on po_token
2024-09-16 23:42:43 +02:00
4 changed files with 58 additions and 40 deletions

2
.github/CODEOWNERS vendored
View File

@ -6,7 +6,7 @@ docker/ @unixfox
kubernetes/ @unixfox kubernetes/ @unixfox
README.md @thefrenchghosty README.md @thefrenchghosty
config/config.example.yml @thefrenchghosty @SamantazFox @unixfox config/config.example.yml @SamantazFox @unixfox
scripts/ @syeopite scripts/ @syeopite
shards.lock @syeopite shards.lock @syeopite

View File

@ -290,26 +290,22 @@ struct Invidious::User
end end
def from_newpipe(user : User, body : String) : Bool def from_newpipe(user : User, body : String) : Bool
io = IO::Memory.new(body) Compress::Zip::File.open(IO::Memory.new(body), true) do |file|
entry = file.entries.find { |file_entry| file_entry.filename == "newpipe.db" }
Compress::Zip::File.open(io) do |file| return false if entry.nil?
file.entries.each do |entry|
entry.open do |file_io| entry.open do |file_io|
# Ensure max size of 4MB # Ensure max size of 4MB
io_sized = IO::Sized.new(file_io, 0x400000) io_sized = IO::Sized.new(file_io, 0x400000)
next if entry.filename != "newpipe.db" begin
temp = File.tempfile(".db") do |tempfile|
tempfile = File.tempfile(".db")
begin begin
File.write(tempfile.path, io_sized.gets_to_end) File.write(tempfile.path, io_sized.gets_to_end)
rescue rescue
return false return false
end end
db = DB.open("sqlite3://" + tempfile.path) DB.open("sqlite3://" + tempfile.path) do |db|
user.watched += db.query_all("SELECT url FROM streams", as: String) user.watched += db.query_all("SELECT url FROM streams", as: String)
.map(&.lchop("https://www.youtube.com/watch?v=")) .map(&.lchop("https://www.youtube.com/watch?v="))
@ -323,9 +319,10 @@ struct Invidious::User
user.subscriptions = get_batch_channels(user.subscriptions) user.subscriptions = get_batch_channels(user.subscriptions)
Invidious::Database::Users.update_subscriptions(user) Invidious::Database::Users.update_subscriptions(user)
end
db.close end
tempfile.delete ensure
temp.delete if !temp.nil?
end end
end end
end end

View File

@ -53,6 +53,10 @@ end
def extract_video_info(video_id : String) def extract_video_info(video_id : String)
# Init client config for the API # Init client config for the API
client_config = YoutubeAPI::ClientConfig.new 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 # Fetch data from the player endpoint
player_response = YoutubeAPI.player(video_id: video_id, params: "2AMB", client_config: client_config) player_response = YoutubeAPI.player(video_id: video_id, params: "2AMB", client_config: client_config)
@ -102,6 +106,13 @@ def extract_video_info(video_id : String)
new_player_response = nil 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 # Don't use Android client if po_token is passed because po_token doesn't
# work for Android client. # work for Android client.
if reason.nil? && CONFIG.po_token.nil? if reason.nil? && CONFIG.po_token.nil?
@ -114,10 +125,9 @@ def extract_video_info(video_id : String)
end end
# Last hope # Last hope
# Only trigger if reason found and po_token or didn't work wth Android client. # Only trigger if reason found or didn't work wth Android client.
# TvHtml5ScreenEmbed now requires sig helper for it to work but po_token is not required # TvHtml5ScreenEmbed now requires sig helper for it to work but doesn't work with po_token.
# if the IP address is not blocked. if reason && CONFIG.po_token.nil?
if CONFIG.po_token && reason || CONFIG.po_token.nil? && new_player_response.nil?
client_config.client_type = YoutubeAPI::ClientType::TvHtml5ScreenEmbed client_config.client_type = YoutubeAPI::ClientType::TvHtml5ScreenEmbed
new_player_response = try_fetch_streaming_data(video_id, client_config) new_player_response = try_fetch_streaming_data(video_id, client_config)
end end
@ -185,10 +195,11 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
end end
video_details = player_response.dig?("videoDetails") 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("videoDetails") if !video_details
raise BrokenTubeException.new("microformat") if !microformat
# Basic video infos # Basic video infos
@ -225,7 +236,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
.try &.as_a.map &.as_s || [] of String .try &.as_a.map &.as_s || [] of String
allow_ratings = video_details["allowRatings"]?.try &.as_bool 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_listed = video_details["isCrawlable"]?.try &.as_bool
is_upcoming = video_details["isUpcoming"]?.try &.as_bool is_upcoming = video_details["isUpcoming"]?.try &.as_bool

View File

@ -29,6 +29,7 @@ module YoutubeAPI
WebEmbeddedPlayer WebEmbeddedPlayer
WebMobile WebMobile
WebScreenEmbed WebScreenEmbed
WebCreator
Android Android
AndroidEmbeddedPlayer AndroidEmbeddedPlayer
@ -80,6 +81,14 @@ module YoutubeAPI
os_version: WINDOWS_VERSION, os_version: WINDOWS_VERSION,
platform: "DESKTOP", 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 # Android
@ -291,8 +300,9 @@ module YoutubeAPI
end end
if client_config.screen == "EMBED" if client_config.screen == "EMBED"
# embedUrl https://www.google.com allow loading almost all video that are configured not embeddable
client_context["thirdParty"] = { client_context["thirdParty"] = {
"embedUrl" => "https://www.youtube.com/embed/#{video_id}", "embedUrl" => "https://www.google.com/",
} of String => String | Int64 } of String => String | Int64
end end