Skip to content

Commit

Permalink
Merge pull request iv-org#4423 from tleydxdy/xml-namespace
Browse files Browse the repository at this point in the history
Fix pubsub feed parsing
  • Loading branch information
unixfox authored Feb 12, 2024
2 parents c005ada + 98c421e commit cf68620
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/invidious/routes/feeds.cr
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,23 @@ module Invidious::Routes::Feeds
end

spawn do
rss = XML.parse_html(body)
rss.xpath_nodes("//feed/entry").each do |entry|
id = entry.xpath_node("videoid").not_nil!.content
author = entry.xpath_node("author/name").not_nil!.content
published = Time.parse_rfc3339(entry.xpath_node("published").not_nil!.content)
updated = Time.parse_rfc3339(entry.xpath_node("updated").not_nil!.content)

video = get_video(id, force_refresh: true)
# TODO: unify this with the other almost identical looking parts in this and channels.cr somehow?
namespaces = {
"yt" => "http://www.youtube.com/xml/schemas/2015",
"default" => "http://www.w3.org/2005/Atom",
}
rss = XML.parse(body)
rss.xpath_nodes("//default:feed/default:entry", namespaces).each do |entry|
id = entry.xpath_node("yt:videoId", namespaces).not_nil!.content
author = entry.xpath_node("default:author/default:name", namespaces).not_nil!.content
published = Time.parse_rfc3339(entry.xpath_node("default:published", namespaces).not_nil!.content)
updated = Time.parse_rfc3339(entry.xpath_node("default:updated", namespaces).not_nil!.content)

begin
video = get_video(id, force_refresh: true)
rescue
next # skip this video since it raised an exception (e.g. it is a scheduled live event)
end

if CONFIG.enable_user_notifications
# Deliver notifications to `/api/v1/auth/notifications`
Expand Down

0 comments on commit cf68620

Please sign in to comment.