Skip to content

Commit f7810ba

Browse files
committed
Use ProblematicTimelineItem as needed in playlists
1 parent c288005 commit f7810ba

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

src/invidious/helpers/serialized_yt_data.cr

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,32 @@ struct ProblematicTimelineItem
309309
json.field "errorBacktrace", @parse_exception.inspect_with_backtrace
310310
end
311311
end
312+
313+
# Provides compatibility with PlaylistVideo
314+
def to_json(json : JSON::Builder, *args, **kwargs)
315+
return to_json("", json)
316+
end
317+
318+
def to_xml(env, locale, xml : XML::Builder)
319+
xml.element("entry") do
320+
xml.element("id") { xml.text "iv-err-#{Random.new.base64(8)}" }
321+
xml.element("title") { xml.text "Parse Error: This item has failed to parse" }
322+
xml.element("updated") { xml.text Time.utc.to_rfc3339 }
323+
324+
xml.element("content", type: "xhtml") do
325+
xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do
326+
xml.element("div") do
327+
xml.element("h4") { translate(locale, "timeline_parse_error_placeholder_heading") }
328+
xml.element("p") { translate(locale, "timeline_parse_error_placeholder_message") }
329+
end
330+
331+
xml.element("pre") do
332+
get_issue_template(env, @parse_exception)
333+
end
334+
end
335+
end
336+
end
337+
end
312338
end
313339

314340
class Category

src/invidious/playlists.cr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def get_playlist_videos(playlist : InvidiousPlaylist | Playlist, offset : Int32,
432432
offset = initial_data.dig?("contents", "twoColumnWatchNextResults", "playlist", "playlist", "currentIndex").try &.as_i || offset
433433
end
434434

435-
videos = [] of PlaylistVideo
435+
videos = [] of PlaylistVideo | ProblematicTimelineItem
436436

437437
until videos.size >= 200 || videos.size == playlist.video_count || offset >= playlist.video_count
438438
# 100 videos per request
@@ -448,7 +448,7 @@ def get_playlist_videos(playlist : InvidiousPlaylist | Playlist, offset : Int32,
448448
end
449449

450450
def extract_playlist_videos(initial_data : Hash(String, JSON::Any))
451-
videos = [] of PlaylistVideo
451+
videos = [] of PlaylistVideo | ProblematicTimelineItem
452452

453453
if initial_data["contents"]?
454454
tabs = initial_data["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]
@@ -500,6 +500,10 @@ def extract_playlist_videos(initial_data : Hash(String, JSON::Any))
500500
index: index,
501501
})
502502
end
503+
rescue ex
504+
videos << ProblematicTimelineItem.new(
505+
parse_exception: ex
506+
)
503507
end
504508

505509
return videos

src/invidious/routes/embed.cr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ module Invidious::Routes::Embed
1212
url = "/playlist?list=#{plid}"
1313
raise NotFoundException.new(translate(locale, "error_video_not_in_playlist", url))
1414
end
15+
16+
get_first_video = videos[0].as(PlaylistVideo)
1517
rescue ex : NotFoundException
1618
return error_template(404, ex)
1719
rescue ex
1820
return error_template(500, ex)
1921
end
2022

21-
url = "/embed/#{videos[0].id}?#{env.params.query}"
23+
url = "/embed/#{get_first_video}?#{env.params.query}"
2224

2325
if env.params.query.size > 0
2426
url += "?#{env.params.query}"
@@ -72,13 +74,15 @@ module Invidious::Routes::Embed
7274
url = "/playlist?list=#{plid}"
7375
raise NotFoundException.new(translate(locale, "error_video_not_in_playlist", url))
7476
end
77+
78+
get_first_video = videos[0].as(PlaylistVideo)
7579
rescue ex : NotFoundException
7680
return error_template(404, ex)
7781
rescue ex
7882
return error_template(500, ex)
7983
end
8084

81-
url = "/embed/#{videos[0].id}"
85+
url = "/embed/#{get_first_video.id}"
8286
elsif video_series
8387
url = "/embed/#{video_series.shift}"
8488
env.params.query["playlist"] = video_series.join(",")

src/invidious/routes/feeds.cr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,13 @@ module Invidious::Routes::Feeds
296296
xml.element("name") { xml.text playlist.author }
297297
end
298298

299-
videos.each &.to_xml(xml)
299+
videos.each do |video|
300+
if video.is_a? PlaylistVideo
301+
video.to_xml(xml)
302+
else
303+
video.to_xml(env, locale, xml)
304+
end
305+
end
300306
end
301307
end
302308
else

0 commit comments

Comments
 (0)