Skip to content

Detect and identify videos restricted to channel members and add settings to exclude them #5222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions assets/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ span > select {
color: #565d64;
}

.light-theme .video-badges > span {
background: rgb(235, 235, 235);
color: #828282;
}

@media (prefers-color-scheme: light) {
.no-theme a:hover,
.no-theme a:active,
Expand Down Expand Up @@ -596,6 +601,11 @@ span > select {
.light-theme .pure-menu-heading {
color: #565d64;
}

.no-theme .video-badges > span {
background: rgb(235, 235, 235);
color: #828282;
}
}


Expand Down Expand Up @@ -658,6 +668,12 @@ body.dark-theme {
color: inherit;
}

.dark-theme .video-badges > span {
background: rgb(50, 50, 50);
color: #9e9e9e;
}


@media (prefers-color-scheme: dark) {
.no-theme a:hover,
.no-theme a:active,
Expand Down Expand Up @@ -719,6 +735,11 @@ body.dark-theme {
.no-theme footer a {
color: #adadad !important;
}

.no-theme .video-badges > span {
background: rgb(50, 50, 50);
color: #9e9e9e;
}
}


Expand Down Expand Up @@ -816,3 +837,19 @@ h1, h2, h3, h4, h5, p,
#download_widget {
width: 100%;
}

.video-badges > span {
display: flex;
align-items: center;
gap: 5px;

padding: 2px 10px;
border-radius: 10px;

font-size: 12px;
font-weight: 600;
}

.video-badges > i {
margin-right: 5px;
}
9 changes: 9 additions & 0 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1008,3 +1008,12 @@ default_user_preferences:
## Default: false
##
#extend_desc: false

##
## Allows excluding videos that are exclusive to channel members
## from the frontend
##
## Accepted values: true, false
## Default: false
##
#exclude_members_only_videos: false
4 changes: 3 additions & 1 deletion locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,5 +501,7 @@
"toggle_theme": "Toggle Theme",
"carousel_slide": "Slide {{current}} of {{total}}",
"carousel_skip": "Skip the Carousel",
"carousel_go_to": "Go to slide `x`"
"carousel_go_to": "Go to slide `x`",
"video_badges_members_only": "Members only",
"preferences_exclude_members_only_videos_label": "Hide channel member-only videos"
}
1 change: 1 addition & 0 deletions src/invidious/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct ConfigPreferences
property vr_mode : Bool = true
property show_nick : Bool = true
property save_player_pos : Bool = false
property exclude_members_only_videos : Bool = false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we exclude the channel only videos by default?


def to_tuple
{% begin %}
Expand Down
2 changes: 2 additions & 0 deletions src/invidious/helpers/serialized_yt_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum VideoBadges
VR180
VR360
ClosedCaptions
MembersOnly
end

struct SearchVideo
Expand Down Expand Up @@ -133,6 +134,7 @@ struct SearchVideo
json.field "isVr360", self.badges.vr360?
json.field "is3d", self.badges.three_d?
json.field "hasCaptions", self.badges.closed_captions?
json.field "isMembersOnly", self.badges.members_only?
end
end

Expand Down
5 changes: 5 additions & 0 deletions src/invidious/routes/preferences.cr
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ module Invidious::Routes::PreferencesRoute
notifications_only ||= "off"
notifications_only = notifications_only == "on"

exclude_members_only_videos = env.params.body["exclude_members_only_videos"]?.try &.as(String)
exclude_members_only_videos ||= "off"
exclude_members_only_videos = exclude_members_only_videos == "on"

# Convert to JSON and back again to take advantage of converters used for compatibility
preferences = Preferences.from_json({
annotations: annotations,
Expand Down Expand Up @@ -180,6 +184,7 @@ module Invidious::Routes::PreferencesRoute
vr_mode: vr_mode,
show_nick: show_nick,
save_player_pos: save_player_pos,
exclude_members_only_videos: exclude_members_only_videos,
}.to_json)

if user = env.get? "user"
Expand Down
2 changes: 2 additions & 0 deletions src/invidious/user/preferences.cr
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ struct Preferences
property volume : Int32 = CONFIG.default_user_preferences.volume
property save_player_pos : Bool = CONFIG.default_user_preferences.save_player_pos

property exclude_members_only_videos : Bool = CONFIG.default_user_preferences.exclude_members_only_videos

module BoolToString
def self.to_json(value : String, json : JSON::Builder)
json.string value
Expand Down
10 changes: 10 additions & 0 deletions src/invidious/views/components/item.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@
</div>
<% end %>
</div>
<% if item.responds_to?(:badges) && !item.badges.none? %>
<div class="video-card-row flexible video-badges">
<%
# TODO Other types of badges
%>
<% if item.badges.members_only? %>
<span><i class="icon ion ion-md-lock"></i><%=translate(locale, "video_badges_members_only")%></span>
<% end %>
</div>
<%end%>
<% end %>
</div>
</div>
3 changes: 3 additions & 0 deletions src/invidious/views/components/items_paginated.ecr
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<%= page_nav_html %>
<% exclude_members_only_videos = env.get("preferences").as(Preferences).exclude_members_only_videos %>

<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? %>
<%= rendered "components/item" %>
<%- end -%>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/invidious/views/feeds/trending.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

<div class="pure-g">
<% trending.each do |item| %>
<% next %>
<%= rendered "components/item" %>
<% end %>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/invidious/views/user/preferences.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@
</select>
<% end %>
</div>

<div class="pure-control-group">
<label for="exclude_members_only_videos"><%= translate(locale, "preferences_exclude_members_only_videos_label") %></label>
<input name="exclude_members_only_videos" id="exclude_members_only_videos" type="checkbox" <% if preferences.exclude_members_only_videos %>checked<% end %>>
</div>

<% if env.get? "user" %>
<div class="pure-control-group">
<label for="show_nick"><%= translate(locale, "preferences_show_nick_label") %></label>
Expand Down
4 changes: 4 additions & 0 deletions src/invidious/yt_backend/extractors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ private module Parsers
when "Premium"
# 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
else nil # Ignore
end
end
Expand Down