diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java index f78664545..b055c6e30 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java @@ -49,4 +49,8 @@ public abstract class PlaylistExtractor extends ListExtractor { public String getSubChannelAvatarUrl() throws ParsingException { return EMPTY_STRING; } + + public PlaylistInfo.PlaylistType getPlaylistType() throws ParsingException { + return PlaylistInfo.PlaylistType.NORMAL; + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java index cd6df3744..20627e2a1 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java @@ -17,6 +17,41 @@ import java.util.List; public class PlaylistInfo extends ListInfo { + /** + * Mixes are handled as particular playlists in NewPipeExtractor. {@link PlaylistType#NORMAL} is + * for non-mixes, while other values are for the different types of mixes. The type of a mix + * depends on how its contents are autogenerated. + */ + public enum PlaylistType { + /** + * A normal playlist (not a mix) + */ + NORMAL, + + /** + * A mix made only of streams related to a particular stream, for example YouTube mixes + */ + MIX_STREAM, + + /** + * A mix made only of music streams related to a particular stream, for example YouTube + * music mixes + */ + MIX_MUSIC, + + /** + * A mix made only of streams from (or related to) the same channel, for example YouTube + * channel mixes + */ + MIX_CHANNEL, + + /** + * A mix made only of streams related to a particular (musical) genre, for example YouTube + * genre mixes + */ + MIX_GENRE, + } + private PlaylistInfo(int serviceId, ListLinkHandler linkHandler, String name) throws ParsingException { super(serviceId, linkHandler, name); } @@ -105,6 +140,11 @@ public class PlaylistInfo extends ListInfo { } catch (Exception e) { info.addError(e); } + try { + info.setPlaylistType(extractor.getPlaylistType()); + } catch (Exception e) { + info.addError(e); + } // do not fail if everything but the uploader infos could be collected if (!uploaderParsingErrors.isEmpty() && (!info.getErrors().isEmpty() || uploaderParsingErrors.size() < 3)) { @@ -127,6 +167,7 @@ public class PlaylistInfo extends ListInfo { private String subChannelName; private String subChannelAvatarUrl; private long streamCount = 0; + private PlaylistType playlistType; public String getThumbnailUrl() { return thumbnailUrl; @@ -199,4 +240,12 @@ public class PlaylistInfo extends ListInfo { public void setStreamCount(long streamCount) { this.streamCount = streamCount; } + + public PlaylistType getPlaylistType() { + return playlistType; + } + + public void setPlaylistType(final PlaylistType playlistType) { + this.playlistType = playlistType; + } } 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 bfe31f1ca..218beea4a 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 @@ -9,6 +9,7 @@ public class PlaylistInfoItem extends InfoItem { * How many streams this playlist have */ private long streamCount = 0; + private PlaylistInfo.PlaylistType playlistType; public PlaylistInfoItem(int serviceId, String url, String name) { super(InfoType.PLAYLIST, serviceId, url, name); @@ -29,4 +30,12 @@ public class PlaylistInfoItem extends InfoItem { public void setStreamCount(long stream_count) { this.streamCount = stream_count; } + + public PlaylistInfo.PlaylistType getPlaylistType() { + return playlistType; + } + + public void setPlaylistType(final PlaylistInfo.PlaylistType playlistType) { + this.playlistType = playlistType; + } } 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 fe75cf20c..4cfa47208 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 @@ -3,6 +3,8 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.InfoItemExtractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import javax.annotation.Nonnull; + public interface PlaylistInfoItemExtractor extends InfoItemExtractor { /** @@ -18,4 +20,13 @@ public interface PlaylistInfoItemExtractor extends InfoItemExtractor { * @throws ParsingException */ long getStreamCount() throws ParsingException; + + /** + * @return the type of this playlist, see {@link PlaylistInfo.PlaylistType} for a description + * of types. If not overridden always returns {@link PlaylistInfo.PlaylistType#NORMAL}. + */ + @Nonnull + default PlaylistInfo.PlaylistType getPlaylistType() throws ParsingException { + return PlaylistInfo.PlaylistType.NORMAL; + } } 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 354ab8f15..a525f423a 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 @@ -33,6 +33,11 @@ public class PlaylistInfoItemsCollector extends InfoItemsCollector