[PeerTube] Apply changes in InfoItemExtractors

Also lower the visibility of attributes of channels and playlists InfoItems to
private.
This commit is contained in:
AudricV 2022-07-27 19:36:44 +02:00
parent 6f8331524b
commit 0a6011a50e
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
4 changed files with 45 additions and 48 deletions

View File

@ -1,22 +1,24 @@
package org.schabi.newpipe.extractor.services.peertube.extractors; package org.schabi.newpipe.extractor.services.peertube.extractors;
import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonObject;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor;
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; import java.util.List;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getAvatarsFromOwnerAccountOrVideoChannelObject;
public class PeertubeChannelInfoItemExtractor implements ChannelInfoItemExtractor { public class PeertubeChannelInfoItemExtractor implements ChannelInfoItemExtractor {
final JsonObject item; private final JsonObject item;
final JsonObject uploader; private final String baseUrl;
final String baseUrl;
public PeertubeChannelInfoItemExtractor(@Nonnull final JsonObject item, public PeertubeChannelInfoItemExtractor(@Nonnull final JsonObject item,
@Nonnull final String baseUrl) { @Nonnull final String baseUrl) {
this.item = item; this.item = item;
this.uploader = item.getObject("uploader");
this.baseUrl = baseUrl; this.baseUrl = baseUrl;
} }
@ -30,14 +32,10 @@ public class PeertubeChannelInfoItemExtractor implements ChannelInfoItemExtracto
return item.getString("url"); return item.getString("url");
} }
@Nonnull
@Override @Override
public String getThumbnailUrl() throws ParsingException { public List<Image> getThumbnails() throws ParsingException {
return item.getArray("avatars").stream() return getAvatarsFromOwnerAccountOrVideoChannelObject(baseUrl, item);
.filter(JsonObject.class::isInstance)
.map(JsonObject.class::cast)
.max(Comparator.comparingInt(avatar -> avatar.getInt("width")))
.map(avatar -> baseUrl + avatar.getString("path"))
.orElse(null);
} }
@Override @Override

View File

@ -6,21 +6,24 @@ import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonWriter; import com.grack.nanojson.JsonWriter;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor; import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.JsonUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import static org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeCommentsExtractor.CHILDREN; import static org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeCommentsExtractor.CHILDREN;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getAvatarsFromOwnerAccountOrVideoChannelObject;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.parseDateFrom;
public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtractor { public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtractor {
@Nonnull @Nonnull
@ -52,15 +55,10 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
return url + "/" + getCommentId(); return url + "/" + getCommentId();
} }
@Nonnull
@Override @Override
public String getThumbnailUrl() { public List<Image> getThumbnails() {
String value; return getUploaderAvatars();
try {
value = JsonUtils.getString(item, "account.avatar.path");
} catch (final Exception e) {
value = "/client/assets/images/default-avatar.png";
}
return baseUrl + value;
} }
@Override @Override
@ -76,7 +74,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
@Override @Override
public DateWrapper getUploadDate() throws ParsingException { public DateWrapper getUploadDate() throws ParsingException {
final String textualUploadDate = getTextualUploadDate(); final String textualUploadDate = getTextualUploadDate();
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate)); return new DateWrapper(parseDateFrom(textualUploadDate));
} }
@Override @Override
@ -97,15 +95,10 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
return Objects.toString(item.getLong("id"), null); return Objects.toString(item.getLong("id"), null);
} }
@Nonnull
@Override @Override
public String getUploaderAvatarUrl() { public List<Image> getUploaderAvatars() {
String value; return getAvatarsFromOwnerAccountOrVideoChannelObject(baseUrl, item.getObject("account"));
try {
value = JsonUtils.getString(item, "account.avatar.path");
} catch (final Exception e) {
value = "/client/assets/images/default-avatar.png";
}
return baseUrl + value;
} }
@Override @Override

View File

@ -2,19 +2,22 @@ package org.schabi.newpipe.extractor.services.peertube.extractors;
import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonObject;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.Description;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.List;
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getThumbnailsFromPlaylistOrVideoItem;
public class PeertubePlaylistInfoItemExtractor implements PlaylistInfoItemExtractor { public class PeertubePlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
final JsonObject item; private final JsonObject item;
final JsonObject uploader; private final JsonObject uploader;
final String baseUrl; private final String baseUrl;
public PeertubePlaylistInfoItemExtractor(@Nonnull final JsonObject item, public PeertubePlaylistInfoItemExtractor(@Nonnull final JsonObject item,
@Nonnull final String baseUrl) { @Nonnull final String baseUrl) {
@ -33,9 +36,10 @@ public class PeertubePlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
return item.getString("url"); return item.getString("url");
} }
@Nonnull
@Override @Override
public String getThumbnailUrl() throws ParsingException { public List<Image> getThumbnails() throws ParsingException {
return baseUrl + item.getString("thumbnailPath"); return getThumbnailsFromPlaylistOrVideoItem(baseUrl, item);
} }
@Override @Override

View File

@ -1,15 +1,20 @@
package org.schabi.newpipe.extractor.services.peertube.extractors; package org.schabi.newpipe.extractor.services.peertube.extractors;
import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonObject;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor; import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.JsonUtils;
import javax.annotation.Nullable; import javax.annotation.Nonnull;
import java.util.List;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getAvatarsFromOwnerAccountOrVideoChannelObject;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getThumbnailsFromPlaylistOrVideoItem;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.parseDateFrom;
public class PeertubeStreamInfoItemExtractor implements StreamInfoItemExtractor { public class PeertubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
@ -27,9 +32,10 @@ public class PeertubeStreamInfoItemExtractor implements StreamInfoItemExtractor
return ServiceList.PeerTube.getStreamLHFactory().fromId(uuid, baseUrl).getUrl(); return ServiceList.PeerTube.getStreamLHFactory().fromId(uuid, baseUrl).getUrl();
} }
@Nonnull
@Override @Override
public String getThumbnailUrl() throws ParsingException { public List<Image> getThumbnails() throws ParsingException {
return baseUrl + JsonUtils.getString(item, "thumbnailPath"); return getThumbnailsFromPlaylistOrVideoItem(baseUrl, item);
} }
@Override @Override
@ -56,14 +62,10 @@ public class PeertubeStreamInfoItemExtractor implements StreamInfoItemExtractor
.fromId("accounts/" + name + "@" + host, baseUrl).getUrl(); .fromId("accounts/" + name + "@" + host, baseUrl).getUrl();
} }
@Nullable @Nonnull
@Override @Override
public String getUploaderAvatarUrl() { public List<Image> getUploaderAvatars() {
final JsonObject account = item.getObject("account"); return getAvatarsFromOwnerAccountOrVideoChannelObject(baseUrl, item.getObject("account"));
if (account.has("avatar") && !account.isNull("avatar")) {
return baseUrl + account.getObject("avatar").getString("path");
}
return null;
} }
@Override @Override
@ -89,7 +91,7 @@ public class PeertubeStreamInfoItemExtractor implements StreamInfoItemExtractor
return null; return null;
} }
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate)); return new DateWrapper(parseDateFrom(textualUploadDate));
} }
@Override @Override