mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-06-28 09:58:25 +00:00
fix: handle microformat as nil if is not present on innertube response.
Videos that return CONTENT_CHECK_REQUIRED do not include the microformat JSON object literal on them. I think it's better to handle microformat as nil instead of raising if microformat is not present.
This commit is contained in:
parent
24e66231df
commit
fda823593e
@ -200,7 +200,6 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
|||||||
microformat = player_response.dig?("microformat", "playerMicroformatRenderer")
|
microformat = player_response.dig?("microformat", "playerMicroformatRenderer")
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -216,13 +215,13 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
|||||||
views_txt ||= video_details["viewCount"]?.try &.as_s || ""
|
views_txt ||= video_details["viewCount"]?.try &.as_s || ""
|
||||||
views = views_txt.gsub(/\D/, "").to_i64?
|
views = views_txt.gsub(/\D/, "").to_i64?
|
||||||
|
|
||||||
length_txt = (microformat["lengthSeconds"]? || video_details["lengthSeconds"])
|
length_txt = (microformat.try &.["lengthSeconds"]? || video_details["lengthSeconds"])
|
||||||
.try &.as_s.to_i64
|
.try &.as_s.to_i64
|
||||||
|
|
||||||
published = microformat["publishDate"]?
|
published = microformat.try &.["publishDate"]?
|
||||||
.try { |t| Time.parse(t.as_s, "%Y-%m-%d", Time::Location::UTC) } || Time.utc
|
.try { |t| Time.parse(t.as_s, "%Y-%m-%d", Time::Location::UTC) } || Time.utc
|
||||||
|
|
||||||
premiere_timestamp = microformat.dig?("liveBroadcastDetails", "startTimestamp")
|
premiere_timestamp = microformat.try &.dig?("liveBroadcastDetails", "startTimestamp")
|
||||||
.try { |t| Time.parse_rfc3339(t.as_s) }
|
.try { |t| Time.parse_rfc3339(t.as_s) }
|
||||||
|
|
||||||
premiere_timestamp ||= player_response.dig?(
|
premiere_timestamp ||= player_response.dig?(
|
||||||
@ -233,7 +232,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
|||||||
.try &.as_s.to_i64
|
.try &.as_s.to_i64
|
||||||
.try { |t| Time.unix(t) }
|
.try { |t| Time.unix(t) }
|
||||||
|
|
||||||
live_now = microformat.dig?("liveBroadcastDetails", "isLiveNow")
|
live_now = microformat.try &.dig?("liveBroadcastDetails", "isLiveNow")
|
||||||
.try &.as_bool
|
.try &.as_bool
|
||||||
live_now ||= video_details.dig?("isLive").try &.as_bool || false
|
live_now ||= video_details.dig?("isLive").try &.as_bool || false
|
||||||
|
|
||||||
@ -242,11 +241,11 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
|||||||
|
|
||||||
# Extra video infos
|
# Extra video infos
|
||||||
|
|
||||||
allowed_regions = microformat["availableCountries"]?
|
allowed_regions = microformat.try &.["availableCountries"]?
|
||||||
.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.try &.["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
|
||||||
|
|
||||||
@ -329,7 +328,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
|||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
|
||||||
description = microformat.dig?("description", "simpleText").try &.as_s || ""
|
description = microformat.try &.dig?("description", "simpleText").try &.as_s || ""
|
||||||
short_description = player_response.dig?("videoDetails", "shortDescription")
|
short_description = player_response.dig?("videoDetails", "shortDescription")
|
||||||
|
|
||||||
# description_html = video_secondary_renderer.try &.dig?("description", "runs")
|
# description_html = video_secondary_renderer.try &.dig?("description", "runs")
|
||||||
@ -343,7 +342,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
|
|||||||
.try &.dig?("metadataRowContainer", "metadataRowContainerRenderer", "rows")
|
.try &.dig?("metadataRowContainer", "metadataRowContainerRenderer", "rows")
|
||||||
.try &.as_a
|
.try &.as_a
|
||||||
|
|
||||||
genre = microformat["category"]?
|
genre = microformat.try &.["category"]?
|
||||||
genre_ucid = nil
|
genre_ucid = nil
|
||||||
license = nil
|
license = nil
|
||||||
|
|
||||||
|
@ -207,13 +207,15 @@ we're going to need to do it here in order to allow for translations.
|
|||||||
<p id="views"><i class="icon ion-ios-eye"></i> <%= number_with_separator(video.views) %></p>
|
<p id="views"><i class="icon ion-ios-eye"></i> <%= number_with_separator(video.views) %></p>
|
||||||
<p id="likes"><i class="icon ion-ios-thumbs-up"></i> <%= number_with_separator(video.likes) %></p>
|
<p id="likes"><i class="icon ion-ios-thumbs-up"></i> <%= number_with_separator(video.likes) %></p>
|
||||||
<p id="dislikes" style="display: none; visibility: hidden;"></p>
|
<p id="dislikes" style="display: none; visibility: hidden;"></p>
|
||||||
<p id="genre"><%= translate(locale, "Genre: ") %>
|
<% if !video.genre.nil? && !video.genre.empty? %>
|
||||||
<% if !video.genre_url %>
|
<p id="genre"><%= translate(locale, "Genre: ") %>
|
||||||
<%= video.genre %>
|
<% if !video.genre_url %>
|
||||||
<% else %>
|
<%= video.genre %>
|
||||||
<a href="<%= video.genre_url %>"><%= video.genre %></a>
|
<% else %>
|
||||||
<% end %>
|
<a href="<%= video.genre_url %>"><%= video.genre %></a>
|
||||||
</p>
|
<% end %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
<% if video.license %>
|
<% if video.license %>
|
||||||
<% if video.license.empty? %>
|
<% if video.license.empty? %>
|
||||||
<p id="license"><%= translate(locale, "License: ") %><%= translate(locale, "Standard YouTube license") %></p>
|
<p id="license"><%= translate(locale, "License: ") %><%= translate(locale, "Standard YouTube license") %></p>
|
||||||
@ -225,14 +227,16 @@ we're going to need to do it here in order to allow for translations.
|
|||||||
<p id="wilson" style="display: none; visibility: hidden;"></p>
|
<p id="wilson" style="display: none; visibility: hidden;"></p>
|
||||||
<p id="rating" style="display: none; visibility: hidden;"></p>
|
<p id="rating" style="display: none; visibility: hidden;"></p>
|
||||||
<p id="engagement" style="display: none; visibility: hidden;"></p>
|
<p id="engagement" style="display: none; visibility: hidden;"></p>
|
||||||
<% if video.allowed_regions.size != REGIONS.size %>
|
<% if !video.allowed_regions.nil? && !video.allowed_regions.empty? %>
|
||||||
<p id="allowed_regions">
|
<% if video.allowed_regions.size != REGIONS.size %>
|
||||||
<% if video.allowed_regions.size < REGIONS.size // 2 %>
|
<p id="allowed_regions">
|
||||||
<%= translate(locale, "Whitelisted regions: ") %><%= video.allowed_regions.join(", ") %>
|
<% if video.allowed_regions.size < REGIONS.size // 2 %>
|
||||||
<% else %>
|
<%= translate(locale, "Whitelisted regions: ") %><%= video.allowed_regions.join(", ") %>
|
||||||
<%= translate(locale, "Blacklisted regions: ") %><%= (REGIONS.to_a - video.allowed_regions).join(", ") %>
|
<% else %>
|
||||||
<% end %>
|
<%= translate(locale, "Blacklisted regions: ") %><%= (REGIONS.to_a - video.allowed_regions).join(", ") %>
|
||||||
</p>
|
<% end %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user