Merge pull request #959 from FireMasterK/playlist-info-item-uploader

Add uploaderUrl and uploaderVerified to PlaylistInfoItem.
This commit is contained in:
Tobi 2022-10-31 13:10:33 +01:00 committed by GitHub
commit eb40bb8458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 139 additions and 2 deletions

View File

@ -2,9 +2,13 @@ package org.schabi.newpipe.extractor.playlist;
import org.schabi.newpipe.extractor.InfoItem;
import javax.annotation.Nullable;
public class PlaylistInfoItem extends InfoItem {
private String uploaderName;
private String uploaderUrl;
private boolean uploaderVerified;
/**
* How many streams this playlist have
*/
@ -23,6 +27,23 @@ public class PlaylistInfoItem extends InfoItem {
this.uploaderName = uploaderName;
}
@Nullable
public String getUploaderUrl() {
return uploaderUrl;
}
public void setUploaderUrl(@Nullable 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 {