Add logic to parse channel watermark data

This commit is contained in:
syeopite 2023-09-22 23:47:30 -04:00
parent d76fed5850
commit 44b8ecfab9
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
3 changed files with 22 additions and 1 deletions

View File

@ -55,6 +55,10 @@ module Invidious::JSONify::APIv1
end
end
if watermark = video.watermark?
json.field "authorWatermark", watermark
end
json.field "subCountText", video.sub_count_text
json.field "lengthSeconds", video.length_seconds

View File

@ -15,7 +15,7 @@ struct Video
# NOTE: don't forget to bump this number if any change is made to
# the `params` structure in videos/parser.cr!!!
#
SCHEMA_VERSION = 2
SCHEMA_VERSION = 3
property id : String
@ -258,6 +258,10 @@ struct Video
}
end
def watermark?
return info["watermark"]?
end
# Macros defining getters/setters for various types of data
private macro getset_string(name)

View File

@ -378,6 +378,18 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
.try &.as_s.split(" ", 2)[0]
end
# Channel watermark
# Annotations is different from legacy annotations
if watermark = player_response.dig?("annotations", 0, "playerAnnotationsExpandedRenderer", "featuredChannel")
watermark_data = {
"startTimeMs" => watermark["startTimeMs"],
"endTimeMS" => watermark["endTimeMs"],
"thumbnailURL" => watermark["watermark"]["thumbnails"][0]["url"],
}
else
watermark_data = {} of String => JSON::Any
end
# Return data
if live_now
@ -422,6 +434,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
"authorThumbnail" => JSON::Any.new(author_thumbnail.try &.as_s || ""),
"authorVerified" => JSON::Any.new(author_verified || false),
"subCountText" => JSON::Any.new(subs_text || "-"),
"watermark" => JSON::Any.new(watermark_data),
}
return params