mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-28 08:27:25 +00:00
switch to enum flag instead of adding lots of properties to SearchVideo
This commit is contained in:
parent
2e649363d2
commit
1961fc3b11
@ -223,7 +223,7 @@ def fetch_channel(ucid, pull_all_videos : Bool)
|
|||||||
length_seconds = channel_video.try &.length_seconds
|
length_seconds = channel_video.try &.length_seconds
|
||||||
length_seconds ||= 0
|
length_seconds ||= 0
|
||||||
|
|
||||||
live_now = channel_video.try &.live_now
|
live_now = channel_video.try &.badges.live_now?
|
||||||
live_now ||= false
|
live_now ||= false
|
||||||
|
|
||||||
premiere_timestamp = channel_video.try &.premiere_timestamp
|
premiere_timestamp = channel_video.try &.premiere_timestamp
|
||||||
@ -275,7 +275,7 @@ def fetch_channel(ucid, pull_all_videos : Bool)
|
|||||||
ucid: video.ucid,
|
ucid: video.ucid,
|
||||||
author: video.author,
|
author: video.author,
|
||||||
length_seconds: video.length_seconds,
|
length_seconds: video.length_seconds,
|
||||||
live_now: video.live_now,
|
live_now: video.badges.live_now?,
|
||||||
premiere_timestamp: video.premiere_timestamp,
|
premiere_timestamp: video.premiere_timestamp,
|
||||||
views: video.views,
|
views: video.views,
|
||||||
})
|
})
|
||||||
|
@ -1,3 +1,16 @@
|
|||||||
|
@[Flags]
|
||||||
|
enum VideoBadges
|
||||||
|
LiveNow
|
||||||
|
Premium
|
||||||
|
ThreeD
|
||||||
|
FourK
|
||||||
|
New
|
||||||
|
EightK
|
||||||
|
VR180
|
||||||
|
VR360
|
||||||
|
CCommons
|
||||||
|
end
|
||||||
|
|
||||||
struct SearchVideo
|
struct SearchVideo
|
||||||
include DB::Serializable
|
include DB::Serializable
|
||||||
|
|
||||||
@ -9,17 +22,9 @@ struct SearchVideo
|
|||||||
property views : Int64
|
property views : Int64
|
||||||
property description_html : String
|
property description_html : String
|
||||||
property length_seconds : Int32
|
property length_seconds : Int32
|
||||||
property live_now : Bool
|
|
||||||
property premium : Bool
|
|
||||||
property premiere_timestamp : Time?
|
property premiere_timestamp : Time?
|
||||||
property author_verified : Bool
|
property author_verified : Bool
|
||||||
property is_new : Bool
|
property badges : VideoBadges
|
||||||
property is_4k : Bool
|
|
||||||
property is_8k : Bool
|
|
||||||
property is_vr180 : Bool
|
|
||||||
property is_vr360 : Bool
|
|
||||||
property is_3d : Bool
|
|
||||||
property has_captions : Bool
|
|
||||||
|
|
||||||
def to_xml(auto_generated, query_params, xml : XML::Builder)
|
def to_xml(auto_generated, query_params, xml : XML::Builder)
|
||||||
query_params["v"] = self.id
|
query_params["v"] = self.id
|
||||||
@ -95,20 +100,20 @@ struct SearchVideo
|
|||||||
json.field "published", self.published.to_unix
|
json.field "published", self.published.to_unix
|
||||||
json.field "publishedText", translate(locale, "`x` ago", recode_date(self.published, locale))
|
json.field "publishedText", translate(locale, "`x` ago", recode_date(self.published, locale))
|
||||||
json.field "lengthSeconds", self.length_seconds
|
json.field "lengthSeconds", self.length_seconds
|
||||||
json.field "liveNow", self.live_now
|
json.field "liveNow", self.badges.live_now?
|
||||||
json.field "premium", self.premium
|
json.field "premium", self.badges.premium?
|
||||||
json.field "isUpcoming", self.upcoming?
|
json.field "isUpcoming", self.upcoming?
|
||||||
|
|
||||||
if self.premiere_timestamp
|
if self.premiere_timestamp
|
||||||
json.field "premiereTimestamp", self.premiere_timestamp.try &.to_unix
|
json.field "premiereTimestamp", self.premiere_timestamp.try &.to_unix
|
||||||
end
|
end
|
||||||
json.field "isNew", self.is_new
|
json.field "isNew", self.badges.new?
|
||||||
json.field "is4k", self.is_4k
|
json.field "is4k", self.badges.four_k?
|
||||||
json.field "is8k", self.is_8k
|
json.field "is8k", self.badges.eight_k?
|
||||||
json.field "isVR180", is_vr180
|
json.field "isVr180", self.badges.vr180?
|
||||||
json.field "isVR360", is_vr360
|
json.field "isVr360", self.badges.vr360?
|
||||||
json.field "is3d", is_3d
|
json.field "is3d", self.badges.three_d?
|
||||||
json.field "hasCaptions", self.has_captions
|
json.field "hasCaptions", self.badges.c_commons?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -192,18 +192,9 @@ module Invidious::Routes::Feeds
|
|||||||
views: views,
|
views: views,
|
||||||
description_html: description_html,
|
description_html: description_html,
|
||||||
length_seconds: 0,
|
length_seconds: 0,
|
||||||
live_now: false,
|
|
||||||
paid: false,
|
|
||||||
premium: false,
|
|
||||||
premiere_timestamp: nil,
|
premiere_timestamp: nil,
|
||||||
author_verified: false,
|
author_verified: false,
|
||||||
is_new: false,
|
badges: VideoBadges::None,
|
||||||
is_4k: false,
|
|
||||||
is_8k: false,
|
|
||||||
is_vr180: false,
|
|
||||||
is_vr360: false,
|
|
||||||
is_3d: false,
|
|
||||||
has_captions: false,
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -108,42 +108,31 @@ private module Parsers
|
|||||||
length_seconds = 0
|
length_seconds = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
live_now = false
|
|
||||||
premium = false
|
|
||||||
is_new = false
|
|
||||||
is_4k = false
|
|
||||||
is_8k = false
|
|
||||||
is_vr180 = false
|
|
||||||
is_vr360 = false
|
|
||||||
is_3d = false
|
|
||||||
has_captions = false
|
|
||||||
|
|
||||||
premiere_timestamp = item_contents.dig?("upcomingEventData", "startTime").try { |t| Time.unix(t.as_s.to_i64) }
|
premiere_timestamp = item_contents.dig?("upcomingEventData", "startTime").try { |t| Time.unix(t.as_s.to_i64) }
|
||||||
|
badges = VideoBadges::None
|
||||||
item_contents["badges"]?.try &.as_a.each do |badge|
|
item_contents["badges"]?.try &.as_a.each do |badge|
|
||||||
b = badge["metadataBadgeRenderer"]
|
b = badge["metadataBadgeRenderer"]
|
||||||
case b["label"].as_s
|
case b["label"].as_s
|
||||||
when "LIVE NOW"
|
when "LIVE NOW"
|
||||||
live_now = true
|
badges |= VideoBadges::LiveNow
|
||||||
when "New"
|
when "New"
|
||||||
is_new = true
|
badges |= VideoBadges::New
|
||||||
when "4K"
|
when "4K"
|
||||||
is_4k = true
|
badges |= VideoBadges::FourK
|
||||||
when "8K"
|
when "8K"
|
||||||
is_8k = true
|
badges |= VideoBadges::EightK
|
||||||
when "VR180"
|
when "VR180"
|
||||||
is_vr180 = true
|
badges |= VideoBadges::VR180
|
||||||
when "360°"
|
when "360°"
|
||||||
is_vr360 = true
|
badges |= VideoBadges::VR360
|
||||||
when "3D"
|
when "3D"
|
||||||
is_3d = true
|
badges |= VideoBadges::ThreeD
|
||||||
when "CC"
|
when "CC"
|
||||||
has_captions = true
|
badges |= VideoBadges::CCommons
|
||||||
when "Premium"
|
when "Premium"
|
||||||
# TODO: Potentially available as item_contents["topStandaloneBadge"]["metadataBadgeRenderer"]
|
# TODO: Potentially available as item_contents["topStandaloneBadge"]["metadataBadgeRenderer"]
|
||||||
premium = true
|
badges |= VideoBadges::Premium
|
||||||
else # Ignore
|
else nil # Ignore
|
||||||
puts b["label"].as_s
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -156,17 +145,9 @@ private module Parsers
|
|||||||
views: view_count,
|
views: view_count,
|
||||||
description_html: description_html,
|
description_html: description_html,
|
||||||
length_seconds: length_seconds,
|
length_seconds: length_seconds,
|
||||||
live_now: live_now,
|
|
||||||
premium: premium,
|
|
||||||
premiere_timestamp: premiere_timestamp,
|
premiere_timestamp: premiere_timestamp,
|
||||||
author_verified: author_verified,
|
author_verified: author_verified,
|
||||||
is_new: is_new,
|
badges: badges,
|
||||||
is_4k: is_4k,
|
|
||||||
is_8k: is_8k,
|
|
||||||
is_vr180: is_vr180,
|
|
||||||
is_vr360: is_vr360,
|
|
||||||
is_3d: is_3d,
|
|
||||||
has_captions: has_captions,
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -590,17 +571,9 @@ private module Parsers
|
|||||||
views: view_count,
|
views: view_count,
|
||||||
description_html: "",
|
description_html: "",
|
||||||
length_seconds: duration,
|
length_seconds: duration,
|
||||||
live_now: false,
|
|
||||||
premium: false,
|
|
||||||
premiere_timestamp: Time.unix(0),
|
premiere_timestamp: Time.unix(0),
|
||||||
author_verified: false,
|
author_verified: false,
|
||||||
is_new: false,
|
badges: VideoBadges::None,
|
||||||
is_4k: false,
|
|
||||||
is_8k: false,
|
|
||||||
is_vr180: false,
|
|
||||||
is_vr360: false,
|
|
||||||
is_3d: false,
|
|
||||||
has_captions: false,
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user