forked from midou/invidious
Make HOST_URL constant
This commit is contained in:
@ -9,14 +9,14 @@ struct InvidiousChannel
|
||||
end
|
||||
|
||||
struct ChannelVideo
|
||||
def to_json(locale, config, kemal_config, json : JSON::Builder)
|
||||
def to_json(locale, json : JSON::Builder)
|
||||
json.object do
|
||||
json.field "type", "shortVideo"
|
||||
|
||||
json.field "title", self.title
|
||||
json.field "videoId", self.id
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, self.id, config, Kemal.config)
|
||||
generate_thumbnails(json, self.id)
|
||||
end
|
||||
|
||||
json.field "lengthSeconds", self.length_seconds
|
||||
@ -31,17 +31,17 @@ struct ChannelVideo
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(locale, config, kemal_config, json : JSON::Builder | Nil = nil)
|
||||
def to_json(locale, json : JSON::Builder | Nil = nil)
|
||||
if json
|
||||
to_json(locale, config, kemal_config, json)
|
||||
to_json(locale, json)
|
||||
else
|
||||
JSON.build do |json|
|
||||
to_json(locale, config, kemal_config, json)
|
||||
to_json(locale, json)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_xml(locale, host_url, query_params, xml : XML::Builder)
|
||||
def to_xml(locale, query_params, xml : XML::Builder)
|
||||
query_params["v"] = self.id
|
||||
|
||||
xml.element("entry") do
|
||||
@ -49,17 +49,17 @@ struct ChannelVideo
|
||||
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?#{query_params}")
|
||||
xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?#{query_params}")
|
||||
|
||||
xml.element("author") do
|
||||
xml.element("name") { xml.text self.author }
|
||||
xml.element("uri") { xml.text "#{host_url}/channel/#{self.ucid}" }
|
||||
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" }
|
||||
end
|
||||
|
||||
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("img", src: "#{host_url}/vi/#{self.id}/mqdefault.jpg")
|
||||
xml.element("a", href: "#{HOST_URL}/watch?#{query_params}") do
|
||||
xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -69,18 +69,18 @@ struct ChannelVideo
|
||||
|
||||
xml.element("media:group") do
|
||||
xml.element("media:title") { xml.text self.title }
|
||||
xml.element("media:thumbnail", url: "#{host_url}/vi/#{self.id}/mqdefault.jpg",
|
||||
xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg",
|
||||
width: "320", height: "180")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_xml(locale, config, kemal_config, xml : XML::Builder | Nil = nil)
|
||||
def to_xml(locale, xml : XML::Builder | Nil = nil)
|
||||
if xml
|
||||
to_xml(locale, config, kemal_config, xml)
|
||||
to_xml(locale, xml)
|
||||
else
|
||||
XML.build do |xml|
|
||||
to_xml(locale, config, kemal_config, xml)
|
||||
to_xml(locale, xml)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -557,7 +557,7 @@ def extract_channel_playlists_cursor(url, auto_generated)
|
||||
end
|
||||
|
||||
# TODO: Add "sort_by"
|
||||
def fetch_channel_community(ucid, continuation, locale, config, kemal_config, format, thin_mode)
|
||||
def fetch_channel_community(ucid, continuation, locale, format, thin_mode)
|
||||
response = YT_POOL.client &.get("/channel/#{ucid}/community?gl=US&hl=en")
|
||||
if response.status_code != 200
|
||||
response = YT_POOL.client &.get("/user/#{ucid}/community?gl=US&hl=en")
|
||||
@ -708,7 +708,7 @@ def fetch_channel_community(ucid, continuation, locale, config, kemal_config, fo
|
||||
json.field "title", attachment["title"]["simpleText"].as_s
|
||||
json.field "videoId", video_id
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video_id, config, kemal_config)
|
||||
generate_thumbnails(json, video_id)
|
||||
end
|
||||
|
||||
json.field "lengthSeconds", decode_length_seconds(attachment["lengthText"]["simpleText"].as_s)
|
||||
@ -956,33 +956,17 @@ def get_about_info(ucid, locale)
|
||||
end
|
||||
|
||||
def get_60_videos(ucid, author, page, auto_generated, sort_by = "newest")
|
||||
count = 0
|
||||
videos = [] of SearchVideo
|
||||
|
||||
2.times do |i|
|
||||
url = produce_channel_videos_url(ucid, page * 2 + (i - 1), auto_generated: auto_generated, sort_by: sort_by)
|
||||
response = YT_POOL.client &.get(url)
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
if json["content_html"]? && !json["content_html"].as_s.empty?
|
||||
document = XML.parse_html(json["content_html"].as_s)
|
||||
nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")]))
|
||||
|
||||
if !json["load_more_widget_html"]?.try &.as_s.empty?
|
||||
count += 30
|
||||
end
|
||||
|
||||
if auto_generated
|
||||
videos += extract_videos(nodeset)
|
||||
else
|
||||
videos += extract_videos(nodeset, ucid, author)
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
response = YT_POOL.client &.get(url, headers)
|
||||
initial_data = JSON.parse(response.body).as_a.find &.["response"]?
|
||||
break if !initial_data
|
||||
videos.concat extract_videos(initial_data.as_h)
|
||||
end
|
||||
|
||||
return videos, count
|
||||
return videos.size, videos
|
||||
end
|
||||
|
||||
def get_latest_videos(ucid)
|
||||
|
@ -727,13 +727,10 @@ def cache_annotation(db, id, annotations)
|
||||
end
|
||||
end
|
||||
|
||||
if has_legacy_annotations
|
||||
# TODO: Update on conflict?
|
||||
db.exec("INSERT INTO annotations VALUES ($1, $2) ON CONFLICT DO NOTHING", id, annotations)
|
||||
end
|
||||
db.exec("INSERT INTO annotations VALUES ($1, $2) ON CONFLICT DO NOTHING", id, annotations) if has_legacy_annotations
|
||||
end
|
||||
|
||||
def create_notification_stream(env, config, kemal_config, decrypt_function, topics, connection_channel)
|
||||
def create_notification_stream(env, topics, connection_channel)
|
||||
connection = Channel(PQ::Notification).new(8)
|
||||
connection_channel.send({true, connection})
|
||||
|
||||
@ -753,7 +750,7 @@ def create_notification_stream(env, config, kemal_config, decrypt_function, topi
|
||||
|
||||
video = get_video(video_id, PG_DB)
|
||||
video.published = published
|
||||
response = JSON.parse(video.to_json(locale, config, kemal_config, decrypt_function))
|
||||
response = JSON.parse(video.to_json(locale))
|
||||
|
||||
if fields_text = env.params.query["fields"]?
|
||||
begin
|
||||
@ -787,7 +784,7 @@ def create_notification_stream(env, config, kemal_config, decrypt_function, topi
|
||||
when .match(/UC[A-Za-z0-9_-]{22}/)
|
||||
PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid = $1 AND published > $2 ORDER BY published DESC LIMIT 15",
|
||||
topic, Time.unix(since.not_nil!), as: ChannelVideo).each do |video|
|
||||
response = JSON.parse(video.to_json(locale, config, Kemal.config))
|
||||
response = JSON.parse(video.to_json(locale))
|
||||
|
||||
if fields_text = env.params.query["fields"]?
|
||||
begin
|
||||
@ -829,7 +826,7 @@ def create_notification_stream(env, config, kemal_config, decrypt_function, topi
|
||||
|
||||
video = get_video(video_id, PG_DB)
|
||||
video.published = Time.unix(published)
|
||||
response = JSON.parse(video.to_json(locale, config, Kemal.config, decrypt_function))
|
||||
response = JSON.parse(video.to_json(locale))
|
||||
|
||||
if fields_text = env.params.query["fields"]?
|
||||
begin
|
||||
|
@ -40,12 +40,12 @@ def fetch_decrypt_function(id = "CvFH_6DNRCY")
|
||||
return decrypt_function
|
||||
end
|
||||
|
||||
def decrypt_signature(fmt, op)
|
||||
def decrypt_signature(fmt : Hash(String, JSON::Any))
|
||||
return "" if !fmt["s"]? || !fmt["sp"]?
|
||||
|
||||
sp = fmt["sp"]
|
||||
sig = fmt["s"].split("")
|
||||
op.each do |proc, value|
|
||||
sp = fmt["sp"].as_s
|
||||
sig = fmt["s"].as_s.split("")
|
||||
DECRYPT_FUNCTION.each do |proc, value|
|
||||
sig = proc.call(sig, value)
|
||||
end
|
||||
|
||||
|
@ -351,10 +351,8 @@ def subscribe_pubsub(topic, key, config)
|
||||
nonce = Random::Secure.hex(4)
|
||||
signature = "#{time}:#{nonce}"
|
||||
|
||||
host_url = make_host_url(config, Kemal.config)
|
||||
|
||||
body = {
|
||||
"hub.callback" => "#{host_url}/feed/webhook/v1:#{time}:#{nonce}:#{OpenSSL::HMAC.hexdigest(:sha1, key, signature)}",
|
||||
"hub.callback" => "#{HOST_URL}/feed/webhook/v1:#{time}:#{nonce}:#{OpenSSL::HMAC.hexdigest(:sha1, key, signature)}",
|
||||
"hub.topic" => "https://www.youtube.com/xml/feeds/videos.xml?#{topic}",
|
||||
"hub.verify" => "async",
|
||||
"hub.mode" => "subscribe",
|
||||
|
@ -1,26 +1,26 @@
|
||||
struct PlaylistVideo
|
||||
def to_xml(host_url, auto_generated, xml : XML::Builder)
|
||||
def to_xml(auto_generated, xml : XML::Builder)
|
||||
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?v=#{self.id}")
|
||||
|
||||
xml.element("author") do
|
||||
if auto_generated
|
||||
xml.element("name") { xml.text self.author }
|
||||
xml.element("uri") { xml.text "#{host_url}/channel/#{self.ucid}" }
|
||||
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" }
|
||||
else
|
||||
xml.element("name") { xml.text author }
|
||||
xml.element("uri") { xml.text "#{host_url}/channel/#{ucid}" }
|
||||
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" }
|
||||
end
|
||||
end
|
||||
|
||||
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("img", src: "#{host_url}/vi/#{self.id}/mqdefault.jpg")
|
||||
xml.element("a", href: "#{HOST_URL}/watch?v=#{self.id}") do
|
||||
xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -29,23 +29,23 @@ struct PlaylistVideo
|
||||
|
||||
xml.element("media:group") do
|
||||
xml.element("media:title") { xml.text self.title }
|
||||
xml.element("media:thumbnail", url: "#{host_url}/vi/#{self.id}/mqdefault.jpg",
|
||||
xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg",
|
||||
width: "320", height: "180")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_xml(host_url, auto_generated, xml : XML::Builder? = nil)
|
||||
def to_xml(auto_generated, xml : XML::Builder? = nil)
|
||||
if xml
|
||||
to_xml(host_url, auto_generated, xml)
|
||||
to_xml(auto_generated, xml)
|
||||
else
|
||||
XML.build do |json|
|
||||
to_xml(host_url, auto_generated, xml)
|
||||
to_xml(auto_generated, xml)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(locale, config, kemal_config, json : JSON::Builder, index : Int32?)
|
||||
def to_json(locale, json : JSON::Builder, index : Int32?)
|
||||
json.object do
|
||||
json.field "title", self.title
|
||||
json.field "videoId", self.id
|
||||
@ -55,7 +55,7 @@ struct PlaylistVideo
|
||||
json.field "authorUrl", "/channel/#{self.ucid}"
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, self.id, config, kemal_config)
|
||||
generate_thumbnails(json, self.id)
|
||||
end
|
||||
|
||||
if index
|
||||
@ -69,12 +69,12 @@ struct PlaylistVideo
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(locale, config, kemal_config, json : JSON::Builder? = nil, index : Int32? = nil)
|
||||
def to_json(locale, json : JSON::Builder? = nil, index : Int32? = nil)
|
||||
if json
|
||||
to_json(locale, config, kemal_config, json, index: index)
|
||||
to_json(locale, json, index: index)
|
||||
else
|
||||
JSON.build do |json|
|
||||
to_json(locale, config, kemal_config, json, index: index)
|
||||
to_json(locale, json, index: index)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -93,7 +93,7 @@ struct PlaylistVideo
|
||||
end
|
||||
|
||||
struct Playlist
|
||||
def to_json(offset, locale, config, kemal_config, json : JSON::Builder, continuation : String? = nil)
|
||||
def to_json(offset, locale, json : JSON::Builder, continuation : String? = nil)
|
||||
json.object do
|
||||
json.field "type", "playlist"
|
||||
json.field "title", self.title
|
||||
@ -130,19 +130,19 @@ struct Playlist
|
||||
json.array do
|
||||
videos = get_playlist_videos(PG_DB, self, offset: offset, locale: locale, continuation: continuation)
|
||||
videos.each_with_index do |video, index|
|
||||
video.to_json(locale, config, Kemal.config, json)
|
||||
video.to_json(locale, json)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(offset, locale, config, kemal_config, json : JSON::Builder? = nil, continuation : String? = nil)
|
||||
def to_json(offset, locale, json : JSON::Builder? = nil, continuation : String? = nil)
|
||||
if json
|
||||
to_json(offset, locale, config, kemal_config, json, continuation: continuation)
|
||||
to_json(offset, locale, json, continuation: continuation)
|
||||
else
|
||||
JSON.build do |json|
|
||||
to_json(offset, locale, config, kemal_config, json, continuation: continuation)
|
||||
to_json(offset, locale, json, continuation: continuation)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -172,7 +172,7 @@ enum PlaylistPrivacy
|
||||
end
|
||||
|
||||
struct InvidiousPlaylist
|
||||
def to_json(offset, locale, config, kemal_config, json : JSON::Builder, continuation : String? = nil)
|
||||
def to_json(offset, locale, json : JSON::Builder, continuation : String? = nil)
|
||||
json.object do
|
||||
json.field "type", "invidiousPlaylist"
|
||||
json.field "title", self.title
|
||||
@ -195,19 +195,19 @@ struct InvidiousPlaylist
|
||||
json.array do
|
||||
videos = get_playlist_videos(PG_DB, self, offset: offset, locale: locale, continuation: continuation)
|
||||
videos.each_with_index do |video, index|
|
||||
video.to_json(locale, config, Kemal.config, json, offset + index)
|
||||
video.to_json(locale, json, offset + index)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(offset, locale, config, kemal_config, json : JSON::Builder? = nil, continuation : String? = nil)
|
||||
def to_json(offset, locale, json : JSON::Builder? = nil, continuation : String? = nil)
|
||||
if json
|
||||
to_json(offset, locale, config, kemal_config, json, continuation: continuation)
|
||||
to_json(offset, locale, json, continuation: continuation)
|
||||
else
|
||||
JSON.build do |json|
|
||||
to_json(offset, locale, config, kemal_config, json, continuation: continuation)
|
||||
to_json(offset, locale, json, continuation: continuation)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
struct SearchVideo
|
||||
def to_xml(host_url, auto_generated, query_params, xml : XML::Builder)
|
||||
def to_xml(auto_generated, query_params, xml : XML::Builder)
|
||||
query_params["v"] = self.id
|
||||
|
||||
xml.element("entry") do
|
||||
@ -7,22 +7,22 @@ struct SearchVideo
|
||||
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?#{query_params}")
|
||||
xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?#{query_params}")
|
||||
|
||||
xml.element("author") do
|
||||
if auto_generated
|
||||
xml.element("name") { xml.text self.author }
|
||||
xml.element("uri") { xml.text "#{host_url}/channel/#{self.ucid}" }
|
||||
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" }
|
||||
else
|
||||
xml.element("name") { xml.text author }
|
||||
xml.element("uri") { xml.text "#{host_url}/channel/#{ucid}" }
|
||||
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" }
|
||||
end
|
||||
end
|
||||
|
||||
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("img", src: "#{host_url}/vi/#{self.id}/mqdefault.jpg")
|
||||
xml.element("a", href: "#{HOST_URL}/watch?#{query_params}") do
|
||||
xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg")
|
||||
end
|
||||
|
||||
xml.element("p", style: "word-break:break-word;white-space:pre-wrap") { xml.text html_to_content(self.description_html) }
|
||||
@ -33,7 +33,7 @@ struct SearchVideo
|
||||
|
||||
xml.element("media:group") do
|
||||
xml.element("media:title") { xml.text self.title }
|
||||
xml.element("media:thumbnail", url: "#{host_url}/vi/#{self.id}/mqdefault.jpg",
|
||||
xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg",
|
||||
width: "320", height: "180")
|
||||
xml.element("media:description") { xml.text html_to_content(self.description_html) }
|
||||
end
|
||||
@ -44,17 +44,17 @@ struct SearchVideo
|
||||
end
|
||||
end
|
||||
|
||||
def to_xml(host_url, auto_generated, query_params, xml : XML::Builder | Nil = nil)
|
||||
def to_xml(auto_generated, query_params, xml : XML::Builder | Nil = nil)
|
||||
if xml
|
||||
to_xml(host_url, auto_generated, query_params, xml)
|
||||
to_xml(HOST_URL, auto_generated, query_params, xml)
|
||||
else
|
||||
XML.build do |json|
|
||||
to_xml(host_url, auto_generated, query_params, xml)
|
||||
to_xml(HOST_URL, auto_generated, query_params, xml)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(locale, config, kemal_config, json : JSON::Builder)
|
||||
def to_json(locale, json : JSON::Builder)
|
||||
json.object do
|
||||
json.field "type", "video"
|
||||
json.field "title", self.title
|
||||
@ -65,7 +65,7 @@ struct SearchVideo
|
||||
json.field "authorUrl", "/channel/#{self.ucid}"
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, self.id, config, kemal_config)
|
||||
generate_thumbnails(json, self.id)
|
||||
end
|
||||
|
||||
json.field "description", html_to_content(self.description_html)
|
||||
@ -78,15 +78,20 @@ struct SearchVideo
|
||||
json.field "liveNow", self.live_now
|
||||
json.field "paid", self.paid
|
||||
json.field "premium", self.premium
|
||||
json.field "isUpcoming", self.is_upcoming
|
||||
|
||||
if self.premiere_timestamp
|
||||
json.field "premiereTimestamp", self.premiere_timestamp.try &.to_unix
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(locale, config, kemal_config, json : JSON::Builder | Nil = nil)
|
||||
def to_json(locale, json : JSON::Builder | Nil = nil)
|
||||
if json
|
||||
to_json(locale, config, kemal_config, json)
|
||||
to_json(locale, json)
|
||||
else
|
||||
JSON.build do |json|
|
||||
to_json(locale, config, kemal_config, json)
|
||||
to_json(locale, json)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -116,7 +121,7 @@ struct SearchPlaylistVideo
|
||||
end
|
||||
|
||||
struct SearchPlaylist
|
||||
def to_json(locale, config, kemal_config, json : JSON::Builder)
|
||||
def to_json(locale, json : JSON::Builder)
|
||||
json.object do
|
||||
json.field "type", "playlist"
|
||||
json.field "title", self.title
|
||||
@ -137,7 +142,7 @@ struct SearchPlaylist
|
||||
json.field "lengthSeconds", video.length_seconds
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
generate_thumbnails(json, video.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -146,12 +151,12 @@ struct SearchPlaylist
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(locale, config, kemal_config, json : JSON::Builder | Nil = nil)
|
||||
def to_json(locale, json : JSON::Builder | Nil = nil)
|
||||
if json
|
||||
to_json(locale, config, kemal_config, json)
|
||||
to_json(locale, json)
|
||||
else
|
||||
JSON.build do |json|
|
||||
to_json(locale, config, kemal_config, json)
|
||||
to_json(locale, json)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -168,7 +173,7 @@ struct SearchPlaylist
|
||||
end
|
||||
|
||||
struct SearchChannel
|
||||
def to_json(locale, config, kemal_config, json : JSON::Builder)
|
||||
def to_json(locale, json : JSON::Builder)
|
||||
json.object do
|
||||
json.field "type", "channel"
|
||||
json.field "author", self.author
|
||||
@ -198,12 +203,12 @@ struct SearchChannel
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(locale, config, kemal_config, json : JSON::Builder | Nil = nil)
|
||||
def to_json(locale, json : JSON::Builder | Nil = nil)
|
||||
if json
|
||||
to_json(locale, config, kemal_config, json)
|
||||
to_json(locale, json)
|
||||
else
|
||||
JSON.build do |json|
|
||||
to_json(locale, config, kemal_config, json)
|
||||
to_json(locale, json)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -255,17 +255,20 @@ struct Video
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(locale, config, kemal_config, decrypt_function, json : JSON::Builder)
|
||||
def to_json(locale, json : JSON::Builder)
|
||||
json.object do
|
||||
json.field "type", "video"
|
||||
|
||||
json.field "title", self.title
|
||||
json.field "videoId", self.id
|
||||
|
||||
json.field "error", info["reason"] if info["reason"]?
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, self.id, config, kemal_config)
|
||||
generate_thumbnails(json, self.id)
|
||||
end
|
||||
json.field "storyboards" do
|
||||
generate_storyboards(json, self.id, self.storyboards, config, kemal_config)
|
||||
generate_storyboards(json, self.id, self.storyboards)
|
||||
end
|
||||
|
||||
json.field "description", html_to_content(self.description_html)
|
||||
@ -316,16 +319,12 @@ struct Video
|
||||
json.field "premiereTimestamp", self.premiere_timestamp.not_nil!.to_unix
|
||||
end
|
||||
|
||||
if player_response["streamingData"]?.try &.["hlsManifestUrl"]?
|
||||
host_url = make_host_url(config, kemal_config)
|
||||
|
||||
hlsvp = player_response["streamingData"]["hlsManifestUrl"].as_s
|
||||
hlsvp = hlsvp.gsub("https://manifest.googlevideo.com", host_url)
|
||||
|
||||
if hlsvp = self.hls_manifest_url
|
||||
hlsvp = hlsvp.gsub("https://manifest.googlevideo.com", HOST_URL)
|
||||
json.field "hlsUrl", hlsvp
|
||||
end
|
||||
|
||||
json.field "dashUrl", "#{make_host_url(config, kemal_config)}/api/manifest/dash/id/#{id}"
|
||||
json.field "dashUrl", "#{HOST_URL}/api/manifest/dash/id/#{id}"
|
||||
|
||||
json.field "adaptiveFormats" do
|
||||
json.array do
|
||||
@ -424,7 +423,7 @@ struct Video
|
||||
json.field "videoId", rv["id"]
|
||||
json.field "title", rv["title"]
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, rv["id"], config, kemal_config)
|
||||
generate_thumbnails(json, rv["id"])
|
||||
end
|
||||
|
||||
json.field "author", rv["author"]
|
||||
@ -457,12 +456,12 @@ struct Video
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(locale, config, kemal_config, decrypt_function, json : JSON::Builder | Nil = nil)
|
||||
def to_json(locale, json : JSON::Builder | Nil = nil)
|
||||
if json
|
||||
to_json(locale, config, kemal_config, decrypt_function, json)
|
||||
to_json(locale, json)
|
||||
else
|
||||
JSON.build do |json|
|
||||
to_json(locale, config, kemal_config, decrypt_function, json)
|
||||
to_json(locale, json)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1391,9 +1390,9 @@ def process_video_params(query, preferences)
|
||||
return params
|
||||
end
|
||||
|
||||
def build_thumbnails(id, config, kemal_config)
|
||||
def build_thumbnails(id)
|
||||
return {
|
||||
{name: "maxres", host: "#{make_host_url(config, kemal_config)}", url: "maxres", height: 720, width: 1280},
|
||||
{name: "maxres", host: "#{HOST_URL}", url: "maxres", height: 720, width: 1280},
|
||||
{name: "maxresdefault", host: "https://i.ytimg.com", url: "maxresdefault", height: 720, width: 1280},
|
||||
{name: "sddefault", host: "https://i.ytimg.com", url: "sddefault", height: 480, width: 640},
|
||||
{name: "high", host: "https://i.ytimg.com", url: "hqdefault", height: 360, width: 480},
|
||||
@ -1405,9 +1404,9 @@ def build_thumbnails(id, config, kemal_config)
|
||||
}
|
||||
end
|
||||
|
||||
def generate_thumbnails(json, id, config, kemal_config)
|
||||
def generate_thumbnails(json, id)
|
||||
json.array do
|
||||
build_thumbnails(id, config, kemal_config).each do |thumbnail|
|
||||
build_thumbnails(id).each do |thumbnail|
|
||||
json.object do
|
||||
json.field "quality", thumbnail[:name]
|
||||
json.field "url", "#{thumbnail[:host]}/vi/#{id}/#{thumbnail["url"]}.jpg"
|
||||
@ -1418,7 +1417,7 @@ def generate_thumbnails(json, id, config, kemal_config)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_storyboards(json, id, storyboards, config, kemal_config)
|
||||
def generate_storyboards(json, id, storyboards)
|
||||
json.array do
|
||||
storyboards.each do |storyboard|
|
||||
json.object do
|
||||
|
@ -3,23 +3,23 @@
|
||||
<meta name="description" content="<%= HTML.escape(video.short_description) %>">
|
||||
<meta name="keywords" content="<%= video.keywords.join(",") %>">
|
||||
<meta property="og:site_name" content="Invidious">
|
||||
<meta property="og:url" content="<%= host_url %>/watch?v=<%= video.id %>">
|
||||
<meta property="og:url" content="<%= HOST_URL %>/watch?v=<%= video.id %>">
|
||||
<meta property="og:title" content="<%= HTML.escape(video.title) %>">
|
||||
<meta property="og:image" content="/vi/<%= video.id %>/maxres.jpg">
|
||||
<meta property="og:description" content="<%= HTML.escape(video.short_description) %>">
|
||||
<meta property="og:description" content="<%= video.short_description %>">
|
||||
<meta property="og:type" content="video.other">
|
||||
<meta property="og:video:url" content="<%= host_url %>/embed/<%= video.id %>">
|
||||
<meta property="og:video:secure_url" content="<%= host_url %>/embed/<%= video.id %>">
|
||||
<meta property="og:video:url" content="<%= HOST_URL %>/embed/<%= video.id %>">
|
||||
<meta property="og:video:secure_url" content="<%= HOST_URL %>/embed/<%= video.id %>">
|
||||
<meta property="og:video:type" content="text/html">
|
||||
<meta property="og:video:width" content="1280">
|
||||
<meta property="og:video:height" content="720">
|
||||
<meta name="twitter:card" content="player">
|
||||
<meta name="twitter:site" content="@omarroth1">
|
||||
<meta name="twitter:url" content="<%= host_url %>/watch?v=<%= video.id %>">
|
||||
<meta name="twitter:url" content="<%= HOST_URL %>/watch?v=<%= video.id %>">
|
||||
<meta name="twitter:title" content="<%= HTML.escape(video.title) %>">
|
||||
<meta name="twitter:description" content="<%= HTML.escape(video.short_description) %>">
|
||||
<meta name="twitter:image" content="<%= host_url %>/vi/<%= video.id %>/maxres.jpg">
|
||||
<meta name="twitter:player" content="<%= host_url %>/embed/<%= video.id %>">
|
||||
<meta name="twitter:description" content="<%= video.short_description %>">
|
||||
<meta name="twitter:image" content="<%= HOST_URL %>/vi/<%= video.id %>/maxres.jpg">
|
||||
<meta name="twitter:player" content="<%= HOST_URL %>/embed/<%= video.id %>">
|
||||
<meta name="twitter:player:width" content="1280">
|
||||
<meta name="twitter:player:height" content="720">
|
||||
<%= rendered "components/player_sources" %>
|
||||
|
Reference in New Issue
Block a user