Class Downloader

java.lang.Object
org.schabi.newpipe.extractor.downloader.Downloader

public abstract class Downloader extends Object
A base for downloader implementations that NewPipe will use to download needed resources during extraction.
  • Constructor Details

    • Downloader

      public Downloader()
  • Method Details

    • get

      public Response get(String url) throws IOException, ReCaptchaException
      Do a GET request to get the resource that the url is pointing to.

      This method calls get(String, Map, Localization) with the default preferred localization. It should only be used when the resource that will be fetched won't be affected by the localization.
      Parameters:
      url - the URL that is pointing to the wanted resource
      Returns:
      the result of the GET request
      Throws:
      IOException
      ReCaptchaException
    • get

      public Response get(String url, Localization localization) throws IOException, ReCaptchaException
      Do a GET request to get the resource that the url is pointing to.

      It will set the Accept-Language header to the language of the localization parameter.
      Parameters:
      url - the URL that is pointing to the wanted resource
      localization - the source of the value of the Accept-Language header
      Returns:
      the result of the GET request
      Throws:
      IOException
      ReCaptchaException
    • get

      public Response get(String url, @Nullable Map<String,List<String>> headers) throws IOException, ReCaptchaException
      Do a GET request with the specified headers.
      Parameters:
      url - the URL that is pointing to the wanted resource
      headers - a list of headers that will be used in the request. Any default headers should be overridden by these.
      Returns:
      the result of the GET request
      Throws:
      IOException
      ReCaptchaException
    • get

      public Response get(String url, @Nullable Map<String,List<String>> headers, Localization localization) throws IOException, ReCaptchaException
      Do a GET request with the specified headers.

      It will set the Accept-Language header to the language of the localization parameter.
      Parameters:
      url - the URL that is pointing to the wanted resource
      headers - a list of headers that will be used in the request. Any default headers should be overridden by these.
      localization - the source of the value of the Accept-Language header
      Returns:
      the result of the GET request
      Throws:
      IOException
      ReCaptchaException
    • head

      public Response head(String url) throws IOException, ReCaptchaException
      Do a HEAD request.
      Parameters:
      url - the URL that is pointing to the wanted resource
      Returns:
      the result of the HEAD request
      Throws:
      IOException
      ReCaptchaException
    • head

      public Response head(String url, @Nullable Map<String,List<String>> headers) throws IOException, ReCaptchaException
      Do a HEAD request with the specified headers.
      Parameters:
      url - the URL that is pointing to the wanted resource
      headers - a list of headers that will be used in the request. Any default headers should be overridden by these.
      Returns:
      the result of the HEAD request
      Throws:
      IOException
      ReCaptchaException
    • post

      public Response post(String url, @Nullable Map<String,List<String>> headers, @Nullable byte[] dataToSend) throws IOException, ReCaptchaException
      Do a POST request with the specified headers, sending the data array.
      Parameters:
      url - the URL that is pointing to the wanted resource
      headers - a list of headers that will be used in the request. Any default headers should be overridden by these.
      dataToSend - byte array that will be sent when doing the request.
      Returns:
      the result of the POST request
      Throws:
      IOException
      ReCaptchaException
    • post

      public Response post(String url, @Nullable Map<String,List<String>> headers, @Nullable byte[] dataToSend, Localization localization) throws IOException, ReCaptchaException
      Do a POST request with the specified headers, sending the data array.
      It will set the Accept-Language header to the language of the localization parameter.
      Parameters:
      url - the URL that is pointing to the wanted resource
      headers - a list of headers that will be used in the request. Any default headers should be overridden by these.
      dataToSend - byte array that will be sent when doing the request.
      localization - the source of the value of the Accept-Language header
      Returns:
      the result of the POST request
      Throws:
      IOException
      ReCaptchaException
    • postWithContentType

      public Response postWithContentType(String url, @Nullable Map<String,List<String>> headers, @Nullable byte[] dataToSend, Localization localization, String contentType) throws IOException, ReCaptchaException
      Convenient method to send a POST request using the specified value of the Content-Type header with a given Localization.
      Parameters:
      url - the URL that is pointing to the wanted resource
      headers - a list of headers that will be used in the request. Any default headers should be overridden by these.
      dataToSend - byte array that will be sent when doing the request.
      localization - the source of the value of the Accept-Language header
      contentType - the mime type of the body sent, which will be set as the value of the Content-Type header
      Returns:
      the result of the POST request
      Throws:
      IOException
      ReCaptchaException
      See Also:
    • postWithContentType

      public Response postWithContentType(String url, @Nullable Map<String,List<String>> headers, @Nullable byte[] dataToSend, String contentType) throws IOException, ReCaptchaException
      Convenient method to send a POST request using the specified value of the Content-Type header.
      Parameters:
      url - the URL that is pointing to the wanted resource
      headers - a list of headers that will be used in the request. Any default headers should be overridden by these.
      dataToSend - byte array that will be sent when doing the request.
      contentType - the mime type of the body sent, which will be set as the value of the Content-Type header
      Returns:
      the result of the POST request
      Throws:
      IOException
      ReCaptchaException
      See Also:
    • postWithContentTypeJson

      public Response postWithContentTypeJson(String url, @Nullable Map<String,List<String>> headers, @Nullable byte[] dataToSend, Localization localization) throws IOException, ReCaptchaException
      Convenient method to send a POST request the JSON mime type as the value of the Content-Type header with a given Localization.
      Parameters:
      url - the URL that is pointing to the wanted resource
      headers - a list of headers that will be used in the request. Any default headers should be overridden by these.
      dataToSend - byte array that will be sent when doing the request.
      localization - the source of the value of the Accept-Language header
      Returns:
      the result of the POST request
      Throws:
      IOException
      ReCaptchaException
      See Also:
    • postWithContentTypeJson

      public Response postWithContentTypeJson(String url, @Nullable Map<String,List<String>> headers, @Nullable byte[] dataToSend) throws IOException, ReCaptchaException
      Convenient method to send a POST request the JSON mime type as the value of the Content-Type header.
      Parameters:
      url - the URL that is pointing to the wanted resource
      headers - a list of headers that will be used in the request. Any default headers should be overridden by these.
      dataToSend - byte array that will be sent when doing the request.
      Returns:
      the result of the POST request
      Throws:
      IOException
      ReCaptchaException
      See Also:
    • execute

      public abstract Response execute(@Nonnull Request request) throws IOException, ReCaptchaException
      Do a request using the specified Request object.
      Returns:
      the result of the request
      Throws:
      IOException
      ReCaptchaException
    • toString

      public String toString()
      Overrides:
      toString in class Object