Class Downloader


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

      Constructors 
      Constructor Description
      Downloader()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract Response execute​(Request request)
      Do a request using the specified Request object.
      Response get​(java.lang.String url)
      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.
      Response get​(java.lang.String url, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
      Do a GET request with the specified headers.
      Response get​(java.lang.String url, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, Localization localization)
      Do a GET request with the specified headers.

      It will set the Accept-Language header to the language of the localization parameter.
      Response get​(java.lang.String url, Localization localization)
      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.
      Response head​(java.lang.String url)
      Do a HEAD request.
      Response head​(java.lang.String url, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
      Do a HEAD request with the specified headers.
      Response post​(java.lang.String url, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, byte[] dataToSend)
      Do a POST request with the specified headers, sending the data array.
      Response post​(java.lang.String url, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, byte[] dataToSend, Localization localization)
      Do a POST request with the specified headers, sending the data array.
      Response postWithContentType​(java.lang.String url, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, byte[] dataToSend, java.lang.String contentType)
      Convenient method to send a POST request using the specified value of the Content-Type header.
      Response postWithContentType​(java.lang.String url, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, byte[] dataToSend, Localization localization, java.lang.String contentType)
      Convenient method to send a POST request using the specified value of the Content-Type header with a given Localization.
      Response postWithContentTypeJson​(java.lang.String url, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, byte[] dataToSend)
      Convenient method to send a POST request the JSON mime type as the value of the Content-Type header.
      Response postWithContentTypeJson​(java.lang.String url, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, byte[] dataToSend, Localization localization)
      Convenient method to send a POST request the JSON mime type as the value of the Content-Type header with a given Localization.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Downloader

        public Downloader()
    • Method Detail

      • get

        public Response get​(java.lang.String url)
                     throws java.io.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:
        java.io.IOException
        ReCaptchaException
      • get

        public Response get​(java.lang.String url,
                            Localization localization)
                     throws java.io.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:
        java.io.IOException
        ReCaptchaException
      • get

        public Response get​(java.lang.String url,
                            @Nullable
                            java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
                     throws java.io.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:
        java.io.IOException
        ReCaptchaException
      • get

        public Response get​(java.lang.String url,
                            @Nullable
                            java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers,
                            Localization localization)
                     throws java.io.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:
        java.io.IOException
        ReCaptchaException
      • head

        public Response head​(java.lang.String url)
                      throws java.io.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:
        java.io.IOException
        ReCaptchaException
      • head

        public Response head​(java.lang.String url,
                             @Nullable
                             java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
                      throws java.io.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:
        java.io.IOException
        ReCaptchaException
      • post

        public Response post​(java.lang.String url,
                             @Nullable
                             java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers,
                             @Nullable
                             byte[] dataToSend)
                      throws java.io.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:
        java.io.IOException
        ReCaptchaException
      • post

        public Response post​(java.lang.String url,
                             @Nullable
                             java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers,
                             @Nullable
                             byte[] dataToSend,
                             Localization localization)
                      throws java.io.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:
        java.io.IOException
        ReCaptchaException
      • postWithContentType

        public Response postWithContentType​(java.lang.String url,
                                            @Nullable
                                            java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers,
                                            @Nullable
                                            byte[] dataToSend,
                                            Localization localization,
                                            java.lang.String contentType)
                                     throws java.io.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:
        java.io.IOException
        ReCaptchaException
        See Also:
        post(String, Map, byte[], Localization)
      • postWithContentType

        public Response postWithContentType​(java.lang.String url,
                                            @Nullable
                                            java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers,
                                            @Nullable
                                            byte[] dataToSend,
                                            java.lang.String contentType)
                                     throws java.io.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:
        java.io.IOException
        ReCaptchaException
        See Also:
        post(String, Map, byte[], Localization)
      • postWithContentTypeJson

        public Response postWithContentTypeJson​(java.lang.String url,
                                                @Nullable
                                                java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers,
                                                @Nullable
                                                byte[] dataToSend,
                                                Localization localization)
                                         throws java.io.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:
        java.io.IOException
        ReCaptchaException
        See Also:
        post(String, Map, byte[], Localization)
      • postWithContentTypeJson

        public Response postWithContentTypeJson​(java.lang.String url,
                                                @Nullable
                                                java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers,
                                                @Nullable
                                                byte[] dataToSend)
                                         throws java.io.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:
        java.io.IOException
        ReCaptchaException
        See Also:
        post(String, Map, byte[], Localization)