Skip to content
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

[Youtube] Mark members-only videos #1280

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,18 @@ public boolean isShortFormContent() throws ParsingException {
throw new ParsingException("Could not determine if this is short-form content", e);
}
}

@Nonnull
@Override
public boolean requiresMembership() throws ParsingException {
final JsonArray badges = videoInfo.getArray("badges");
for (final Object badge : badges) {
if (((JsonObject) badge).getObject("metadataBadgeRenderer")
.getString("style", "").equals("BADGE_STYLE_TYPE_MEMBERS_ONLY")) {
return true;
}
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,16 @@ public boolean isShortFormContent() throws ParsingException {
return false;
}

/**
* Whether the stream is only available to channel members.
*
* @return whether the stream is only available to channel members.
* @throws ParsingException if there is an error in the extraction
*/
public boolean requiresMembership() throws ParsingException {
return false;
}

public enum Privacy {
PUBLIC,
UNLISTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ private static void extractOptionalData(final StreamInfo streamInfo,
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setRequiresMembership(extractor.requiresMembership());
} catch (final Exception e) {
streamInfo.addError(e);
}

streamInfo.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo,
extractor));
Expand Down Expand Up @@ -381,6 +386,7 @@ private static void extractOptionalData(final StreamInfo streamInfo,
private List<StreamSegment> streamSegments = List.of();
private List<MetaInfo> metaInfo = List.of();
private boolean shortFormContent = false;
private boolean membersOnly = false;

/**
* Preview frames, e.g. for the storyboard / seekbar thumbnail preview
Expand Down Expand Up @@ -727,4 +733,12 @@ public boolean isShortFormContent() {
public void setShortFormContent(final boolean isShortFormContent) {
this.shortFormContent = isShortFormContent;
}

public boolean requiresMembership() {
return membersOnly;
}

public void setRequiresMembership(final boolean requiresMembership) {
this.membersOnly = requiresMembership;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class StreamInfoItem extends InfoItem {
private List<Image> uploaderAvatars = List.of();
private boolean uploaderVerified = false;
private boolean shortFormContent = false;
private boolean requiresMembership = false;

public StreamInfoItem(final int serviceId,
final String url,
Expand Down Expand Up @@ -143,6 +144,14 @@ public void setShortFormContent(final boolean shortFormContent) {
this.shortFormContent = shortFormContent;
}

public boolean requiresMembership() {
return requiresMembership;
}

public void setRequiresMembership(final boolean requiresMembership) {
this.requiresMembership = requiresMembership;
}

@Override
public String toString() {
return "StreamInfoItem{"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,14 @@ default String getShortDescription() throws ParsingException {
default boolean isShortFormContent() throws ParsingException {
return false;
}

/**
* Whether the stream is only available to channel members.
*
* @return whether the stream is only available to channel members.
* @throws ParsingException if there is an error in the extraction
*/
default boolean requiresMembership() throws ParsingException {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public StreamInfoItem extract(final StreamInfoItemExtractor extractor) throws Pa
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setRequiresMembership(extractor.requiresMembership());
} catch (final Exception e) {
addError(e);
}

return resultItem;
}
Expand Down