From a685941bba116a5dd217a0eeb3fe55cd862c0535 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 31 Jul 2021 01:33:38 +0530 Subject: [PATCH 1/4] Fix YouTube music search. --- .../youtube/extractors/YoutubeMusicSearchExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java index a0c2e99c7..967780701 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java @@ -165,7 +165,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor { public InfoItemsPage getInitialPage() throws ExtractionException, IOException { 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; From fd19c53f65f9f596e186b96e4c6e794e8d2f6149 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 31 Jul 2021 02:08:50 +0530 Subject: [PATCH 2/4] Fix search suggestions test. --- .../youtube/extractors/YoutubeMusicSearchExtractor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java index 967780701..267fafa6a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java @@ -121,8 +121,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor { @Nonnull @Override public String getSearchSuggestion() throws ParsingException { - final JsonObject itemSectionRenderer = initialData.getObject("contents").getObject("sectionListRenderer") - .getArray("contents").getObject(0).getObject("itemSectionRenderer"); + final JsonObject itemSectionRenderer = JsonUtils.getArray(JsonUtils.getArray(initialData, "contents.tabbedSearchResultsRenderer.tabs").getObject(0), "tabRenderer.content.sectionListRenderer.contents").getObject(0).getObject("itemSectionRenderer"); if (itemSectionRenderer.isEmpty()) { return ""; } From 88c11db4c517e1aa6a0c377d93b9b0b8fa291d2b Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 31 Jul 2021 02:18:18 +0530 Subject: [PATCH 3/4] Fix isCorrectedSearch test. --- .../extractors/YoutubeMusicSearchExtractor.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java index 267fafa6a..a7ac5cc6d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java @@ -141,16 +141,15 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor { } @Override - public boolean isCorrectedSearch() { - final JsonObject itemSectionRenderer = initialData.getObject("contents").getObject("sectionListRenderer") - .getArray("contents").getObject(0).getObject("itemSectionRenderer"); + public boolean isCorrectedSearch() throws ParsingException { + final JsonObject itemSectionRenderer = JsonUtils.getArray(JsonUtils.getArray(initialData, "contents.tabbedSearchResultsRenderer.tabs").getObject(0), "tabRenderer.content.sectionListRenderer.contents").getObject(0).getObject("itemSectionRenderer"); if (itemSectionRenderer.isEmpty()) { return false; } - final JsonObject showingResultsForRenderer = itemSectionRenderer.getArray("contents").getObject(0) - .getObject("showingResultsForRenderer"); - return !showingResultsForRenderer.isEmpty(); + final boolean corrected = itemSectionRenderer.getArray("contents").getObject(0) + .has("didYouMeanRenderer"); + return corrected; } @Nonnull From f4aad8b01444a3847764846e2f7701bf071f7d0b Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 31 Jul 2021 14:40:51 +0530 Subject: [PATCH 4/4] Fix tests again. --- .../youtube/extractors/YoutubeMusicSearchExtractor.java | 6 ++++-- .../youtube/search/YoutubeMusicSearchExtractorTest.java | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java index a7ac5cc6d..0e17c60c6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java @@ -147,8 +147,10 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor { return false; } - final boolean corrected = itemSectionRenderer.getArray("contents").getObject(0) - .has("didYouMeanRenderer"); + JsonObject firstContent = itemSectionRenderer.getArray("contents").getObject(0); + + final boolean corrected = firstContent + .has("didYouMeanRenderer") || firstContent.has("showingResultsForRenderer"); return corrected; } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeMusicSearchExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeMusicSearchExtractorTest.java index 785250e74..6f9f81f8e 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeMusicSearchExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeMusicSearchExtractorTest.java @@ -133,6 +133,7 @@ public class YoutubeMusicSearchExtractorTest { public static class Suggestion extends DefaultSearchExtractorTest { private static SearchExtractor extractor; private static final String QUERY = "megaman x3"; + private static final boolean CORRECTED = true; @BeforeClass public static void setUp() throws Exception { @@ -150,6 +151,7 @@ public class YoutubeMusicSearchExtractorTest { @Override public String expectedSearchString() { return QUERY; } @Nullable @Override public String expectedSearchSuggestion() { return "mega man x3"; } @Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.STREAM; } + @Override public boolean isCorrectedSearch() { return CORRECTED; } } public static class CorrectedSearch extends DefaultSearchExtractorTest {