From 7f2ec183721c55ea5718119e76c3fc6ce6cd72bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milien=20Devos?= Date: Tue, 9 Aug 2022 10:05:13 +0200 Subject: [PATCH 1/4] Add param 8AEB for getting youtube stories --- src/invidious/videos.cr | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index f87c6b47..e9526c18 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -893,7 +893,8 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_ end # Fetch data from the player endpoint - player_response = YoutubeAPI.player(video_id: video_id, params: "", client_config: client_config) + # 8AEB param for fetching YouTube stories + player_response = YoutubeAPI.player(video_id: video_id, params: "8AEB", client_config: client_config) playability_status = player_response.dig?("playabilityStatus", "status").try &.as_s @@ -931,7 +932,8 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_ else client_config.client_type = YoutubeAPI::ClientType::Android end - android_player = YoutubeAPI.player(video_id: video_id, params: "", client_config: client_config) + # 8AEB param for fetching YouTube stories + android_player = YoutubeAPI.player(video_id: video_id, params: "8AEB", client_config: client_config) # Sometime, the video is available from the web client, but not on Android, so check # that here, and fallback to the streaming data from the web client if needed. From 1bb8f2815dd3cf7ab4a0080a5355ca4c0287319f Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 17 Nov 2022 22:41:51 +0000 Subject: [PATCH 2/4] CI: Use Crystal 1.6.2 in test matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dfe3ba87..4aa334c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: - 1.3.2 - 1.4.1 - 1.5.1 - - 1.6.1 + - 1.6.2 include: - crystal: nightly stable: false From afc0ec3c30d82b5cbbb38b09d3e57cdab2be5700 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Sun, 20 Nov 2022 22:52:33 +0100 Subject: [PATCH 3/4] search: Fix short text parsing --- src/invidious/channels/about.cr | 5 +++-- src/invidious/helpers/utils.cr | 24 +++++++++++------------- src/invidious/yt_backend/extractors.cr | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/invidious/channels/about.cr b/src/invidious/channels/about.cr index f60ee7af..4c442959 100644 --- a/src/invidious/channels/about.cr +++ b/src/invidious/channels/about.cr @@ -130,8 +130,9 @@ def get_about_info(ucid, locale) : AboutChannel tabs = tabs_json.reject { |node| node["tabRenderer"]?.nil? }.map(&.["tabRenderer"]["title"].as_s.downcase) end - sub_count = initdata["header"]["c4TabbedHeaderRenderer"]?.try &.["subscriberCountText"]?.try &.["simpleText"]?.try &.as_s? - .try { |text| short_text_to_number(text.split(" ")[0]) } || 0 + sub_count = initdata + .dig?("header", "c4TabbedHeaderRenderer", "subscriberCountText", "simpleText").try &.as_s? + .try { |text| short_text_to_number(text.split(" ")[0]).to_i32 } || 0 AboutChannel.new( ucid: ucid, diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 8ae5034a..ed0cca38 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -161,21 +161,19 @@ def number_with_separator(number) number.to_s.reverse.gsub(/(\d{3})(?=\d)/, "\\1,").reverse end -def short_text_to_number(short_text : String) : Int32 - case short_text - when .ends_with? "M" - number = short_text.rstrip(" mM").to_f - number *= 1000000 - when .ends_with? "K" - number = short_text.rstrip(" kK").to_f - number *= 1000 - else - number = short_text.rstrip(" ") +def short_text_to_number(short_text : String) : Int64 + matches = /(?\d+(\.\d+)?)\s?(?[mMkKbB])?/.match(short_text) + number = matches.try &.["number"].to_f || 0.0 + + case matches.try &.["suffix"].downcase + when "k" then number *= 1_000 + when "m" then number *= 1_000_000 + when "b" then number *= 1_000_000_000 end - number = number.to_i - - return number + return number.to_i64 +rescue ex + return 0_i64 end def number_to_short_text(number) diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index 8112930d..edc722cf 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -170,7 +170,7 @@ private module Parsers # Always simpleText # TODO change default value to nil subscriber_count = item_contents.dig?("subscriberCountText", "simpleText") - .try { |s| short_text_to_number(s.as_s.split(" ")[0]) } || 0 + .try { |s| short_text_to_number(s.as_s.split(" ")[0]).to_i32 } || 0 # Auto-generated channels doesn't have videoCountText # Taken from: https://github.com/iv-org/invidious/pull/2228#discussion_r717620922 From f44506b7e032e8ed29dfc6a1c817442e4cf747f1 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Sun, 20 Nov 2022 23:48:59 +0100 Subject: [PATCH 4/4] yt api: bump web client version --- src/invidious/yt_backend/youtube_api.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index 02327025..91a9332c 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -43,7 +43,7 @@ module YoutubeAPI ClientType::Web => { name: "WEB", name_proto: "1", - version: "2.20220804.07.00", + version: "2.20221118.01.00", api_key: DEFAULT_API_KEY, screen: "WATCH_FULL_SCREEN", os_name: "Windows",