Merge pull request #959 from FireMasterK/playlist-info-item-uploader
Add uploaderUrl and uploaderVerified to PlaylistInfoItem.
This commit is contained in:
commit
eb40bb8458
10 changed files with 139 additions and 2 deletions
|
@ -2,9 +2,13 @@ package org.schabi.newpipe.extractor.playlist;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class PlaylistInfoItem extends InfoItem {
|
public class PlaylistInfoItem extends InfoItem {
|
||||||
|
|
||||||
private String uploaderName;
|
private String uploaderName;
|
||||||
|
private String uploaderUrl;
|
||||||
|
private boolean uploaderVerified;
|
||||||
/**
|
/**
|
||||||
* How many streams this playlist have
|
* How many streams this playlist have
|
||||||
*/
|
*/
|
||||||
|
@ -23,6 +27,23 @@ public class PlaylistInfoItem extends InfoItem {
|
||||||
this.uploaderName = uploaderName;
|
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() {
|
public long getStreamCount() {
|
||||||
return streamCount;
|
return streamCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,18 @@ public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
|
||||||
*/
|
*/
|
||||||
String getUploaderName() throws ParsingException;
|
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
|
* Get the number of streams
|
||||||
* @return the number of streams
|
* @return the number of streams
|
||||||
|
|
|
@ -21,6 +21,16 @@ public class PlaylistInfoItemsCollector
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
addError(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 {
|
try {
|
||||||
resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
|
resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
|
|
@ -20,6 +20,16 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac
|
||||||
.split(" by")[0];
|
.split(" by")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUploaderUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUploaderVerified() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getStreamCount() {
|
public long getStreamCount() {
|
||||||
final String length = resultInfo.getElementsByClass("length").text();
|
final String length = resultInfo.getElementsByClass("length").text();
|
||||||
|
|
|
@ -18,6 +18,16 @@ public class BandcampPlaylistInfoItemFeaturedExtractor implements PlaylistInfoIt
|
||||||
return featuredStory.getString("band_name");
|
return featuredStory.getString("band_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUploaderUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUploaderVerified() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getStreamCount() {
|
public long getStreamCount() {
|
||||||
return featuredStory.getInt("num_streamable_tracks");
|
return featuredStory.getInt("num_streamable_tracks");
|
||||||
|
|
|
@ -38,6 +38,16 @@ public class BandcampRelatedPlaylistInfoItemExtractor implements PlaylistInfoIte
|
||||||
return relatedAlbum.getElementsByClass("by-artist").text().replace("by ", "");
|
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
|
@Override
|
||||||
public long getStreamCount() throws ParsingException {
|
public long getStreamCount() throws ParsingException {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -81,6 +81,16 @@ public class SoundcloudPlaylistInfoItemExtractor implements PlaylistInfoItemExtr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUploaderUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUploaderVerified() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getStreamCount() {
|
public long getStreamCount() {
|
||||||
return itemObject.getLong("track_count");
|
return itemObject.getLong("track_count");
|
||||||
|
|
|
@ -1014,6 +1014,28 @@ public final class YoutubeParsingHelper {
|
||||||
return getTextFromObject(textObject, false);
|
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
|
@Nullable
|
||||||
public static String getTextAtKey(@Nonnull final JsonObject jsonObject, final String theKey)
|
public static String getTextAtKey(@Nonnull final JsonObject jsonObject, final String theKey)
|
||||||
throws ParsingException {
|
throws ParsingException {
|
||||||
|
|
|
@ -47,10 +47,22 @@ public class YoutubeMixOrPlaylistInfoItemExtractor implements PlaylistInfoItemEx
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderName() throws ParsingException {
|
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"));
|
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
|
@Override
|
||||||
public long getStreamCount() throws ParsingException {
|
public long getStreamCount() throws ParsingException {
|
||||||
final String countString = YoutubeParsingHelper.getTextFromObject(
|
final String countString = YoutubeParsingHelper.getTextFromObject(
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
|
|
||||||
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.services.youtube.YoutubeParsingHelper;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
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.fixThumbnailUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
|
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 {
|
public class YoutubePlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
||||||
private final JsonObject playlistInfoItem;
|
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
|
@Override
|
||||||
public long getStreamCount() throws ParsingException {
|
public long getStreamCount() throws ParsingException {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue