mirror of
https://gitea.invidious.io/iv-org/invidious.git
synced 2024-08-15 00:53:41 +00:00
Fix parsing shorts on channel page
This commit is contained in:
parent
8a44bd11d2
commit
5767344746
2 changed files with 35 additions and 59 deletions
|
@ -127,38 +127,15 @@ module Invidious::Channel::Tabs
|
||||||
# Shorts
|
# Shorts
|
||||||
# -------------------
|
# -------------------
|
||||||
|
|
||||||
private def fetch_shorts_data(ucid : String, continuation : String? = nil)
|
def get_shorts(channel : AboutChannel, continuation : String? = nil)
|
||||||
if continuation.nil?
|
if continuation.nil?
|
||||||
# EgZzaG9ydHPyBgUKA5oBAA%3D%3D is the protobuf object to load "shorts"
|
# EgZzaG9ydHPyBgUKA5oBAA%3D%3D is the protobuf object to load "shorts"
|
||||||
# TODO: try to extract the continuation tokens that allows other sorting options
|
# TODO: try to extract the continuation tokens that allows other sorting options
|
||||||
return YoutubeAPI.browse(ucid, params: "EgZzaG9ydHPyBgUKA5oBAA%3D%3D")
|
initial_data = YoutubeAPI.browse(channel.ucid, params: "EgZzaG9ydHPyBgUKA5oBAA%3D%3D")
|
||||||
else
|
else
|
||||||
return YoutubeAPI.browse(continuation: continuation)
|
initial_data = YoutubeAPI.browse(continuation: continuation)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_shorts(channel : AboutChannel, continuation : String? = nil)
|
|
||||||
initial_data = self.fetch_shorts_data(channel.ucid, continuation)
|
|
||||||
|
|
||||||
begin
|
|
||||||
# Try to parse the initial data fetched above
|
|
||||||
return extract_items(initial_data, channel.author, channel.ucid)
|
|
||||||
rescue ex : RetryOnceException
|
|
||||||
# Sometimes, for a completely unknown reason, the "reelItemRenderer"
|
|
||||||
# object is missing some critical information (it happens once in about
|
|
||||||
# 20 subsequent requests). Refreshing the page is required to properly
|
|
||||||
# show the "shorts" tab.
|
|
||||||
#
|
|
||||||
# In order to make the experience smoother for the user, we simulate
|
|
||||||
# said page refresh by fetching again the JSON. If that still doesn't
|
|
||||||
# work, we raise a BrokenTubeException, as something is really broken.
|
|
||||||
begin
|
|
||||||
initial_data = self.fetch_shorts_data(channel.ucid, continuation)
|
|
||||||
return extract_items(initial_data, channel.author, channel.ucid)
|
|
||||||
rescue ex : RetryOnceException
|
|
||||||
raise BrokenTubeException.new "reelPlayerHeaderSupportedRenderers"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
return extract_items(initial_data, channel.author, channel.ucid)
|
||||||
end
|
end
|
||||||
|
|
||||||
# -------------------
|
# -------------------
|
||||||
|
|
|
@ -423,42 +423,41 @@ private module Parsers
|
||||||
"overlay", "reelPlayerOverlayRenderer"
|
"overlay", "reelPlayerOverlayRenderer"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Sometimes, the "reelPlayerOverlayRenderer" object is missing the
|
if video_details_container = reel_player_overlay.dig?(
|
||||||
# important part of the response. We use this exception to tell
|
"reelPlayerHeaderSupportedRenderers",
|
||||||
# the calling function to fetch the content again.
|
"reelPlayerHeaderRenderer"
|
||||||
if !reel_player_overlay.as_h.has_key?("reelPlayerHeaderSupportedRenderers")
|
)
|
||||||
raise RetryOnceException.new
|
# Author infos
|
||||||
|
|
||||||
|
author = video_details_container
|
||||||
|
.dig?("channelTitleText", "runs", 0, "text")
|
||||||
|
.try &.as_s || author_fallback.name
|
||||||
|
|
||||||
|
ucid = video_details_container
|
||||||
|
.dig?("channelNavigationEndpoint", "browseEndpoint", "browseId")
|
||||||
|
.try &.as_s || author_fallback.id
|
||||||
|
|
||||||
|
# Title & publication date
|
||||||
|
|
||||||
|
title = video_details_container.dig?("reelTitleText")
|
||||||
|
.try { |t| extract_text(t) } || ""
|
||||||
|
|
||||||
|
published = video_details_container
|
||||||
|
.dig?("timestampText", "simpleText")
|
||||||
|
.try { |t| decode_date(t.as_s) } || Time.utc
|
||||||
|
|
||||||
|
# View count
|
||||||
|
view_count_text = video_details_container.dig?("viewCountText", "simpleText")
|
||||||
|
else
|
||||||
|
author = author_fallback.name
|
||||||
|
ucid = author_fallback.id
|
||||||
|
published = Time.utc
|
||||||
|
title = item_contents.dig?("headline", "simpleText").try &.as_s || ""
|
||||||
end
|
end
|
||||||
|
|
||||||
video_details_container = reel_player_overlay.dig(
|
|
||||||
"reelPlayerHeaderSupportedRenderers",
|
|
||||||
"reelPlayerHeaderRenderer"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Author infos
|
|
||||||
|
|
||||||
author = video_details_container
|
|
||||||
.dig?("channelTitleText", "runs", 0, "text")
|
|
||||||
.try &.as_s || author_fallback.name
|
|
||||||
|
|
||||||
ucid = video_details_container
|
|
||||||
.dig?("channelNavigationEndpoint", "browseEndpoint", "browseId")
|
|
||||||
.try &.as_s || author_fallback.id
|
|
||||||
|
|
||||||
# Title & publication date
|
|
||||||
|
|
||||||
title = video_details_container.dig?("reelTitleText")
|
|
||||||
.try { |t| extract_text(t) } || ""
|
|
||||||
|
|
||||||
published = video_details_container
|
|
||||||
.dig?("timestampText", "simpleText")
|
|
||||||
.try { |t| decode_date(t.as_s) } || Time.utc
|
|
||||||
|
|
||||||
# View count
|
# View count
|
||||||
|
|
||||||
# View count used to be in the reelWatchEndpoint, but that changed?
|
# View count used to be in the reelWatchEndpoint, but that changed?
|
||||||
view_count_text = item_contents.dig?("viewCountText", "simpleText")
|
view_count_text ||= item_contents.dig?("viewCountText", "simpleText")
|
||||||
view_count_text ||= video_details_container.dig?("viewCountText", "simpleText")
|
|
||||||
|
|
||||||
view_count = view_count_text.try &.as_s.gsub(/\D+/, "").to_i64? || 0_i64
|
view_count = view_count_text.try &.as_s.gsub(/\D+/, "").to_i64? || 0_i64
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue