Class YoutubeChannelHelper
- java.lang.Object
-
- org.schabi.newpipe.extractor.services.youtube.YoutubeChannelHelper
-
public final class YoutubeChannelHelper extends java.lang.Object
Shared functions for extracting YouTube channel pages and tabs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
YoutubeChannelHelper.ChannelHeader
A channel header response.static class
YoutubeChannelHelper.ChannelResponseData
Response 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.JsonObject
getChannelAgeGateRenderer(com.grack.nanojson.JsonObject jsonResponse)
static YoutubeChannelHelper.ChannelHeader
getChannelHeader(com.grack.nanojson.JsonObject channelResponse)
Get a channel header it if exists.static java.lang.String
getChannelId(YoutubeChannelHelper.ChannelHeader channelHeader, com.grack.nanojson.JsonObject jsonResponse, java.lang.String fallbackChannelId)
Get the ID of a channel from its response.static java.lang.String
getChannelName(YoutubeChannelHelper.ChannelHeader channelHeader, com.grack.nanojson.JsonObject channelAgeGateRenderer, com.grack.nanojson.JsonObject jsonResponse)
static YoutubeChannelHelper.ChannelResponseData
getChannelResponse(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 boolean
isChannelVerified(YoutubeChannelHelper.ChannelHeader channelHeader)
Check if a channel is verified by using its header.static java.lang.String
resolveChannelId(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.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:
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_OQ
andUCok7UTQQEP1Rsctxiv3gwSQ
, and they all redirect to theUClgRkhTL3_hImCAmdLfDE4g
one.- Parameters:
channelId
- a valid YouTube channel IDparameters
- the parameters to specify the YouTube channel tab; if invalid ones are specified, YouTube should return theHome
tablocalization
- theLocalization
to usecountry
- theContentCountry
to 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.ChannelHeader
ornull
if 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
channelAgeGateRenderer
cannot be checked.- Parameters:
channelHeader
- theYoutubeChannelHelper.ChannelHeader
of 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 ParsingException
Get the ID of a channel from its response.For
c4TabbedHeaderRenderer
andcarouselHeaderRenderer
channel headers, the ID is get from the header.For other headers or if it cannot be got, the ID from the
channelMetadataRenderer
in 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)
-
-