Skip to content

Commit

Permalink
Parse more metadata badges for SearchVideos
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkyProgrammer committed Aug 24, 2024
1 parent c5fdd9e commit d26ecbf
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/invidious/helpers/serialized_yt_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ struct SearchVideo
property premium : Bool
property premiere_timestamp : Time?
property author_verified : Bool
property is_new : Bool
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)
query_params["v"] = self.id
Expand Down Expand Up @@ -95,6 +102,13 @@ struct SearchVideo
if self.premiere_timestamp
json.field "premiereTimestamp", self.premiere_timestamp.try &.to_unix
end
json.field "isNew", self.is_new
json.field "is4k", self.is_4k
json.field "is8k", self.is_8k
json.field "isVR180", is_vr180
json.field "isVR360", is_vr360
json.field "is3d", is_3d
json.field "hasCaptions", self.has_captions
end
end

Expand Down
7 changes: 7 additions & 0 deletions src/invidious/routes/feeds.cr
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ module Invidious::Routes::Feeds
premium: false,
premiere_timestamp: nil,
author_verified: false,
is_new: false,
is_4k: false,
is_8k: false,
is_vr180: false,
is_vr360: false,
is_3d: false,
has_captions: false,
})
end

Expand Down
40 changes: 37 additions & 3 deletions src/invidious/yt_backend/extractors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ private module Parsers

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) }

Expand All @@ -118,12 +125,25 @@ private module Parsers
case b["label"].as_s
when "LIVE NOW"
live_now = true
when "New", "4K", "CC"
# TODO
when "New"
is_new = true
when "4K"
is_4k = true
when "8K"
is_8k = true
when "VR180"
is_vr180 = true
when "360°"
is_vr360 = true
when "3D"
is_3d = true
when "CC"
has_captions = true
when "Premium"
# TODO: Potentially available as item_contents["topStandaloneBadge"]["metadataBadgeRenderer"]
premium = true
else nil # Ignore
else # Ignore
puts b["label"].as_s
end
end

Expand All @@ -140,6 +160,13 @@ private module Parsers
premium: premium,
premiere_timestamp: premiere_timestamp,
author_verified: author_verified,
is_new: is_new,
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

Expand Down Expand Up @@ -567,6 +594,13 @@ private module Parsers
premium: false,
premiere_timestamp: Time.unix(0),
author_verified: false,
is_new: false,
is_4k: false,
is_8k: false,
is_vr180: false,
is_vr360: false,
is_3d: false,
has_captions: false,
})
end

Expand Down

0 comments on commit d26ecbf

Please sign in to comment.