Skip to content

Commit

Permalink
Channel RSS: deprecate author thumbnail, make less requests to youtube
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkyProgrammer committed Oct 30, 2024
1 parent 1827203 commit b37a433
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions src/invidious/routes/feeds.cr
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,21 @@ module Invidious::Routes::Feeds
# RSS feeds

def self.rss_channel(env)
locale = env.get("preferences").as(Preferences).locale

env.response.headers["Content-Type"] = "application/atom+xml"
env.response.content_type = "application/atom+xml"

ucid = env.params.url["ucid"]

params = HTTP::Params.parse(env.params.query["params"]? || "")

begin
channel = get_about_info(ucid, locale)
rescue ex : ChannelRedirect
return env.redirect env.request.resource.gsub(ucid, ex.channel_id)
rescue ex : NotFoundException
return error_atom(404, ex)
rescue ex
return error_atom(500, ex)
end

namespaces = {
"yt" => "http://www.youtube.com/xml/schemas/2015",
"media" => "http://search.yahoo.com/mrss/",
"default" => "http://www.w3.org/2005/Atom",
}

response = YT_POOL.client &.get("/feeds/videos.xml?channel_id=#{channel.ucid}")
response = YT_POOL.client &.get("/feeds/videos.xml?channel_id=#{ucid}")
return error_atom(404, NotFoundException.new("Channel does not exist.")) if response.status_code == 404
rss = XML.parse(response.body)

videos = rss.xpath_nodes("//default:feed/default:entry", namespaces).map do |entry|
Expand All @@ -179,15 +168,15 @@ module Invidious::Routes::Feeds
updated = Time.parse_rfc3339(entry.xpath_node("default:updated", namespaces).not_nil!.content)

author = entry.xpath_node("default:author/default:name", namespaces).not_nil!.content
ucid = entry.xpath_node("yt:channelId", namespaces).not_nil!.content
video_ucid = entry.xpath_node("yt:channelId", namespaces).not_nil!.content
description_html = entry.xpath_node("media:group/media:description", namespaces).not_nil!.to_s
views = entry.xpath_node("media:group/media:community/media:statistics", namespaces).not_nil!.["views"].to_i64

SearchVideo.new({
title: title,
id: video_id,
author: author,
ucid: ucid,
ucid: video_ucid,
published: published,
views: views,
description_html: description_html,
Expand All @@ -198,30 +187,33 @@ module Invidious::Routes::Feeds
})
end

author = ""
author = videos[0].author if videos.size > 0

XML.build(indent: " ", encoding: "UTF-8") do |xml|
xml.element("feed", "xmlns:yt": "http://www.youtube.com/xml/schemas/2015",
"xmlns:media": "http://search.yahoo.com/mrss/", xmlns: "http://www.w3.org/2005/Atom",
"xml:lang": "en-US") do
xml.element("link", rel: "self", href: "#{HOST_URL}#{env.request.resource}")
xml.element("id") { xml.text "yt:channel:#{channel.ucid}" }
xml.element("yt:channelId") { xml.text channel.ucid }
xml.element("icon") { xml.text channel.author_thumbnail }
xml.element("title") { xml.text channel.author }
xml.element("link", rel: "alternate", href: "#{HOST_URL}/channel/#{channel.ucid}")
xml.element("id") { xml.text "yt:channel:#{ucid}" }
xml.element("yt:channelId") { xml.text ucid }
xml.element("icon") { xml.text "" }
xml.element("title") { author }
xml.element("link", rel: "alternate", href: "#{HOST_URL}/channel/#{ucid}")

xml.element("author") do
xml.element("name") { xml.text channel.author }
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{channel.ucid}" }
xml.element("name") { xml.text author }
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" }
end

xml.element("image") do
xml.element("url") { xml.text channel.author_thumbnail }
xml.element("title") { xml.text channel.author }
xml.element("url") { xml.text "" }
xml.element("title") { xml.text author }
xml.element("link", rel: "self", href: "#{HOST_URL}#{env.request.resource}")
end

videos.each do |video|
video.to_xml(channel.auto_generated, params, xml)
video.to_xml(false, params, xml)
end
end
end
Expand Down

0 comments on commit b37a433

Please sign in to comment.