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

Fix avatar,banner and description extraction for channels #1202

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,20 @@ public List<Image> getAvatars() throws ParsingException {
return channelHeader.map(header -> {
switch (header.headerType) {
case PAGE:
return header.json.getObject("content")
final JsonObject image = header.json.getObject("content")
.getObject("pageHeaderViewModel")
.getObject("image");
if (image.has("contentPreviewImageViewModel")) {
return image.getObject("contentPreviewImageViewModel")
.getObject("image")
.getObject("contentPreviewImageViewModel")
.getArray("sources");
} else {
return image.getObject("decoratedAvatarViewModel")
.getObject("avatar")
.getObject("avatarViewModel")
.getObject("image")
.getArray("sources");
}

case INTERACTIVE_TABBED:
return header.json.getObject("boxArt")
Expand All @@ -235,10 +243,20 @@ public List<Image> getBanners() {
return List.of();
}

// No banner is available on pageHeaderRenderer headers
return channelHeader.filter(header -> header.headerType != HeaderType.PAGE)
.map(header -> header.json.getObject("banner")
.getArray("thumbnails"))
return channelHeader.map(header -> {
switch (header.headerType) {
case PAGE:
return header.json.getObject("content")
.getObject("pageHeaderViewModel")
.getObject("banner")
.getObject("imageBannerViewModel")
.getObject("image")
.getArray("sources");
default:
return header.json.getObject("banner")
.getArray("thumbnails");
}
})
.map(YoutubeParsingHelper::getImagesFromThumbnailsArray)
.orElse(List.of());
}
Expand Down Expand Up @@ -303,11 +321,6 @@ public String getDescription() throws ParsingException {
if (channelHeader.isPresent()) {
final ChannelHeader header = channelHeader.get();

if (header.headerType == HeaderType.PAGE) {
// A pageHeaderRenderer doesn't contain a description
return null;
}

if (header.headerType == HeaderType.INTERACTIVE_TABBED) {
/*
In an interactiveTabbedHeaderRenderer, the real description, is only available
Expand Down