[YouTube] Fix id extraction for some channels

Some channels had no reliable way to get the redirected id in the response,
so saving it for later was a valid alternative.
This commit is contained in:
Mauricio Colli 2020-03-14 02:34:29 -03:00
parent 00d1ed439b
commit b086e9db3f
No known key found for this signature in database
GPG Key ID: F200BFD6F29DDD85
1 changed files with 24 additions and 4 deletions

View File

@ -46,6 +46,18 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
private JsonObject initialData;
private JsonObject videoTab;
/**
* Some channels have response redirects and the only way to reliably get the id is by saving it.
*<p>
* "Movies & Shows":
* <pre>
* UCuJcl0Ju-gPDoksRjK1ya-w
* UChBfWrfBXL9wS6tQtgjt_OQ UClgRkhTL3_hImCAmdLfDE4g
* UCok7UTQQEP1Rsctxiv3gwSQ
* </pre>
*/
private String redirectedChannelId;
public YoutubeChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
super(service, linkHandler);
}
@ -80,6 +92,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
}
url = "https://www.youtube.com/channel/" + browseId + "/videos?pbj=1&view=0&flow=grid";
redirectedChannelId = browseId;
level++;
} else {
ajaxJson = jsonResponse;
@ -117,10 +130,17 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Nonnull
@Override
public String getId() throws ParsingException {
try {
return initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getString("channelId");
} catch (Exception e) {
throw new ParsingException("Could not get channel id", e);
final String channelId = initialData
.getObject("header", EMPTY_OBJECT)
.getObject("c4TabbedHeaderRenderer", EMPTY_OBJECT)
.getString("channelId", EMPTY_STRING);
if (!channelId.isEmpty()) {
return channelId;
} else if (redirectedChannelId != null && !redirectedChannelId.isEmpty()) {
return redirectedChannelId;
} else {
throw new ParsingException("Could not get channel id");
}
}