Skip to content

Commit 2a8729a

Browse files
TobiGrStypox
andcommitted
Apply suggestions
Co-authored-by: Stypox <stypox@pm.me>
1 parent d75a997 commit 2a8729a

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeParsingHelper.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,12 @@ public static void collectStreamsFrom(final InfoItemsCollector collector,
111111
final InfoItemExtractor extractor;
112112
if (sepia) {
113113
extractor = new PeertubeSepiaStreamInfoItemExtractor(item, baseUrl);
114+
} else if (isPlaylistInfoItem) {
115+
extractor = new PeertubePlaylistInfoItemExtractor(item, baseUrl);
116+
} else if (isChannelInfoItem) {
117+
extractor = new PeertubeChannelInfoItemExtractor(item, baseUrl);
114118
} else {
115-
if (isPlaylistInfoItem) {
116-
extractor = new PeertubePlaylistInfoItemExtractor(item, baseUrl);
117-
} else if (isChannelInfoItem) {
118-
extractor = new PeertubeChannelInfoItemExtractor(item, baseUrl);
119-
} else {
120-
extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
121-
}
119+
extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
122120
}
123121
collector.commit(extractor);
124122
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeChannelInfoItemExtractor.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package org.schabi.newpipe.extractor.services.peertube.extractors;
22

3-
import com.grack.nanojson.JsonArray;
43
import com.grack.nanojson.JsonObject;
5-
64
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
75
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
86
import org.schabi.newpipe.extractor.exceptions.ParsingException;
97

108
import javax.annotation.Nonnull;
9+
import java.util.Comparator;
1110

1211
public class PeertubeChannelInfoItemExtractor implements ChannelInfoItemExtractor {
1312

@@ -33,19 +32,12 @@ public String getUrl() throws ParsingException {
3332

3433
@Override
3534
public String getThumbnailUrl() throws ParsingException {
36-
final JsonArray avatars = item.getArray("avatars");
37-
if (avatars.isEmpty()) {
38-
return null;
39-
}
40-
int highestRes = -1;
41-
JsonObject avatar = null;
42-
for (final Object a: avatars) {
43-
if (((JsonObject) a).getInt("width") > highestRes) {
44-
avatar = (JsonObject) a;
45-
highestRes = avatar.getInt("width");
46-
}
47-
}
48-
return baseUrl + avatar.getString("path");
35+
return item.getArray("avatars").stream()
36+
.filter(JsonObject.class::isInstance)
37+
.map(JsonObject.class::cast)
38+
.max(Comparator.comparingInt(avatar -> avatar.getInt("width")))
39+
.map(avatar -> baseUrl + avatar.getString("path"))
40+
.orElse(null);
4941
}
5042

5143
@Override

0 commit comments

Comments
 (0)