Apply suggestions

Co-authored-by: Stypox <stypox@pm.me>
This commit is contained in:
TobiGr 2022-12-31 18:23:28 +01:00
parent d75a997611
commit 2a8729aeb2
2 changed files with 12 additions and 22 deletions

View File

@ -111,14 +111,12 @@ public final class PeertubeParsingHelper {
final InfoItemExtractor extractor; final InfoItemExtractor extractor;
if (sepia) { if (sepia) {
extractor = new PeertubeSepiaStreamInfoItemExtractor(item, baseUrl); extractor = new PeertubeSepiaStreamInfoItemExtractor(item, baseUrl);
} else if (isPlaylistInfoItem) {
extractor = new PeertubePlaylistInfoItemExtractor(item, baseUrl);
} else if (isChannelInfoItem) {
extractor = new PeertubeChannelInfoItemExtractor(item, baseUrl);
} else { } else {
if (isPlaylistInfoItem) { extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
extractor = new PeertubePlaylistInfoItemExtractor(item, baseUrl);
} else if (isChannelInfoItem) {
extractor = new PeertubeChannelInfoItemExtractor(item, baseUrl);
} else {
extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
}
} }
collector.commit(extractor); collector.commit(extractor);
} }

View File

@ -1,13 +1,12 @@
package org.schabi.newpipe.extractor.services.peertube.extractors; package org.schabi.newpipe.extractor.services.peertube.extractors;
import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonObject;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor; import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Comparator;
public class PeertubeChannelInfoItemExtractor implements ChannelInfoItemExtractor { public class PeertubeChannelInfoItemExtractor implements ChannelInfoItemExtractor {
@ -33,19 +32,12 @@ public class PeertubeChannelInfoItemExtractor implements ChannelInfoItemExtracto
@Override @Override
public String getThumbnailUrl() throws ParsingException { public String getThumbnailUrl() throws ParsingException {
final JsonArray avatars = item.getArray("avatars"); return item.getArray("avatars").stream()
if (avatars.isEmpty()) { .filter(JsonObject.class::isInstance)
return null; .map(JsonObject.class::cast)
} .max(Comparator.comparingInt(avatar -> avatar.getInt("width")))
int highestRes = -1; .map(avatar -> baseUrl + avatar.getString("path"))
JsonObject avatar = null; .orElse(null);
for (final Object a: avatars) {
if (((JsonObject) a).getInt("width") > highestRes) {
avatar = (JsonObject) a;
highestRes = avatar.getInt("width");
}
}
return baseUrl + avatar.getString("path");
} }
@Override @Override