mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
synced 2024-08-15 00:53:38 +00:00
Unify parameters of the different #to_xml methods
This commit is contained in:
parent
7c3c0564f5
commit
6b8189b465
4 changed files with 7 additions and 34 deletions
|
@ -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 %}
|
||||
{
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue