diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2022-12-01 23:01:31 +0100 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2022-12-22 16:13:34 +0100 |
| commit | 5d6abd5301b14c24475bf7ad477a43c60ff78993 (patch) | |
| tree | 47f17157409a1907bb5274ca1fc3b5928c727ea0 | |
| parent | 52ef89f02d0ab29fd0f218abc4051328b3d96809 (diff) | |
| download | invidious-5d6abd5301b14c24475bf7ad477a43c60ff78993.tar.gz invidious-5d6abd5301b14c24475bf7ad477a43c60ff78993.tar.bz2 invidious-5d6abd5301b14c24475bf7ad477a43c60ff78993.zip | |
extractors: Fix ReelItemRendererParser
| -rw-r--r-- | src/invidious/yt_backend/extractors.cr | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index baf52118..bca0dcbd 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -382,7 +382,9 @@ private module Parsers end private def self.parse(item_contents, author_fallback) - return VideoRendererParser.process(item_contents, author_fallback) + child = VideoRendererParser.process(item_contents, author_fallback) + child ||= ReelItemRendererParser.process(item_contents, author_fallback) + return child end def self.parser_name @@ -406,12 +408,18 @@ private module Parsers private def self.parse(item_contents, author_fallback) video_id = item_contents["videoId"].as_s - video_details_container = item_contents.dig( - "navigationEndpoint", "reelWatchEndpoint", - "overlay", "reelPlayerOverlayRenderer", - "reelPlayerHeaderSupportedRenderers", - "reelPlayerHeaderRenderer" - ) + begin + video_details_container = item_contents.dig( + "navigationEndpoint", "reelWatchEndpoint", + "overlay", "reelPlayerOverlayRenderer", + "reelPlayerHeaderSupportedRenderers", + "reelPlayerHeaderRenderer" + ) + rescue ex : KeyError + # Extract key name from original message + key = /"([^"]+)"/.match(ex.message || "").try &.[1]? + raise BrokenTubeException.new(key || "reelPlayerOverlayRenderer") + end # Author infos @@ -434,9 +442,9 @@ private module Parsers # View count - view_count_text = video_details_container.dig?("viewCountText", "simpleText") - view_count_text ||= video_details_container - .dig?("viewCountText", "accessibility", "accessibilityData", "label") + # View count used to be in the reelWatchEndpoint, but that changed? + 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 @@ -448,8 +456,8 @@ private module Parsers regex_match = /- (?<min>\d+ minutes? )?(?<sec>\d+ seconds?)+ -/.match(a11y_data) - minutes = regex_match.try &.["min"].to_i(strict: false) || 0 - seconds = regex_match.try &.["sec"].to_i(strict: false) || 0 + minutes = regex_match.try &.["min"]?.try &.to_i(strict: false) || 0 + seconds = regex_match.try &.["sec"]?.try &.to_i(strict: false) || 0 duration = (minutes*60 + seconds) |
