summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgirst <girst@users.noreply.github.com>2019-09-07 17:45:37 +0200
committergirst <girst@users.noreply.github.com>2019-09-30 17:48:13 +0200
commit4aa1180fce1eea8eea262be276660f5a8ca4b324 (patch)
tree2b67f1350b01ffc4eccdd1374acb27f900e438db
parent7c75111c41ae2fbe6a54b90b9487498b7df38251 (diff)
downloadinvidious-4aa1180fce1eea8eea262be276660f5a8ca4b324.tar.gz
invidious-4aa1180fce1eea8eea262be276660f5a8ca4b324.tar.bz2
invidious-4aa1180fce1eea8eea262be276660f5a8ca4b324.zip
Forward parameters given in &params= from Atom feeds
Any parameters given in &params=... are appended to /watch URLs. This allows e.g. passing &raw=1&listen=1 to a playlist of music and use an rss reader like newsboat as a media player, like so: https://invidio.us/feed/playlist/XXX?params=%26raw%3D1%listen%3D1 All three feeds--channels, playlists, subscriptions--are supported.
-rw-r--r--src/invidious.cr18
-rw-r--r--src/invidious/channels.cr8
-rw-r--r--src/invidious/search.cr14
3 files changed, 25 insertions, 15 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 8f7e1a63..42a2b23a 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -2630,6 +2630,8 @@ get "/feed/channel/:ucid" do |env|
ucid = env.params.url["ucid"]
+ params = HTTP::Params.parse(env.params.query["params"]? || "")
+
begin
channel = get_about_info(ucid, locale)
rescue ex
@@ -2690,7 +2692,7 @@ get "/feed/channel/:ucid" do |env|
end
videos.each do |video|
- video.to_xml(host_url, channel.auto_generated, xml)
+ video.to_xml(host_url, channel.auto_generated, params, xml)
end
end
end
@@ -2721,6 +2723,8 @@ get "/feed/private" do |env|
page = env.params.query["page"]?.try &.to_i?
page ||= 1
+ params = HTTP::Params.parse(env.params.query["params"]? || "")
+
videos, notifications = get_subscription_feed(PG_DB, user, max_results, page)
host_url = make_host_url(config, Kemal.config)
@@ -2734,7 +2738,7 @@ get "/feed/private" do |env|
xml.element("title") { xml.text translate(locale, "Invidious Private Feed for `x`", user.email) }
(notifications + videos).each do |video|
- video.to_xml(locale, host_url, xml)
+ video.to_xml(locale, host_url, params, xml)
end
end
end
@@ -2747,6 +2751,8 @@ get "/feed/playlist/:plid" do |env|
plid = env.params.url["plid"]
+ params = HTTP::Params.parse(env.params.query["params"]? || "")
+
host_url = make_host_url(config, Kemal.config)
path = env.request.path
@@ -2757,10 +2763,10 @@ get "/feed/playlist/:plid" do |env|
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}"
+ when "url", "href"
+ full_path = URI.parse(node[attribute.name]).full_path
+ query_string_opt = full_path.starts_with?("/watch?v=") ? "&#{params}" : ""
+ node[attribute.name] = "#{host_url}#{full_path}#{query_string_opt}"
end
end
end
diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr
index 00eac902..85502505 100644
--- a/src/invidious/channels.cr
+++ b/src/invidious/channels.cr
@@ -41,13 +41,15 @@ struct ChannelVideo
end
end
- def to_xml(locale, host_url, xml : XML::Builder)
+ def to_xml(locale, host_url, query_params, xml : XML::Builder)
+ query_params["v"] = self.id
+
xml.element("entry") do
xml.element("id") { xml.text "yt:video:#{self.id}" }
xml.element("yt:videoId") { xml.text self.id }
xml.element("yt:channelId") { xml.text self.ucid }
xml.element("title") { xml.text self.title }
- xml.element("link", rel: "alternate", href: "#{host_url}/watch?v=#{self.id}")
+ xml.element("link", rel: "alternate", href: "#{host_url}/watch?#{query_params}")
xml.element("author") do
xml.element("name") { xml.text self.author }
@@ -56,7 +58,7 @@ struct ChannelVideo
xml.element("content", type: "xhtml") do
xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do
- xml.element("a", href: "#{host_url}/watch?v=#{self.id}") do
+ xml.element("a", href: "#{host_url}/watch?#{query_params}") do
xml.element("img", src: "#{host_url}/vi/#{self.id}/mqdefault.jpg")
end
end
diff --git a/src/invidious/search.cr b/src/invidious/search.cr
index a55bb216..56035160 100644
--- a/src/invidious/search.cr
+++ b/src/invidious/search.cr
@@ -1,11 +1,13 @@
struct SearchVideo
- def to_xml(host_url, auto_generated, xml : XML::Builder)
+ def to_xml(host_url, auto_generated, query_params, xml : XML::Builder)
+ query_params["v"] = self.id
+
xml.element("entry") do
xml.element("id") { xml.text "yt:video:#{self.id}" }
xml.element("yt:videoId") { xml.text self.id }
xml.element("yt:channelId") { xml.text self.ucid }
xml.element("title") { xml.text self.title }
- xml.element("link", rel: "alternate", href: "#{host_url}/watch?v=#{self.id}")
+ xml.element("link", rel: "alternate", href: "#{host_url}/watch?#{query_params}")
xml.element("author") do
if auto_generated
@@ -19,7 +21,7 @@ struct SearchVideo
xml.element("content", type: "xhtml") do
xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do
- xml.element("a", href: "#{host_url}/watch?v=#{self.id}") do
+ xml.element("a", href: "#{host_url}/watch?#{query_params}") do
xml.element("img", src: "#{host_url}/vi/#{self.id}/mqdefault.jpg")
end
end
@@ -40,12 +42,12 @@ struct SearchVideo
end
end
- def to_xml(host_url, auto_generated, xml : XML::Builder | Nil = nil)
+ def to_xml(host_url, auto_generated, query_params, xml : XML::Builder | Nil = nil)
if xml
- to_xml(host_url, auto_generated, xml)
+ to_xml(host_url, auto_generated, query_params, xml)
else
XML.build do |json|
- to_xml(host_url, auto_generated, xml)
+ to_xml(host_url, auto_generated, query_params, xml)
end
end
end