Unify parameters of the different #to_xml methods

This commit is contained in:
Samantaz Fox 2022-04-17 15:53:10 +02:00
parent 7c3c0564f5
commit 6b8189b465
No known key found for this signature in database
GPG key ID: F42821059186176E
4 changed files with 7 additions and 34 deletions

View file

@ -50,9 +50,7 @@ struct ChannelVideo
end
end
def to_xml(locale, query_params, xml : XML::Builder)
query_params["v"] = self.id
def to_xml(xml : XML::Builder, query_params : HTTP::Params)
xml.element("entry") do
xml.element("id") { xml.text "ni://invidious/sha-256;" + sha256("video/#{self.id}") }
xml.element("title") { xml.text self.title }
@ -65,7 +63,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?#{query_params}") do
xml.element("a", href: "#{HOST_URL}/watch?v=#{self.id}&#{query_params}") do
xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg")
end
end
@ -82,12 +80,6 @@ struct ChannelVideo
end
end
def to_xml(locale, _xml : Nil = nil)
XML.build do |xml|
to_xml(locale, xml)
end
end
def to_tuple
{% begin %}
{

View file

@ -14,9 +14,7 @@ struct SearchVideo
property premiere_timestamp : Time?
property author_verified : Bool
def to_xml(auto_generated, query_params, xml : XML::Builder)
query_params["v"] = self.id
def to_xml(xml : XML::Builder, query_params : HTTP::Params)
xml.element("entry") do
xml.element("id") { xml.text "ni://invidious/sha-256;" + sha256("video/#{self.id}") }
xml.element("title") { xml.text self.title }
@ -29,7 +27,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?#{query_params}") do
xml.element("a", href: "#{HOST_URL}/watch?v=#{self.id}&#{query_params}") do
xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg")
end
@ -54,12 +52,6 @@ struct SearchVideo
end
end
def to_xml(auto_generated, query_params, _xml : Nil)
XML.build do |xml|
to_xml(auto_generated, query_params, xml)
end
end
def to_json(locale : String?, json : JSON::Builder)
json.object do
json.field "type", "video"

View file

@ -11,7 +11,7 @@ struct PlaylistVideo
property index : Int64
property live_now : Bool
def to_xml(xml : XML::Builder)
def to_xml(xml : XML::Builder, query_params : HTTP::Params)
xml.element("entry") do
xml.element("id") { xml.text "ni://invidious/sha-256;" + sha256("video/#{self.id}") }
xml.element("title") { xml.text self.title }
@ -24,7 +24,7 @@ struct PlaylistVideo
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?v=#{self.id}&#{query_params}") do
xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg")
end
end
@ -40,10 +40,6 @@ struct PlaylistVideo
end
end
def to_xml(_xml : Nil = nil)
XML.build { |xml| to_xml(xml) }
end
def to_json(json : JSON::Builder, index : Int32? = nil)
json.object do
json.field "title", self.title

View file

@ -110,14 +110,7 @@ module Invidious::RssAtom
end
# Video entries
# TODO: Unify `.to_xml` methods
videos.each do |video|
case video
when .is_a?(PlaylistVideo) then video.to_xml(xml)
when .is_a?(ChannelVideo) then video.to_xml(locale, params, xml)
when .is_a?(SearchVideo) then video.to_xml(false, params, xml)
end
end
videos.each { |video| video.to_xml(xml, params) }
end
end
end