Skip to content

Commit b81e22d

Browse files
authored
Merge pull request #291 from wb9688/yt-music-search
Add support for YouTube Music search
2 parents cef7c96 + bce27a0 commit b81e22d

10 files changed

Lines changed: 881 additions & 55 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,33 @@
33
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
44
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
55

6-
import javax.annotation.Nonnull;
76
import java.io.IOException;
87
import java.util.Collections;
98
import java.util.List;
109

10+
import javax.annotation.Nonnull;
11+
1112
/**
1213
* Base class to extractors that have a list (e.g. playlists, users).
1314
*/
1415
public abstract class ListExtractor<R extends InfoItem> extends Extractor {
1516

17+
/**
18+
* Constant that should be returned whenever
19+
* a list has an unknown number of items.
20+
*/
21+
public static final long ITEM_COUNT_UNKNOWN = -1;
22+
/**
23+
* Constant that should be returned whenever a list has an
24+
* infinite number of items. For example a YouTube mix.
25+
*/
26+
public static final long ITEM_COUNT_INFINITE = -2;
27+
/**
28+
* Constant that should be returned whenever a list
29+
* has an unknown number of items bigger than 100.
30+
*/
31+
public static final long ITEM_COUNT_MORE_THAN_100 = -3;
32+
1633
public ListExtractor(StreamingService service, ListLinkHandler linkHandler) {
1734
super(service, linkHandler);
1835
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,45 @@
77
import org.schabi.newpipe.extractor.feed.FeedExtractor;
88
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
99
import org.schabi.newpipe.extractor.kiosk.KioskList;
10-
import org.schabi.newpipe.extractor.linkhandler.*;
10+
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
11+
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
12+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
13+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
14+
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
15+
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
1116
import org.schabi.newpipe.extractor.localization.ContentCountry;
1217
import org.schabi.newpipe.extractor.localization.Localization;
1318
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
1419
import org.schabi.newpipe.extractor.search.SearchExtractor;
15-
import org.schabi.newpipe.extractor.services.youtube.extractors.*;
16-
import org.schabi.newpipe.extractor.services.youtube.linkHandler.*;
20+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeChannelExtractor;
21+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeCommentsExtractor;
22+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeFeedExtractor;
23+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeMusicSearchExtractor;
24+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubePlaylistExtractor;
25+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor;
26+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
27+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSubscriptionExtractor;
28+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSuggestionExtractor;
29+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
30+
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
31+
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeCommentsLinkHandlerFactory;
32+
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
33+
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
34+
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
35+
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingLinkHandlerFactory;
1736
import org.schabi.newpipe.extractor.stream.StreamExtractor;
1837
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
1938
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
2039

21-
import javax.annotation.Nonnull;
2240
import java.util.List;
2341

42+
import javax.annotation.Nonnull;
43+
2444
import static java.util.Arrays.asList;
25-
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.*;
45+
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
46+
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
47+
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.LIVE;
48+
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.VIDEO;
2649

2750
/*
2851
* Created by Christian Schabesberger on 23.08.15.
@@ -92,7 +115,13 @@ public PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler) {
92115

93116
@Override
94117
public SearchExtractor getSearchExtractor(SearchQueryHandler query) {
95-
return new YoutubeSearchExtractor(this, query);
118+
final List<String> contentFilters = query.getContentFilters();
119+
120+
if (contentFilters.size() > 0 && contentFilters.get(0).startsWith("music_")) {
121+
return new YoutubeMusicSearchExtractor(this, query);
122+
} else {
123+
return new YoutubeSearchExtractor(this, query);
124+
}
96125
}
97126

98127
@Override

0 commit comments

Comments
 (0)