[YouTube] Avoid using Consumer

This commit is contained in:
Stypox 2023-08-06 12:57:31 +02:00
parent ef67c7cd74
commit e34b4f1978
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 22 additions and 26 deletions

View File

@ -23,7 +23,6 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.Consumer;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeChannelHelper.getChannelResponse; import static org.schabi.newpipe.extractor.services.youtube.YoutubeChannelHelper.getChannelResponse;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeChannelHelper.resolveChannelId; import static org.schabi.newpipe.extractor.services.youtube.YoutubeChannelHelper.resolveChannelId;
@ -299,20 +298,20 @@ public class YoutubeChannelTabExtractor extends ChannelTabExtractor {
.getObject("content"); .getObject("content");
if (richItem.has("videoRenderer")) { if (richItem.has("videoRenderer")) {
getCommitVideoConsumer(collector, timeAgoParser, channelIds).accept( getCommitVideoConsumer(collector, timeAgoParser, channelIds,
richItem.getObject("videoRenderer")); richItem.getObject("videoRenderer"));
} else if (richItem.has("reelItemRenderer")) { } else if (richItem.has("reelItemRenderer")) {
getCommitReelItemConsumer(collector, timeAgoParser, channelIds).accept( getCommitReelItemConsumer(collector, timeAgoParser, channelIds,
richItem.getObject("reelItemRenderer")); richItem.getObject("reelItemRenderer"));
} else if (richItem.has("playlistRenderer")) { } else if (richItem.has("playlistRenderer")) {
getCommitPlaylistConsumer(collector, channelIds).accept( getCommitPlaylistConsumer(collector, channelIds,
item.getObject("playlistRenderer")); item.getObject("playlistRenderer"));
} }
} else if (item.has("gridVideoRenderer")) { } else if (item.has("gridVideoRenderer")) {
getCommitVideoConsumer(collector, timeAgoParser, channelIds).accept( getCommitVideoConsumer(collector, timeAgoParser, channelIds,
item.getObject("gridVideoRenderer")); item.getObject("gridVideoRenderer"));
} else if (item.has("gridPlaylistRenderer")) { } else if (item.has("gridPlaylistRenderer")) {
getCommitPlaylistConsumer(collector, channelIds).accept( getCommitPlaylistConsumer(collector, channelIds,
item.getObject("gridPlaylistRenderer")); item.getObject("gridPlaylistRenderer"));
} else if (item.has("gridChannelRenderer")) { } else if (item.has("gridChannelRenderer")) {
collector.commit(new YoutubeChannelInfoItemExtractor( collector.commit(new YoutubeChannelInfoItemExtractor(
@ -336,13 +335,12 @@ public class YoutubeChannelTabExtractor extends ChannelTabExtractor {
return Optional.empty(); return Optional.empty();
} }
@Nonnull private void getCommitVideoConsumer(@Nonnull final MultiInfoItemsCollector collector,
private Consumer<JsonObject> getCommitVideoConsumer( @Nonnull final TimeAgoParser timeAgoParser,
@Nonnull final MultiInfoItemsCollector collector, @Nonnull final List<String> channelIds,
@Nonnull final TimeAgoParser timeAgoParser, @Nonnull final JsonObject jsonObject) {
@Nonnull final List<String> channelIds) { collector.commit(
return videoRenderer -> collector.commit( new YoutubeStreamInfoItemExtractor(jsonObject, timeAgoParser) {
new YoutubeStreamInfoItemExtractor(videoRenderer, timeAgoParser) {
@Override @Override
public String getUploaderName() throws ParsingException { public String getUploaderName() throws ParsingException {
if (channelIds.size() >= 2) { if (channelIds.size() >= 2) {
@ -361,13 +359,12 @@ public class YoutubeChannelTabExtractor extends ChannelTabExtractor {
}); });
} }
@Nonnull private void getCommitReelItemConsumer(@Nonnull final MultiInfoItemsCollector collector,
private Consumer<JsonObject> getCommitReelItemConsumer( @Nonnull final TimeAgoParser timeAgoParser,
@Nonnull final MultiInfoItemsCollector collector, @Nonnull final List<String> channelIds,
@Nonnull final TimeAgoParser timeAgoParser, @Nonnull final JsonObject jsonObject) {
@Nonnull final List<String> channelIds) { collector.commit(
return reelItemRenderer -> collector.commit( new YoutubeReelInfoItemExtractor(jsonObject, timeAgoParser) {
new YoutubeReelInfoItemExtractor(reelItemRenderer, timeAgoParser) {
@Override @Override
public String getUploaderName() throws ParsingException { public String getUploaderName() throws ParsingException {
if (channelIds.size() >= 2) { if (channelIds.size() >= 2) {
@ -386,12 +383,11 @@ public class YoutubeChannelTabExtractor extends ChannelTabExtractor {
}); });
} }
@Nonnull private void getCommitPlaylistConsumer(@Nonnull final MultiInfoItemsCollector collector,
private Consumer<JsonObject> getCommitPlaylistConsumer( @Nonnull final List<String> channelIds,
@Nonnull final MultiInfoItemsCollector collector, @Nonnull final JsonObject jsonObject) {
@Nonnull final List<String> channelIds) { collector.commit(
return playlistRenderer -> collector.commit( new YoutubePlaylistInfoItemExtractor(jsonObject) {
new YoutubePlaylistInfoItemExtractor(playlistRenderer) {
@Override @Override
public String getUploaderName() throws ParsingException { public String getUploaderName() throws ParsingException {
if (channelIds.size() >= 2) { if (channelIds.size() >= 2) {