Extract uploader url from certain YouTube Music videos

This commit is contained in:
wb9688 2020-03-25 10:42:34 +01:00
parent aa8cea47f3
commit cf0f2aff3e
2 changed files with 20 additions and 7 deletions

View File

@ -394,12 +394,25 @@ public class YoutubeSearchExtractor extends SearchExtractor {
@Override
public String getUploaderUrl() throws ParsingException {
if (searchType.equals(MUSIC_VIDEOS)) return null;
String url = null;
if (searchType.equals(MUSIC_VIDEOS)) {
JsonArray items = info.getObject("menu").getObject("menuRenderer").getArray("items");
for (Object item : items) {
JsonObject menuNavigationItemRenderer = ((JsonObject) item).getObject("menuNavigationItemRenderer");
if (menuNavigationItemRenderer != null && menuNavigationItemRenderer.getObject("icon").getString("iconType").equals("ARTIST")) {
url = getUrlFromNavigationEndpoint(menuNavigationItemRenderer.getObject("navigationEndpoint"));
break;
}
}
} else {
JsonObject navigationEndpoint = info.getArray("flexColumns")
.getObject(1).getObject("musicResponsiveListItemFlexColumnRenderer")
.getObject("text").getArray("runs").getObject(0).getObject("navigationEndpoint");
if (navigationEndpoint == null) return null;
String url = getUrlFromNavigationEndpoint(navigationEndpoint);
url = getUrlFromNavigationEndpoint(navigationEndpoint);
}
if (url != null && !url.isEmpty()) return url;
throw new ParsingException("Could not get uploader url");
}

View File

@ -16,7 +16,7 @@ import javax.annotation.Nullable;
import static java.util.Collections.singletonList;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
public class YoutubeSearchExtractorMusicTest {
public class YoutubeMusicSearchExtractorTest {
public static class MusicSongs extends DefaultSearchExtractorTest {
private static SearchExtractor extractor;
private static final String QUERY = "mocromaniac";