Merge branch 'iv-org:master' into DCCXX-view-as-playlist

This commit is contained in:
DCCXX 2022-11-21 21:44:07 +01:00 committed by GitHub
commit d8259a4992
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 20 deletions

View file

@ -41,7 +41,7 @@ jobs:
- 1.3.2 - 1.3.2
- 1.4.1 - 1.4.1
- 1.5.1 - 1.5.1
- 1.6.1 - 1.6.2
include: include:
- crystal: nightly - crystal: nightly
stable: false stable: false

View file

@ -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) tabs = tabs_json.reject { |node| node["tabRenderer"]?.nil? }.map(&.["tabRenderer"]["title"].as_s.downcase)
end end
sub_count = initdata["header"]["c4TabbedHeaderRenderer"]?.try &.["subscriberCountText"]?.try &.["simpleText"]?.try &.as_s? sub_count = initdata
.try { |text| short_text_to_number(text.split(" ")[0]) } || 0 .dig?("header", "c4TabbedHeaderRenderer", "subscriberCountText", "simpleText").try &.as_s?
.try { |text| short_text_to_number(text.split(" ")[0]).to_i32 } || 0
AboutChannel.new( AboutChannel.new(
ucid: ucid, ucid: ucid,

View file

@ -161,21 +161,19 @@ def number_with_separator(number)
number.to_s.reverse.gsub(/(\d{3})(?=\d)/, "\\1,").reverse number.to_s.reverse.gsub(/(\d{3})(?=\d)/, "\\1,").reverse
end end
def short_text_to_number(short_text : String) : Int32 def short_text_to_number(short_text : String) : Int64
case short_text matches = /(?<number>\d+(\.\d+)?)\s?(?<suffix>[mMkKbB])?/.match(short_text)
when .ends_with? "M" number = matches.try &.["number"].to_f || 0.0
number = short_text.rstrip(" mM").to_f
number *= 1000000 case matches.try &.["suffix"].downcase
when .ends_with? "K" when "k" then number *= 1_000
number = short_text.rstrip(" kK").to_f when "m" then number *= 1_000_000
number *= 1000 when "b" then number *= 1_000_000_000
else
number = short_text.rstrip(" ")
end end
number = number.to_i return number.to_i64
rescue ex
return number return 0_i64
end end
def number_to_short_text(number) def number_to_short_text(number)

View file

@ -55,7 +55,8 @@ def extract_video_info(video_id : String, proxy_region : String? = nil)
client_config = YoutubeAPI::ClientConfig.new(proxy_region: proxy_region) client_config = YoutubeAPI::ClientConfig.new(proxy_region: proxy_region)
# Fetch data from the player endpoint # Fetch data from the player endpoint
player_response = YoutubeAPI.player(video_id: video_id, params: "", client_config: client_config) # 8AEB param is used to fetch 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 playability_status = player_response.dig?("playabilityStatus", "status").try &.as_s
@ -128,7 +129,8 @@ end
def try_fetch_streaming_data(id : String, client_config : YoutubeAPI::ClientConfig) : Hash(String, JSON::Any)? def try_fetch_streaming_data(id : String, client_config : YoutubeAPI::ClientConfig) : Hash(String, JSON::Any)?
LOGGER.debug("try_fetch_streaming_data: [#{id}] Using #{client_config.client_type} client.") LOGGER.debug("try_fetch_streaming_data: [#{id}] Using #{client_config.client_type} client.")
response = YoutubeAPI.player(video_id: id, params: "", client_config: client_config) # 8AEB param is used to fetch YouTube stories
response = YoutubeAPI.player(video_id: id, params: "8AEB", client_config: client_config)
playability_status = response["playabilityStatus"]["status"] playability_status = response["playabilityStatus"]["status"]
LOGGER.debug("try_fetch_streaming_data: [#{id}] Got playabilityStatus == #{playability_status}.") LOGGER.debug("try_fetch_streaming_data: [#{id}] Got playabilityStatus == #{playability_status}.")

View file

@ -170,7 +170,7 @@ private module Parsers
# Always simpleText # Always simpleText
# TODO change default value to nil # TODO change default value to nil
subscriber_count = item_contents.dig?("subscriberCountText", "simpleText") 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 # Auto-generated channels doesn't have videoCountText
# Taken from: https://github.com/iv-org/invidious/pull/2228#discussion_r717620922 # Taken from: https://github.com/iv-org/invidious/pull/2228#discussion_r717620922

View file

@ -43,7 +43,7 @@ module YoutubeAPI
ClientType::Web => { ClientType::Web => {
name: "WEB", name: "WEB",
name_proto: "1", name_proto: "1",
version: "2.20220804.07.00", version: "2.20221118.01.00",
api_key: DEFAULT_API_KEY, api_key: DEFAULT_API_KEY,
screen: "WATCH_FULL_SCREEN", screen: "WATCH_FULL_SCREEN",
os_name: "Windows", os_name: "Windows",