From bd5ec2f2f3ed2852978d216c1ea9a10554544d7d Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Mon, 17 Sep 2018 18:13:24 -0500 Subject: [PATCH] Add playlist RSS --- src/invidious.cr | 32 ++++++++++++++++++++++++++++++++ src/invidious/views/playlist.ecr | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/src/invidious.cr b/src/invidious.cr index 3286f3ae..d1509437 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1618,6 +1618,38 @@ get "/feed/private" do |env| feed end +get "/feed/playlist/:plid" do |env| + plid = env.params.url["plid"] + + host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, env.request.headers["Host"]?) + path = env.request.path + + client = make_client(YT_URL) + response = client.get("/feeds/videos.xml?playlist_id=#{plid}") + document = XML.parse(response.body) + + document.xpath_nodes(%q(//*[@href]|//*[@url])).each do |node| + node.attributes.each do |attribute| + case attribute.name + when "url" + node["url"] = "#{host_url}#{URI.parse(node["url"]).full_path}" + when "href" + node["href"] = "#{host_url}#{URI.parse(node["href"]).full_path}" + end + end + end + + document = document.to_xml(options: XML::SaveOptions::NO_DECL) + + document.scan(/(?[^<]+)<\/uri>/).each do |match| + content = "#{host_url}#{URI.parse(match["url"]).full_path}" + document = document.gsub(match[0], "#{content}") + end + + env.response.content_type = "text/xml" + document +end + # Channels # YouTube appears to let users set a "brand" URL that diff --git a/src/invidious/views/playlist.ecr b/src/invidious/views/playlist.ecr index 4e93fc6f..56ad79f3 100644 --- a/src/invidious/views/playlist.ecr +++ b/src/invidious/views/playlist.ecr @@ -6,6 +6,11 @@

<%= playlist.title %>

+
+

+ +

+