From 6a256d063168fff202c2e6530403569aaf332991 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 29 Oct 2022 22:43:04 +0100 Subject: [PATCH 1/2] Add uploader url and verified to PlaylistInfoItem. --- .../extractor/playlist/PlaylistInfoItem.java | 18 +++++++++++++++ .../playlist/PlaylistInfoItemExtractor.java | 12 ++++++++++ .../playlist/PlaylistInfoItemsCollector.java | 10 +++++++++ .../BandcampPlaylistInfoItemExtractor.java | 10 +++++++++ ...campPlaylistInfoItemFeaturedExtractor.java | 10 +++++++++ ...dcampRelatedPlaylistInfoItemExtractor.java | 10 +++++++++ .../SoundcloudPlaylistInfoItemExtractor.java | 10 +++++++++ .../youtube/YoutubeParsingHelper.java | 22 +++++++++++++++++++ ...YoutubeMixOrPlaylistInfoItemExtractor.java | 14 +++++++++++- .../YoutubePlaylistInfoItemExtractor.java | 22 ++++++++++++++++++- 10 files changed, 136 insertions(+), 2 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java index 92ade89b..967fef08 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java @@ -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; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java index be9b1026..ccb3c2c7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java @@ -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 diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemsCollector.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemsCollector.java index 328f1261..3184c67d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemsCollector.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemsCollector.java @@ -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) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java index e31344ea..4bc4a1c6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java @@ -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(); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemFeaturedExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemFeaturedExtractor.java index 060d461f..0808e10c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemFeaturedExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemFeaturedExtractor.java @@ -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"); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRelatedPlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRelatedPlaylistInfoItemExtractor.java index 74e4997b..d485b0b3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRelatedPlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRelatedPlaylistInfoItemExtractor.java @@ -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; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistInfoItemExtractor.java index f152a505..d97fe5af 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistInfoItemExtractor.java @@ -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"); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index 273d17ab..d56dc191 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -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 { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixOrPlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixOrPlaylistInfoItemExtractor.java index 4ed42887..4847302e 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixOrPlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixOrPlaylistInfoItemExtractor.java @@ -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( diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistInfoItemExtractor.java index 14895aac..ef09a505 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistInfoItemExtractor.java @@ -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 { From b441910257a421472edd0874594a1c528819e42a Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sun, 30 Oct 2022 13:36:04 +0000 Subject: [PATCH 2/2] Mark uploaderUrl as nullable. --- .../schabi/newpipe/extractor/playlist/PlaylistInfoItem.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java index 967fef08..852a1819 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java @@ -2,6 +2,8 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.InfoItem; +import javax.annotation.Nullable; + public class PlaylistInfoItem extends InfoItem { private String uploaderName; @@ -25,11 +27,12 @@ public class PlaylistInfoItem extends InfoItem { this.uploaderName = uploaderName; } + @Nullable public String getUploaderUrl() { return uploaderUrl; } - public void setUploaderUrl(final String uploaderUrl) { + public void setUploaderUrl(@Nullable final String uploaderUrl) { this.uploaderUrl = uploaderUrl; }