mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-14 14:20:33 +05:30
Merge pull request #699 from FireMasterK/yt-music-search
Fix YouTube music search.
This commit is contained in:
commit
06a5219c9c
@ -121,8 +121,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getSearchSuggestion() throws ParsingException {
|
public String getSearchSuggestion() throws ParsingException {
|
||||||
final JsonObject itemSectionRenderer = initialData.getObject("contents").getObject("sectionListRenderer")
|
final JsonObject itemSectionRenderer = JsonUtils.getArray(JsonUtils.getArray(initialData, "contents.tabbedSearchResultsRenderer.tabs").getObject(0), "tabRenderer.content.sectionListRenderer.contents").getObject(0).getObject("itemSectionRenderer");
|
||||||
.getArray("contents").getObject(0).getObject("itemSectionRenderer");
|
|
||||||
if (itemSectionRenderer.isEmpty()) {
|
if (itemSectionRenderer.isEmpty()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -142,16 +141,17 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCorrectedSearch() {
|
public boolean isCorrectedSearch() throws ParsingException {
|
||||||
final JsonObject itemSectionRenderer = initialData.getObject("contents").getObject("sectionListRenderer")
|
final JsonObject itemSectionRenderer = JsonUtils.getArray(JsonUtils.getArray(initialData, "contents.tabbedSearchResultsRenderer.tabs").getObject(0), "tabRenderer.content.sectionListRenderer.contents").getObject(0).getObject("itemSectionRenderer");
|
||||||
.getArray("contents").getObject(0).getObject("itemSectionRenderer");
|
|
||||||
if (itemSectionRenderer.isEmpty()) {
|
if (itemSectionRenderer.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final JsonObject showingResultsForRenderer = itemSectionRenderer.getArray("contents").getObject(0)
|
JsonObject firstContent = itemSectionRenderer.getArray("contents").getObject(0);
|
||||||
.getObject("showingResultsForRenderer");
|
|
||||||
return !showingResultsForRenderer.isEmpty();
|
final boolean corrected = firstContent
|
||||||
|
.has("didYouMeanRenderer") || firstContent.has("showingResultsForRenderer");
|
||||||
|
return corrected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -165,7 +165,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||||||
public InfoItemsPage<InfoItem> getInitialPage() throws ExtractionException, IOException {
|
public InfoItemsPage<InfoItem> getInitialPage() throws ExtractionException, IOException {
|
||||||
final InfoItemsSearchCollector collector = new InfoItemsSearchCollector(getServiceId());
|
final InfoItemsSearchCollector collector = new InfoItemsSearchCollector(getServiceId());
|
||||||
|
|
||||||
final JsonArray contents = initialData.getObject("contents").getObject("sectionListRenderer").getArray("contents");
|
final JsonArray contents = JsonUtils.getArray(JsonUtils.getArray(initialData, "contents.tabbedSearchResultsRenderer.tabs").getObject(0), "tabRenderer.content.sectionListRenderer.contents");
|
||||||
|
|
||||||
Page nextPage = null;
|
Page nextPage = null;
|
||||||
|
|
||||||
|
@ -133,6 +133,7 @@ public class YoutubeMusicSearchExtractorTest {
|
|||||||
public static class Suggestion extends DefaultSearchExtractorTest {
|
public static class Suggestion extends DefaultSearchExtractorTest {
|
||||||
private static SearchExtractor extractor;
|
private static SearchExtractor extractor;
|
||||||
private static final String QUERY = "megaman x3";
|
private static final String QUERY = "megaman x3";
|
||||||
|
private static final boolean CORRECTED = true;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
@ -150,6 +151,7 @@ public class YoutubeMusicSearchExtractorTest {
|
|||||||
@Override public String expectedSearchString() { return QUERY; }
|
@Override public String expectedSearchString() { return QUERY; }
|
||||||
@Nullable @Override public String expectedSearchSuggestion() { return "mega man x3"; }
|
@Nullable @Override public String expectedSearchSuggestion() { return "mega man x3"; }
|
||||||
@Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.STREAM; }
|
@Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.STREAM; }
|
||||||
|
@Override public boolean isCorrectedSearch() { return CORRECTED; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CorrectedSearch extends DefaultSearchExtractorTest {
|
public static class CorrectedSearch extends DefaultSearchExtractorTest {
|
||||||
|
Loading…
Reference in New Issue
Block a user