Class YoutubeChannelHelper
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA channel header response.static final classResponse data object forgetChannelResponse(String, String, Localization, ContentCountry), after any redirection in the allowed redirects count (3). -
Method Summary
Modifier and TypeMethodDescriptionstatic com.grack.nanojson.JsonObjectgetChannelAgeGateRenderer(com.grack.nanojson.JsonObject jsonResponse) getChannelHeader(com.grack.nanojson.JsonObject channelResponse) Get a channel header it if exists.static StringgetChannelId(YoutubeChannelHelper.ChannelHeader channelHeader, com.grack.nanojson.JsonObject jsonResponse, String fallbackChannelId) Get the ID of a channel from its response.static StringgetChannelName(YoutubeChannelHelper.ChannelHeader channelHeader, com.grack.nanojson.JsonObject channelAgeGateRenderer, com.grack.nanojson.JsonObject jsonResponse) getChannelResponse(String channelId, String parameters, Localization localization, ContentCountry country) Fetch a YouTube channel tab response, using the given channel ID and tab parameters.static booleanisChannelVerified(YoutubeChannelHelper.ChannelHeader channelHeader) Check if a channel is verified by using its header.static StringresolveChannelId(String idOrPath) Take a YouTube channel ID or URL path, resolve it if necessary and return a channel ID.
-
Method Details
-
resolveChannelId
@Nonnull public static String resolveChannelId(@Nonnull String idOrPath) throws ExtractionException, IOException Take a YouTube channel ID or URL path, resolve it if necessary and return a channel ID.- Parameters:
idOrPath- a YouTube channel ID or URL path- Returns:
- a YouTube channel ID
- Throws:
IOException- if a channel resolve request failedExtractionException- if a channel resolve request response could not be parsed or is invalid
-
getChannelResponse
@Nonnull public static YoutubeChannelHelper.ChannelResponseData getChannelResponse(@Nonnull String channelId, @Nonnull String parameters, @Nonnull Localization localization, @Nonnull ContentCountry country) throws ExtractionException, IOException Fetch a YouTube channel tab response, using the given channel ID and tab parameters.Redirections to other channels are supported to up to 3 redirects, which could happen for instance for localized channels or for auto-generated ones. For instance, there are three IDs of the auto-generated "Movies and Shows" channel, i.e.
UCuJcl0Ju-gPDoksRjK1ya-w,UChBfWrfBXL9wS6tQtgjt_OQandUCok7UTQQEP1Rsctxiv3gwSQ, and they all redirect to theUClgRkhTL3_hImCAmdLfDE4gone.- Parameters:
channelId- a valid YouTube channel IDparameters- the parameters to specify the YouTube channel tab; if invalid ones are specified, YouTube should return theHometablocalization- theLocalizationto usecountry- theContentCountryto use- Returns:
- a
channel response data - Throws:
IOException- if a channel request failedExtractionException- if a channel request response could not be parsed or is invalid
-
getChannelHeader
@Nullable public static YoutubeChannelHelper.ChannelHeader getChannelHeader(@Nonnull com.grack.nanojson.JsonObject channelResponse) Get a channel header it if exists.- Parameters:
channelResponse- a full channel JSON response- Returns:
- a
YoutubeChannelHelper.ChannelHeaderornullif no supported header has been found
-
isChannelVerified
Check if a channel is verified by using its header.The header is mandatory, so the verified status of age-restricted channels with a
channelAgeGateRenderercannot be checked.- Parameters:
channelHeader- theYoutubeChannelHelper.ChannelHeaderof a non age-restricted channel- Returns:
- whether the channel is verified
-
getChannelId
@Nonnull public static String getChannelId(@Nullable YoutubeChannelHelper.ChannelHeader channelHeader, @Nonnull com.grack.nanojson.JsonObject jsonResponse, @Nullable String fallbackChannelId) throws ParsingException Get the ID of a channel from its response.For
c4TabbedHeaderRendererandcarouselHeaderRendererchannel headers, the ID is get from the header.For other headers or if it cannot be got, the ID from the
channelMetadataRendererin the channel response is used.If the ID cannot still be get, the fallback channel ID, if provided, will be used.
- Parameters:
channelHeader- the channel headerfallbackChannelId- the fallback channel ID, which can be null- Returns:
- the ID of the channel
- Throws:
ParsingException- if the channel ID cannot be got from the channel header, the channel response and the fallback channel ID
-
getChannelName
@Nonnull public static String getChannelName(@Nullable YoutubeChannelHelper.ChannelHeader channelHeader, @Nullable com.grack.nanojson.JsonObject channelAgeGateRenderer, @Nonnull com.grack.nanojson.JsonObject jsonResponse) throws ParsingException - Throws:
ParsingException
-
getChannelAgeGateRenderer
@Nullable public static com.grack.nanojson.JsonObject getChannelAgeGateRenderer(@Nonnull com.grack.nanojson.JsonObject jsonResponse)
-