[Mix] Add type to playlists & playlist items, to distinguish mixes

This commit is contained in:
Stypox 2022-02-02 19:12:36 +01:00
parent d8f2031619
commit 53673d64c6
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
5 changed files with 78 additions and 0 deletions

View File

@ -49,4 +49,8 @@ public abstract class PlaylistExtractor extends ListExtractor<StreamInfoItem> {
public String getSubChannelAvatarUrl() throws ParsingException {
return EMPTY_STRING;
}
public PlaylistInfo.PlaylistType getPlaylistType() throws ParsingException {
return PlaylistInfo.PlaylistType.NORMAL;
}
}

View File

@ -17,6 +17,41 @@ import java.util.List;
public class PlaylistInfo extends ListInfo<StreamInfoItem> {
/**
* 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<StreamInfoItem> {
} 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<StreamInfoItem> {
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<StreamInfoItem> {
public void setStreamCount(long streamCount) {
this.streamCount = streamCount;
}
public PlaylistType getPlaylistType() {
return playlistType;
}
public void setPlaylistType(final PlaylistType playlistType) {
this.playlistType = playlistType;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -33,6 +33,11 @@ public class PlaylistInfoItemsCollector extends InfoItemsCollector<PlaylistInfoI
} catch (Exception e) {
addError(e);
}
try {
resultItem.setPlaylistType(extractor.getPlaylistType());
} catch (Exception e) {
addError(e);
}
return resultItem;
}
}