Compare commits
5 Commits
e6f52eaf00
...
29af3f8add
Author | SHA1 | Date | |
---|---|---|---|
29af3f8add | |||
d7b01d2ab7 | |||
|
d8b893e9ad | ||
|
70e4eb7f5d | ||
|
0d03818700 |
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@ -38,10 +38,11 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
stable: [true]
|
stable: [true]
|
||||||
crystal:
|
crystal:
|
||||||
- 1.9.2
|
|
||||||
- 1.10.1
|
- 1.10.1
|
||||||
- 1.11.2
|
- 1.11.2
|
||||||
- 1.12.1
|
- 1.12.1
|
||||||
|
- 1.13.2
|
||||||
|
- 1.14.0
|
||||||
include:
|
include:
|
||||||
- crystal: nightly
|
- crystal: nightly
|
||||||
stable: false
|
stable: false
|
||||||
@ -51,6 +52,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
|
|
||||||
|
- name: Install required APT packages
|
||||||
|
run: |
|
||||||
|
sudo apt install -y libsqlite3-dev
|
||||||
|
shell: bash
|
||||||
|
|
||||||
- name: Install Crystal
|
- name: Install Crystal
|
||||||
uses: crystal-lang/install-crystal@v1.8.0
|
uses: crystal-lang/install-crystal@v1.8.0
|
||||||
with:
|
with:
|
||||||
|
@ -53,10 +53,6 @@ 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)
|
||||||
@ -106,13 +102,6 @@ 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?
|
||||||
@ -125,9 +114,10 @@ def extract_video_info(video_id : String)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Last hope
|
# Last hope
|
||||||
# Only trigger if reason found or didn't work wth Android client.
|
# 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 doesn't work with po_token.
|
# TvHtml5ScreenEmbed now requires sig helper for it to work but po_token is not required
|
||||||
if reason && CONFIG.po_token.nil?
|
# 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
|
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
|
||||||
@ -206,11 +196,10 @@ 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")
|
||||||
if !(microformat = player_response.dig?("microformat", "playerMicroformatRenderer"))
|
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
|
||||||
|
|
||||||
@ -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
|
.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
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ module YoutubeAPI
|
|||||||
WebEmbeddedPlayer
|
WebEmbeddedPlayer
|
||||||
WebMobile
|
WebMobile
|
||||||
WebScreenEmbed
|
WebScreenEmbed
|
||||||
WebCreator
|
|
||||||
|
|
||||||
Android
|
Android
|
||||||
AndroidEmbeddedPlayer
|
AndroidEmbeddedPlayer
|
||||||
@ -81,14 +80,6 @@ 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
|
||||||
|
|
||||||
@ -300,9 +291,8 @@ 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.google.com/",
|
"embedUrl" => "https://www.youtube.com/embed/#{video_id}",
|
||||||
} of String => String | Int64
|
} of String => String | Int64
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user