Class YoutubeChannelHelper
- java.lang.Object
-
- org.schabi.newpipe.extractor.services.youtube.YoutubeChannelHelper
-
public final class YoutubeChannelHelper extends java.lang.ObjectShared functions for extracting YouTube channel pages and tabs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classYoutubeChannelHelper.ChannelHeaderA channel header response.static classYoutubeChannelHelper.ChannelResponseDataResponse data object forgetChannelResponse(String, String, Localization, ContentCountry), after any redirection in the allowed redirects count (3).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.grack.nanojson.JsonObjectgetChannelAgeGateRenderer(com.grack.nanojson.JsonObject jsonResponse)static YoutubeChannelHelper.ChannelHeadergetChannelHeader(com.grack.nanojson.JsonObject channelResponse)Get a channel header it if exists.static java.lang.StringgetChannelId(YoutubeChannelHelper.ChannelHeader channelHeader, com.grack.nanojson.JsonObject jsonResponse, java.lang.String fallbackChannelId)Get the ID of a channel from its response.static java.lang.StringgetChannelName(YoutubeChannelHelper.ChannelHeader channelHeader, com.grack.nanojson.JsonObject channelAgeGateRenderer, com.grack.nanojson.JsonObject jsonResponse)static YoutubeChannelHelper.ChannelResponseDatagetChannelResponse(java.lang.String channelId, java.lang.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 java.lang.StringresolveChannelId(java.lang.String idOrPath)Take a YouTube channel ID or URL path, resolve it if necessary and return a channel ID.
-
-
-
Method Detail
-
resolveChannelId
@Nonnull public static java.lang.String resolveChannelId(@Nonnull java.lang.String idOrPath) throws ExtractionException, java.io.IOExceptionTake 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:
java.io.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 java.lang.String channelId, @Nonnull java.lang.String parameters, @Nonnull Localization localization, @Nonnull ContentCountry country) throws ExtractionException, java.io.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:
java.io.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
public static boolean isChannelVerified(@Nonnull YoutubeChannelHelper.ChannelHeader channelHeader)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 java.lang.String getChannelId(@Nullable YoutubeChannelHelper.ChannelHeader channelHeader, @Nonnull com.grack.nanojson.JsonObject jsonResponse, @Nullable java.lang.String fallbackChannelId) throws ParsingExceptionGet 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 java.lang.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)
-
-