Add uploader url and verified to PlaylistInfoItem.

This commit is contained in:
Kavin 2022-10-29 22:43:04 +01:00
parent 430504b4b5
commit 6a256d0631
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
10 changed files with 136 additions and 2 deletions

View file

@ -5,6 +5,8 @@ import org.schabi.newpipe.extractor.InfoItem;
public class PlaylistInfoItem extends InfoItem {
private String uploaderName;
private String uploaderUrl;
private boolean uploaderVerified;
/**
* How many streams this playlist have
*/
@ -23,6 +25,22 @@ public class PlaylistInfoItem extends InfoItem {
this.uploaderName = uploaderName;
}
public String getUploaderUrl() {
return uploaderUrl;
}
public void setUploaderUrl(final String uploaderUrl) {
this.uploaderUrl = uploaderUrl;
}
public boolean isUploaderVerified() {
return uploaderVerified;
}
public void setUploaderVerified(final boolean uploaderVerified) {
this.uploaderVerified = uploaderVerified;
}
public long getStreamCount() {
return streamCount;
}

View file

@ -13,6 +13,18 @@ public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
*/
String getUploaderName() throws ParsingException;
/**
* Get the uploader url
* @return the uploader url
*/
String getUploaderUrl() throws ParsingException;
/**
* Get whether the uploader is verified
* @return whether the uploader is verified
*/
boolean isUploaderVerified() throws ParsingException;
/**
* Get the number of streams
* @return the number of streams

View file

@ -21,6 +21,16 @@ public class PlaylistInfoItemsCollector
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploaderUrl(extractor.getUploaderUrl());
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploaderVerified(extractor.isUploaderVerified());
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (final Exception e) {

View file

@ -20,6 +20,16 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
.split(" by")[0];
}
@Override
public String getUploaderUrl() {
return null;
}
@Override
public boolean isUploaderVerified() {
return false;
}
@Override
public long getStreamCount() {
final String length = resultInfo.getElementsByClass("length").text();

View file

@ -18,6 +18,16 @@ public class BandcampPlaylistInfoItemFeaturedExtractor implements PlaylistInfoIt
return featuredStory.getString("band_name");
}
@Override
public String getUploaderUrl() {
return null;
}
@Override
public boolean isUploaderVerified() {
return false;
}
@Override
public long getStreamCount() {
return featuredStory.getInt("num_streamable_tracks");

View file

@ -38,6 +38,16 @@ public class BandcampRelatedPlaylistInfoItemExtractor implements PlaylistInfoIte
return relatedAlbum.getElementsByClass("by-artist").text().replace("by ", "");
}
@Override
public String getUploaderUrl() throws ParsingException {
return null;
}
@Override
public boolean isUploaderVerified() throws ParsingException {
return false;
}
@Override
public long getStreamCount() throws ParsingException {
return -1;

View file

@ -81,6 +81,16 @@ public class SoundcloudPlaylistInfoItemExtractor implements PlaylistInfoItemExtr
}
}
@Override
public String getUploaderUrl() {
return null;
}
@Override
public boolean isUploaderVerified() {
return false;
}
@Override
public long getStreamCount() {
return itemObject.getLong("track_count");

View file

@ -1014,6 +1014,28 @@ public final class YoutubeParsingHelper {
return getTextFromObject(textObject, false);
}
@Nullable
public static String getUrlFromObject(final JsonObject textObject) throws ParsingException {
if (isNullOrEmpty(textObject)) {
return null;
}
if (textObject.getArray("runs").isEmpty()) {
return null;
}
for (final Object textPart : textObject.getArray("runs")) {
final String url = getUrlFromNavigationEndpoint(((JsonObject) textPart)
.getObject("navigationEndpoint"));
if (!isNullOrEmpty(url)) {
return url;
}
}
return null;
}
@Nullable
public static String getTextAtKey(@Nonnull final JsonObject jsonObject, final String theKey)
throws ParsingException {

View file

@ -47,10 +47,22 @@ public class YoutubeMixOrPlaylistInfoItemExtractor implements PlaylistInfoItemEx
@Override
public String getUploaderName() throws ParsingException {
// this will be "YouTube" for mixes
// this will be a list of uploaders for mixes
return YoutubeParsingHelper.getTextFromObject(mixInfoItem.getObject("longBylineText"));
}
@Override
public String getUploaderUrl() throws ParsingException {
// They're auto-generated, so there's no uploader
return null;
}
@Override
public boolean isUploaderVerified() throws ParsingException {
// They're auto-generated, so there's no uploader
return false;
}
@Override
public long getStreamCount() throws ParsingException {
final String countString = YoutubeParsingHelper.getTextFromObject(

View file

@ -1,14 +1,16 @@
package org.schabi.newpipe.extractor.services.youtube.extractors;
import com.grack.nanojson.JsonObject;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Utils;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.fixThumbnailUrl;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromObject;
public class YoutubePlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
private final JsonObject playlistInfoItem;
@ -57,6 +59,24 @@ public class YoutubePlaylistInfoItemExtractor implements PlaylistInfoItemExtract
}
}
@Override
public String getUploaderUrl() throws ParsingException {
try {
return getUrlFromObject(playlistInfoItem.getObject("longBylineText"));
} catch (final Exception e) {
throw new ParsingException("Could not get uploader url", e);
}
}
@Override
public boolean isUploaderVerified() throws ParsingException {
try {
return YoutubeParsingHelper.isVerified(playlistInfoItem.getArray("ownerBadges"));
} catch (final Exception e) {
throw new ParsingException("Could not get uploader verification info", e);
}
}
@Override
public long getStreamCount() throws ParsingException {
try {