From 5de66eb4ca4808693268646373d021ddeb802729 Mon Sep 17 00:00:00 2001 From: Jishnu M Date: Tue, 18 Jun 2024 12:15:39 +0530 Subject: [PATCH] Update docs and bump version --- README.md | 25 ++++++++++++++++++------- pypdl/manager.py | 2 -- setup.py | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 770c741..a8b84c6 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ The `Pypdl` object provides additional options for advanced usage: ```py from pypdl import Pypdl -dl = Pypdl(allow_reuse=False) +dl = Pypdl(allow_reuse=False, logger=default_logger("Pypdl")) dl.start( url='http://example.com/file.txt', file_path='file.txt', @@ -63,7 +63,8 @@ dl.start( ``` Each option is explained below: -- `allow_reuse`: Whether to allow reuse of existing Pypdl object for next download. The default value is `False`. +- `allow_reuse`: Whether to allow reuse of existing Pypdl object for next download. The default value is `False`. +- `logger`: A logger object to log messages. The default value is custom `Logger` with the name Pypdl. - `url`: The URL of the file to download. - `file_path`: An optional path to save the downloaded file. By default, it uses the present working directory. If `file_path` is a directory, then the file is downloaded into it otherwise, the file is downloaded into the given path. - `segments`: The number of segments the file should be divided in multi-segmented download. The default value is 10. @@ -119,7 +120,7 @@ if __name__ == '__main__': This example downloads a file from the internet using 10 segments and displays the download progress. If the download fails, it will retry up to 3 times. we are also using headers, proxies and authentication. -Another example of implementing pause resume functionality and printing the progress to console: +Another example of implementing pause resume functionality, printing the progress to console and changing log level to debug: ```py from pypdl import Pypdl @@ -127,6 +128,9 @@ from pypdl import Pypdl # create a pypdl object dl = Pypdl() +# changing log level to debug +dl.logger.setLevel('DEBUG') + # start the download process # block=False so we can print the progress # display=False so we can print the progress ourselves @@ -183,9 +187,10 @@ if dl.completed: else: print('Hash is invalid') ``` -An example of using Pypdl object with `allow_reuse` set to `True`: +An example of using Pypdl object with `allow_reuse` set to `True` and custom logger: ```py +import logging from pypdl import Pypdl urls = [ @@ -196,8 +201,11 @@ urls = [ 'https://example.com/file5.zip', ] +# create a custom logger +logger = logging.getLogger('custom') + # create a pypdl object -dl = Pypdl(allow_reuse=True) +dl = Pypdl(allow_reuse=True, logger=logger) for url in urls: dl.start(url, block=True) @@ -274,7 +282,7 @@ The `Pypdl` class represents a file downloader that can download a file from a g #### Arguments - `allow_reuse`: (bool, Optional) Whether to allow reuse of existing `Pypdl` object for next download. The default value is `False`.It's essential to use `shutdown()` method when `allow_reuse` is enabled to ensure efficient resource management. -- Additional keyword arguments +- Supported Keyword Arguments: - `params` (default `None`): Parameters to be sent in the query string of the new request. - `data` (default `None`): The data to send in the body of the request. - `json` (default `None`): A JSON-compatible Python object to send in the body of the request. @@ -289,6 +297,7 @@ The `Pypdl` class represents a file downloader that can download a file from a g - `ssl` (default `None`): SSL validation mode. - `proxy_headers` (default `None`): HTTP headers to send to the proxy if the `proxy` parameter has been provided. + For detailed information on each parameter, refer the [aiohttp documentation](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession.request). Please ensure that only the *supported keyword arguments* are used. Using unsupported or irrelevant keyword arguments may lead to unexpected behavior or errors. #### Attributes - `size`: The total size of the file to be downloaded, in bytes. @@ -336,7 +345,7 @@ The `PypdlFactory` class manages multiple instances of the `Pypdl` downloader. I - `instances`: (int, Optional) The number of `Pypdl` instances to create. The default value is 5. - `allow_reuse`: (bool, Optional) Whether to allow reuse of existing `PypdlFactory` objects for next download. The default value is `False`. It's essential to use `shutdown()` method when `allow_reuse` is enabled to ensure efficient resource management. -- Additional keyword arguments +- Supported Keyword Arguments: - `params` (default `None`): Parameters to be sent in the query string of the new request. - `data` (default `None`): The data to send in the body of the request. - `json` (default `None`): A JSON-compatible Python object to send in the body of the request. @@ -351,6 +360,8 @@ The `PypdlFactory` class manages multiple instances of the `Pypdl` downloader. I - `ssl` (default `None`): SSL validation mode. - `proxy_headers` (default `None`): HTTP headers to send to the proxy if the `proxy` parameter has been provided. + For detailed information on each parameter, refer the [aiohttp documentation](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession.request). Please ensure that only the *supported keyword arguments* are used. Using unsupported or irrelevant keyword arguments may lead to unexpected behavior or errors. + #### Attributes diff --git a/pypdl/manager.py b/pypdl/manager.py index c9f045d..35f0488 100644 --- a/pypdl/manager.py +++ b/pypdl/manager.py @@ -94,9 +94,7 @@ def download(): try: _url = mirror_func() if i > 0 and callable(mirror_func) else url self._reset() - self.logger.debug("Downloading, url: %s attempt: %s", _url, (i + 1)) - result = self._execute( _url, file_path, diff --git a/setup.py b/setup.py index 409f00b..6a0b750 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = "1.4.0" +VERSION = "1.4.1" DESCRIPTION = "A concurrent python download manager" with open("README.md", "r") as f: LONG_DESCRIPTION = f.read()