[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

View File

@ -46,6 +46,18 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
private JsonObject initialData; private JsonObject initialData;
private JsonObject videoTab; 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) { public YoutubeChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
super(service, 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"; url = "https://www.youtube.com/channel/" + browseId + "/videos?pbj=1&view=0&flow=grid";
redirectedChannelId = browseId;
level++; level++;
} else { } else {
ajaxJson = jsonResponse; ajaxJson = jsonResponse;
@ -117,10 +130,17 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Nonnull @Nonnull
@Override @Override
public String getId() throws ParsingException { public String getId() throws ParsingException {
try { final String channelId = initialData
return initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getString("channelId"); .getObject("header", EMPTY_OBJECT)
} catch (Exception e) { .getObject("c4TabbedHeaderRenderer", EMPTY_OBJECT)
throw new ParsingException("Could not get channel id", e); .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");
} }
} }