Skip to content

Commit 7f2ea13

Browse files
authored
Merge pull request #788 from Stypox/mix
Add MixInfoItem and extract YouTube mixes in related items
2 parents d8f2031 + 09ddb6a commit 7f2ea13

File tree

58 files changed

+4343
-1651
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4343
-1651
lines changed
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
package org.schabi.newpipe.extractor.search;
1+
package org.schabi.newpipe.extractor;
22

3-
import org.schabi.newpipe.extractor.InfoItem;
4-
import org.schabi.newpipe.extractor.InfoItemExtractor;
5-
import org.schabi.newpipe.extractor.InfoItemsCollector;
63
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
74
import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector;
85
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -36,23 +33,24 @@
3633
*/
3734

3835
/**
39-
* Collector for search results
36+
* A collector that can handle many extractor types, to be used when a list contains items of
37+
* different types (e.g. search)
4038
* <p>
4139
* This collector can handle the following extractor types:
4240
* <ul>
4341
* <li>{@link StreamInfoItemExtractor}</li>
4442
* <li>{@link ChannelInfoItemExtractor}</li>
4543
* <li>{@link PlaylistInfoItemExtractor}</li>
4644
* </ul>
47-
* Calling {@link #extract(InfoItemExtractor)} or {@link #commit(Object)} with any
45+
* Calling {@link #extract(InfoItemExtractor)} or {@link #commit(InfoItemExtractor)} with any
4846
* other extractor type will raise an exception.
4947
*/
50-
public class InfoItemsSearchCollector extends InfoItemsCollector<InfoItem, InfoItemExtractor> {
48+
public class MultiInfoItemsCollector extends InfoItemsCollector<InfoItem, InfoItemExtractor> {
5149
private final StreamInfoItemsCollector streamCollector;
5250
private final ChannelInfoItemsCollector userCollector;
5351
private final PlaylistInfoItemsCollector playlistCollector;
5452

55-
public InfoItemsSearchCollector(int serviceId) {
53+
public MultiInfoItemsCollector(int serviceId) {
5654
super(serviceId);
5755
streamCollector = new StreamInfoItemsCollector(serviceId);
5856
userCollector = new ChannelInfoItemsCollector(serviceId);

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
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampSearchExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1616
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1717
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
18-
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
18+
import org.schabi.newpipe.extractor.MultiInfoItemsCollector;
1919
import org.schabi.newpipe.extractor.search.SearchExtractor;
2020
import org.schabi.newpipe.extractor.services.bandcamp.extractors.streaminfoitem.BandcampSearchStreamInfoItemExtractor;
2121

@@ -50,7 +50,7 @@ public List<MetaInfo> getMetaInfo() throws ParsingException {
5050
public InfoItemsPage<InfoItem> getPage(final Page page) throws IOException, ExtractionException {
5151
final String html = getDownloader().get(page.getUrl()).responseBody();
5252

53-
final InfoItemsSearchCollector collector = new InfoItemsSearchCollector(getServiceId());
53+
final MultiInfoItemsCollector collector = new MultiInfoItemsCollector(getServiceId());
5454

5555

5656
final Document d = Jsoup.parse(html);

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCSearchExtractor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1616
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1717
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
18-
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
18+
import org.schabi.newpipe.extractor.MultiInfoItemsCollector;
1919
import org.schabi.newpipe.extractor.search.SearchExtractor;
2020
import org.schabi.newpipe.extractor.services.media_ccc.extractors.infoItems.MediaCCCStreamInfoItemExtractor;
2121
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferencesListLinkHandlerFactory;
@@ -66,7 +66,7 @@ public List<MetaInfo> getMetaInfo() {
6666
@Nonnull
6767
@Override
6868
public InfoItemsPage<InfoItem> getInitialPage() {
69-
final InfoItemsSearchCollector searchItems = new InfoItemsSearchCollector(getServiceId());
69+
final MultiInfoItemsCollector searchItems = new MultiInfoItemsCollector(getServiceId());
7070

7171
if (getLinkHandler().getContentFilters().contains(CONFERENCES)
7272
|| getLinkHandler().getContentFilters().contains(ALL)
@@ -122,7 +122,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
122122

123123
private void searchConferences(final String searchString,
124124
final List<ChannelInfoItem> channelItems,
125-
final InfoItemsSearchCollector collector) {
125+
final MultiInfoItemsCollector collector) {
126126
for (final ChannelInfoItem item : channelItems) {
127127
if (item.getName().toUpperCase().contains(
128128
searchString.toUpperCase())) {

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeSearchExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1313
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1414
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
15-
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
15+
import org.schabi.newpipe.extractor.MultiInfoItemsCollector;
1616
import org.schabi.newpipe.extractor.search.SearchExtractor;
1717
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
1818
import org.schabi.newpipe.extractor.utils.Utils;
@@ -87,7 +87,7 @@ public InfoItemsPage<InfoItem> getPage(final Page page) throws IOException, Extr
8787
PeertubeParsingHelper.validate(json);
8888
final long total = json.getLong("total");
8989

90-
final InfoItemsSearchCollector collector = new InfoItemsSearchCollector(getServiceId());
90+
final MultiInfoItemsCollector collector = new MultiInfoItemsCollector(getServiceId());
9191
collectStreamsFrom(collector, json, getBaseUrl(), sepia);
9292

9393
return new InfoItemsPage<>(collector, PeertubeParsingHelper.getNextPage(page.getUrl(), total));

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSearchExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1010
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1111
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
12-
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
12+
import org.schabi.newpipe.extractor.MultiInfoItemsCollector;
1313
import org.schabi.newpipe.extractor.search.SearchExtractor;
1414
import org.schabi.newpipe.extractor.utils.Parser;
1515

@@ -100,7 +100,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
100100

101101
private InfoItemsCollector<InfoItem, InfoItemExtractor> collectItems(
102102
final JsonArray searchCollection) {
103-
final InfoItemsSearchCollector collector = new InfoItemsSearchCollector(getServiceId());
103+
final MultiInfoItemsCollector collector = new MultiInfoItemsCollector(getServiceId());
104104

105105
for (final Object result : searchCollection) {
106106
if (!(result instanceof JsonObject)) continue;

0 commit comments

Comments
 (0)