Class YoutubeChannelHelper

java.lang.Object
org.schabi.newpipe.extractor.services.youtube.YoutubeChannelHelper

public final class YoutubeChannelHelper extends Object
Shared functions for extracting YouTube channel pages and tabs.
  • 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 failed
      ExtractionException - 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_OQ and UCok7UTQQEP1Rsctxiv3gwSQ, and they all redirect to the UClgRkhTL3_hImCAmdLfDE4g one.

      Parameters:
      channelId - a valid YouTube channel ID
      parameters - the parameters to specify the YouTube channel tab; if invalid ones are specified, YouTube should return the Home tab
      localization - the Localization to use
      country - the ContentCountry to use
      Returns:
      a channel response data
      Throws:
      IOException - if a channel request failed
      ExtractionException - 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 or null 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 - the YoutubeChannelHelper.ChannelHeader of 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 c4TabbedHeaderRenderer and carouselHeaderRenderer 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 header
      fallbackChannelId - 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)