Add support for "members first" badge

This commit is contained in:
syeopite 2025-04-20 19:57:21 -07:00
parent 2a50d20715
commit 789b561c76
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
5 changed files with 15 additions and 4 deletions

View File

@ -503,5 +503,6 @@
"carousel_skip": "Skip the Carousel",
"carousel_go_to": "Go to slide `x`",
"video_badges_members_only": "Members only",
"video_badges_members_first": "Members first",
"preferences_exclude_members_only_videos_label": "Hide channel member-only videos"
}

View File

@ -10,6 +10,7 @@ enum VideoBadges
VR360
ClosedCaptions
MembersOnly
MembersFirst
end
struct SearchVideo
@ -152,6 +153,13 @@ struct SearchVideo
def upcoming?
premiere_timestamp ? true : false
end
# Shorthand to check whether the video is restricted to only channel members
#
# Whether as an early access video ("members first") or only for members ("members only")
def restricted_to_members?
return badges.members_only? || badges.members_first?
end
end
struct SearchPlaylistVideo

View File

@ -208,6 +208,9 @@
<% if item.badges.members_only? %>
<span><i class="icon ion ion-md-lock"></i><%=translate(locale, "video_badges_members_only")%></span>
<% end %>
<% if item.badges.members_first? %>
<span><i class="icon ion ion-md-lock"></i><%=translate(locale, "video_badges_members_first")%></span>
<% end %>
</div>
<%end%>
<% end %>

View File

@ -3,8 +3,7 @@
<div class="pure-g">
<%- items.each do |item| -%>
<% next if exclude_members_only_videos && item.responds_to?(:badges) &&
item.is_a? SearchVideo && item.badges.members_only? %>
<% next if exclude_members_only_videos && item.responds_to?(:restricted_to_members?) && item.restricted_to_members? %>
<%= rendered "components/item" %>
<%- end -%>
</div>

View File

@ -136,9 +136,9 @@ private module Parsers
# TODO: Potentially available as item_contents["topStandaloneBadge"]["metadataBadgeRenderer"]
badges |= VideoBadges::Premium
when "Members only"
# TODO: Identify based on style attribute instead of label
# It should be more resistant to Youtube changes.
badges |= VideoBadges::MembersOnly
when "Members first"
badges |= VideoBadges::MembersFirst
else nil # Ignore
end
end