From 57754d69e132a60a81122ea22559feec5a329bf8 Mon Sep 17 00:00:00 2001 From: syeopite Date: Thu, 7 Oct 2021 02:52:48 -0700 Subject: [PATCH] Don't use extract_text for video length extraction The extract_text function attempts to extract from both the simpleText and the runs route. This is typically what we'd want for text extraction as it could appear in both locations. However, while this still holds true, the thumbnailOverlayTimeStatusRenderer writes a numerical length (when present on the video) to the simpleText route and uses runs for a text overlay like "LIVE" or "PREMIERE". Therefore, when a video has a text overlay instead of a numerical one, Invidious still passes it onto decode_length_seconds, which obviously raises since it cannot be converted into integers. In the future, if more routes requires one text route over the other, we should go ahead and add an argument to extract_text itself. Though for now, this is sufficient. --- src/invidious/helpers/extractors.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/invidious/helpers/extractors.cr b/src/invidious/helpers/extractors.cr index e29dbdf5..acaa4800 100644 --- a/src/invidious/helpers/extractors.cr +++ b/src/invidious/helpers/extractors.cr @@ -76,10 +76,10 @@ private module Parsers elsif length_container = item_contents["thumbnailOverlays"]?.try &.as_a.find(&.["thumbnailOverlayTimeStatusRenderer"]?) # This needs to only go down the `simpleText` path (if possible). If more situations came up that requires # a specific pathway then we should add an argument to extract_text that'll make this possible - length_seconds = extract_text(length_container["thumbnailOverlayTimeStatusRenderer"]["text"]) + length_seconds = length_container.dig?("thumbnailOverlayTimeStatusRenderer", "text", "simpleText") - if length_seconds && length_seconds != "LIVE" - length_seconds = decode_length_seconds(length_seconds) + if length_seconds + length_seconds = decode_length_seconds(length_seconds.as_s) else length_seconds = 0 end