[Mix] Add type to playlists & playlist items, to distinguish mixes
This commit is contained in:
parent
d8f2031619
commit
53673d64c6
|
@ -49,4 +49,8 @@ public abstract class PlaylistExtractor extends ListExtractor<StreamInfoItem> {
|
||||||
public String getSubChannelAvatarUrl() throws ParsingException {
|
public String getSubChannelAvatarUrl() throws ParsingException {
|
||||||
return EMPTY_STRING;
|
return EMPTY_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlaylistInfo.PlaylistType getPlaylistType() throws ParsingException {
|
||||||
|
return PlaylistInfo.PlaylistType.NORMAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,41 @@ import java.util.List;
|
||||||
|
|
||||||
public class PlaylistInfo extends ListInfo<StreamInfoItem> {
|
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 {
|
private PlaylistInfo(int serviceId, ListLinkHandler linkHandler, String name) throws ParsingException {
|
||||||
super(serviceId, linkHandler, name);
|
super(serviceId, linkHandler, name);
|
||||||
}
|
}
|
||||||
|
@ -105,6 +140,11 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
info.addError(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
|
// do not fail if everything but the uploader infos could be collected
|
||||||
if (!uploaderParsingErrors.isEmpty() &&
|
if (!uploaderParsingErrors.isEmpty() &&
|
||||||
(!info.getErrors().isEmpty() || uploaderParsingErrors.size() < 3)) {
|
(!info.getErrors().isEmpty() || uploaderParsingErrors.size() < 3)) {
|
||||||
|
@ -127,6 +167,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
|
||||||
private String subChannelName;
|
private String subChannelName;
|
||||||
private String subChannelAvatarUrl;
|
private String subChannelAvatarUrl;
|
||||||
private long streamCount = 0;
|
private long streamCount = 0;
|
||||||
|
private PlaylistType playlistType;
|
||||||
|
|
||||||
public String getThumbnailUrl() {
|
public String getThumbnailUrl() {
|
||||||
return thumbnailUrl;
|
return thumbnailUrl;
|
||||||
|
@ -199,4 +240,12 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
|
||||||
public void setStreamCount(long streamCount) {
|
public void setStreamCount(long streamCount) {
|
||||||
this.streamCount = streamCount;
|
this.streamCount = streamCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlaylistType getPlaylistType() {
|
||||||
|
return playlistType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlaylistType(final PlaylistType playlistType) {
|
||||||
|
this.playlistType = playlistType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ public class PlaylistInfoItem extends InfoItem {
|
||||||
* How many streams this playlist have
|
* How many streams this playlist have
|
||||||
*/
|
*/
|
||||||
private long streamCount = 0;
|
private long streamCount = 0;
|
||||||
|
private PlaylistInfo.PlaylistType playlistType;
|
||||||
|
|
||||||
public PlaylistInfoItem(int serviceId, String url, String name) {
|
public PlaylistInfoItem(int serviceId, String url, String name) {
|
||||||
super(InfoType.PLAYLIST, serviceId, url, name);
|
super(InfoType.PLAYLIST, serviceId, url, name);
|
||||||
|
@ -29,4 +30,12 @@ public class PlaylistInfoItem extends InfoItem {
|
||||||
public void setStreamCount(long stream_count) {
|
public void setStreamCount(long stream_count) {
|
||||||
this.streamCount = stream_count;
|
this.streamCount = stream_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlaylistInfo.PlaylistType getPlaylistType() {
|
||||||
|
return playlistType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlaylistType(final PlaylistInfo.PlaylistType playlistType) {
|
||||||
|
this.playlistType = playlistType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.schabi.newpipe.extractor.playlist;
|
||||||
import org.schabi.newpipe.extractor.InfoItemExtractor;
|
import org.schabi.newpipe.extractor.InfoItemExtractor;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
|
public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,4 +20,13 @@ public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
|
||||||
* @throws ParsingException
|
* @throws ParsingException
|
||||||
*/
|
*/
|
||||||
long getStreamCount() 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,11 @@ public class PlaylistInfoItemsCollector extends InfoItemsCollector<PlaylistInfoI
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
addError(e);
|
addError(e);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
resultItem.setPlaylistType(extractor.getPlaylistType());
|
||||||
|
} catch (Exception e) {
|
||||||
|
addError(e);
|
||||||
|
}
|
||||||
return resultItem;
|
return resultItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue