Invidious is an alternative front-end to YouTube
Use ProblematicTimelineItem as needed in playlists
syeopitef7810ba007d0
diff --git a/src/invidious/helpers/serialized_yt_data.cr b/src/invidious/helpers/serialized_yt_data.crindex 5eef2359..56b64dbf 100644--- a/src/invidious/helpers/serialized_yt_data.cr+++ b/src/invidious/helpers/serialized_yt_data.cr@@ -309,6 +309,32 @@ struct ProblematicTimelineItemjson.field "errorBacktrace", @parse_exception.inspect_with_backtraceendend++ # Provides compatibility with PlaylistVideo+ def to_json(json : JSON::Builder, *args, **kwargs)+ return to_json("", json)+ end++ def to_xml(env, locale, xml : XML::Builder)+ xml.element("entry") do+ xml.element("id") { xml.text "iv-err-#{Random.new.base64(8)}" }+ xml.element("title") { xml.text "Parse Error: This item has failed to parse" }+ xml.element("updated") { xml.text Time.utc.to_rfc3339 }++ xml.element("content", type: "xhtml") do+ xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do+ xml.element("div") do+ xml.element("h4") { translate(locale, "timeline_parse_error_placeholder_heading") }+ xml.element("p") { translate(locale, "timeline_parse_error_placeholder_message") }+ end++ xml.element("pre") do+ get_issue_template(env, @parse_exception)+ end+ end+ end+ end+ endendclass Categorydiff --git a/src/invidious/playlists.cr b/src/invidious/playlists.crindex b670c009..c762b64b 100644--- a/src/invidious/playlists.cr+++ b/src/invidious/playlists.cr@@ -432,7 +432,7 @@ def get_playlist_videos(playlist : InvidiousPlaylist | Playlist, offset : Int32,offset = initial_data.dig?("contents", "twoColumnWatchNextResults", "playlist", "playlist", "currentIndex").try &.as_i || offsetend- videos = [] of PlaylistVideo+ videos = [] of PlaylistVideo | ProblematicTimelineItemuntil videos.size >= 200 || videos.size == playlist.video_count || offset >= playlist.video_count# 100 videos per request@@ -448,7 +448,7 @@ def get_playlist_videos(playlist : InvidiousPlaylist | Playlist, offset : Int32,enddef extract_playlist_videos(initial_data : Hash(String, JSON::Any))- videos = [] of PlaylistVideo+ videos = [] of PlaylistVideo | ProblematicTimelineItemif initial_data["contents"]?tabs = initial_data["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]@@ -500,6 +500,10 @@ def extract_playlist_videos(initial_data : Hash(String, JSON::Any))index: index,})end+ rescue ex+ videos << ProblematicTimelineItem.new(+ parse_exception: ex+ )endreturn videosdiff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.crindex bdbb2d89..b7ae4e0e 100644--- a/src/invidious/routes/embed.cr+++ b/src/invidious/routes/embed.cr@@ -12,13 +12,15 @@ module Invidious::Routes::Embedurl = "/playlist?list=#{plid}"raise NotFoundException.new(translate(locale, "error_video_not_in_playlist", url))end++ get_first_video = videos[0].as(PlaylistVideo)rescue ex : NotFoundExceptionreturn error_template(404, ex)rescue exreturn error_template(500, ex)end- url = "/embed/#{videos[0].id}?#{env.params.query}"+ url = "/embed/#{get_first_video}?#{env.params.query}"if env.params.query.size > 0url += "?#{env.params.query}"@@ -72,13 +74,15 @@ module Invidious::Routes::Embedurl = "/playlist?list=#{plid}"raise NotFoundException.new(translate(locale, "error_video_not_in_playlist", url))end++ get_first_video = videos[0].as(PlaylistVideo)rescue ex : NotFoundExceptionreturn error_template(404, ex)rescue exreturn error_template(500, ex)end- url = "/embed/#{videos[0].id}"+ url = "/embed/#{get_first_video.id}"elsif video_seriesurl = "/embed/#{video_series.shift}"env.params.query["playlist"] = video_series.join(",")diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.crindex 7f9a0edb..abfea9ee 100644--- a/src/invidious/routes/feeds.cr+++ b/src/invidious/routes/feeds.cr@@ -296,7 +296,13 @@ module Invidious::Routes::Feedsxml.element("name") { xml.text playlist.author }end- videos.each &.to_xml(xml)+ videos.each do |video|+ if video.is_a? PlaylistVideo+ video.to_xml(xml)+ else+ video.to_xml(env, locale, xml)+ end+ endendendelse