Skip to content

Commit 53673d6

Browse files
committed
[Mix] Add type to playlists & playlist items, to distinguish mixes
1 parent d8f2031 commit 53673d6

5 files changed

Lines changed: 78 additions & 0 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ public String getSubChannelUrl() throws ParsingException {
4949
public String getSubChannelAvatarUrl() throws ParsingException {
5050
return EMPTY_STRING;
5151
}
52+
53+
public PlaylistInfo.PlaylistType getPlaylistType() throws ParsingException {
54+
return PlaylistInfo.PlaylistType.NORMAL;
55+
}
5256
}

extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,41 @@
1717

1818
public class PlaylistInfo extends ListInfo<StreamInfoItem> {
1919

20+
/**
21+
* Mixes are handled as particular playlists in NewPipeExtractor. {@link PlaylistType#NORMAL} is
22+
* for non-mixes, while other values are for the different types of mixes. The type of a mix
23+
* depends on how its contents are autogenerated.
24+
*/
25+
public enum PlaylistType {
26+
/**
27+
* A normal playlist (not a mix)
28+
*/
29+
NORMAL,
30+
31+
/**
32+
* A mix made only of streams related to a particular stream, for example YouTube mixes
33+
*/
34+
MIX_STREAM,
35+
36+
/**
37+
* A mix made only of music streams related to a particular stream, for example YouTube
38+
* music mixes
39+
*/
40+
MIX_MUSIC,
41+
42+
/**
43+
* A mix made only of streams from (or related to) the same channel, for example YouTube
44+
* channel mixes
45+
*/
46+
MIX_CHANNEL,
47+
48+
/**
49+
* A mix made only of streams related to a particular (musical) genre, for example YouTube
50+
* genre mixes
51+
*/
52+
MIX_GENRE,
53+
}
54+
2055
private PlaylistInfo(int serviceId, ListLinkHandler linkHandler, String name) throws ParsingException {
2156
super(serviceId, linkHandler, name);
2257
}
@@ -105,6 +140,11 @@ public static PlaylistInfo getInfo(PlaylistExtractor extractor) throws Extractio
105140
} catch (Exception e) {
106141
info.addError(e);
107142
}
143+
try {
144+
info.setPlaylistType(extractor.getPlaylistType());
145+
} catch (Exception e) {
146+
info.addError(e);
147+
}
108148
// do not fail if everything but the uploader infos could be collected
109149
if (!uploaderParsingErrors.isEmpty() &&
110150
(!info.getErrors().isEmpty() || uploaderParsingErrors.size() < 3)) {
@@ -127,6 +167,7 @@ public static PlaylistInfo getInfo(PlaylistExtractor extractor) throws Extractio
127167
private String subChannelName;
128168
private String subChannelAvatarUrl;
129169
private long streamCount = 0;
170+
private PlaylistType playlistType;
130171

131172
public String getThumbnailUrl() {
132173
return thumbnailUrl;
@@ -199,4 +240,12 @@ public long getStreamCount() {
199240
public void setStreamCount(long streamCount) {
200241
this.streamCount = streamCount;
201242
}
243+
244+
public PlaylistType getPlaylistType() {
245+
return playlistType;
246+
}
247+
248+
public void setPlaylistType(final PlaylistType playlistType) {
249+
this.playlistType = playlistType;
250+
}
202251
}

extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class PlaylistInfoItem extends InfoItem {
99
* How many streams this playlist have
1010
*/
1111
private long streamCount = 0;
12+
private PlaylistInfo.PlaylistType playlistType;
1213

1314
public PlaylistInfoItem(int serviceId, String url, String name) {
1415
super(InfoType.PLAYLIST, serviceId, url, name);
@@ -29,4 +30,12 @@ public long getStreamCount() {
2930
public void setStreamCount(long stream_count) {
3031
this.streamCount = stream_count;
3132
}
33+
34+
public PlaylistInfo.PlaylistType getPlaylistType() {
35+
return playlistType;
36+
}
37+
38+
public void setPlaylistType(final PlaylistInfo.PlaylistType playlistType) {
39+
this.playlistType = playlistType;
40+
}
3241
}

extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.schabi.newpipe.extractor.InfoItemExtractor;
44
import org.schabi.newpipe.extractor.exceptions.ParsingException;
55

6+
import javax.annotation.Nonnull;
7+
68
public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
79

810
/**
@@ -18,4 +20,13 @@ public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
1820
* @throws ParsingException
1921
*/
2022
long getStreamCount() throws ParsingException;
23+
24+
/**
25+
* @return the type of this playlist, see {@link PlaylistInfo.PlaylistType} for a description
26+
* of types. If not overridden always returns {@link PlaylistInfo.PlaylistType#NORMAL}.
27+
*/
28+
@Nonnull
29+
default PlaylistInfo.PlaylistType getPlaylistType() throws ParsingException {
30+
return PlaylistInfo.PlaylistType.NORMAL;
31+
}
2132
}

extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemsCollector.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public PlaylistInfoItem extract(PlaylistInfoItemExtractor extractor) throws Pars
3333
} catch (Exception e) {
3434
addError(e);
3535
}
36+
try {
37+
resultItem.setPlaylistType(extractor.getPlaylistType());
38+
} catch (Exception e) {
39+
addError(e);
40+
}
3641
return resultItem;
3742
}
3843
}

0 commit comments

Comments
 (0)