From dca19f0fd4464547fb7c9115b4558c9527c7a260 Mon Sep 17 00:00:00 2001 From: Jishnu M Date: Tue, 18 Jun 2024 14:46:44 +0530 Subject: [PATCH] Improve file organization --- README.md | 4 ++-- pypdl/__init__.py | 5 ++++- pypdl/downloader.py | 2 +- pypdl/main.py | 18 ------------------ pypdl/{factory.py => pypdl_factory.py} | 10 ++++++++-- pypdl/{manager.py => pypdl_manager.py} | 12 +++++++++--- setup.py | 6 ++++-- 7 files changed, 28 insertions(+), 29 deletions(-) delete mode 100644 pypdl/main.py rename pypdl/{factory.py => pypdl_factory.py} (97%) rename pypdl/{manager.py => pypdl_manager.py} (97%) diff --git a/README.md b/README.md index b145a5a..1b53310 100644 --- a/README.md +++ b/README.md @@ -416,9 +416,9 @@ The `Basicdown` class is the base downloader class that provides the basic struc - `download(url, path, mode, session, **kwargs)`: Downloads data in chunks. -#### `Simpledown()` +#### `Singledown()` -The `Simpledown` class extends `Basicdown` and is responsible for downloading a whole file in a single segment. +The `Singledown` class extends `Basicdown` and is responsible for downloading a whole file in a single segment. ##### Methods diff --git a/pypdl/__init__.py b/pypdl/__init__.py index 087d97d..6ae884c 100644 --- a/pypdl/__init__.py +++ b/pypdl/__init__.py @@ -1 +1,4 @@ -from .main import Pypdl, PypdlFactory +__version__ = "1.4.1" + +from .pypdl_manager import Pypdl +from .pypdl_factory import PypdlFactory diff --git a/pypdl/downloader.py b/pypdl/downloader.py index 370c92a..ba2df98 100644 --- a/pypdl/downloader.py +++ b/pypdl/downloader.py @@ -30,7 +30,7 @@ async def download( break -class Simpledown(Basicdown): +class Singledown(Basicdown): """Class for downloading the whole file in a single segment.""" async def worker( diff --git a/pypdl/main.py b/pypdl/main.py deleted file mode 100644 index 1746cb6..0000000 --- a/pypdl/main.py +++ /dev/null @@ -1,18 +0,0 @@ -from .factory import Factory -from .manager import DownloadManager - - -class Pypdl(DownloadManager): - """ - A multi-segment file downloader that supports progress tracking, retries, pause/resume functionality etc. - - This class also supports additional keyword arguments specified in the documentation. - """ - - -class PypdlFactory(Factory): - """ - A factory class for managing multiple instances of the Pypdl downloader. - - This class also supports additional keyword arguments specified in the documentation. - """ diff --git a/pypdl/factory.py b/pypdl/pypdl_factory.py similarity index 97% rename from pypdl/factory.py rename to pypdl/pypdl_factory.py index 8d39531..6ed5382 100644 --- a/pypdl/factory.py +++ b/pypdl/pypdl_factory.py @@ -4,7 +4,7 @@ from logging import Logger, getLogger from typing import Union -from .manager import DownloadManager as Pypdl +from .pypdl_manager import Pypdl from .utls import ( AutoShutdownFuture, ScreenCleaner, @@ -15,7 +15,13 @@ ) -class Factory: +class PypdlFactory: + """ + A factory class for managing multiple instances of the Pypdl downloader. + + This class also supports additional keyword arguments specified in the documentation. + """ + def __init__( self, instances: int = 2, diff --git a/pypdl/manager.py b/pypdl/pypdl_manager.py similarity index 97% rename from pypdl/manager.py rename to pypdl/pypdl_manager.py index 35f0488..cdf484c 100644 --- a/pypdl/manager.py +++ b/pypdl/pypdl_manager.py @@ -9,7 +9,7 @@ import aiohttp -from .downloader import Multidown, Simpledown +from .downloader import Multidown, Singledown from .utls import ( AutoShutdownFuture, FileValidator, @@ -24,7 +24,13 @@ ) -class DownloadManager: +class Pypdl: + """ + A multi-segment file downloader that supports progress tracking, retries, pause/resume functionality etc. + + This class also supports additional keyword arguments specified in the documentation. + """ + def __init__( self, allow_reuse: bool = False, @@ -270,7 +276,7 @@ async def _multi_segment(self, segments, segment_table): async def _single_segment(self, url, file_path): self.logger.debug("Single-Segment download started") async with aiohttp.ClientSession() as session: - sd = Simpledown(self._interrupt) + sd = Singledown(self._interrupt) self._workers.append(sd) try: await sd.worker(url, file_path, session, **self._kwargs) diff --git a/setup.py b/setup.py index 6a0b750..b5a19dc 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,12 @@ from setuptools import setup, find_packages -VERSION = "1.4.1" -DESCRIPTION = "A concurrent python download manager" +DESCRIPTION = "A concurrent pure python download manager" with open("README.md", "r") as f: LONG_DESCRIPTION = f.read() +with open("pypdl/__init__.py", "r") as f: + VERSION = f.readline().split("=")[1].strip().strip("\"'") + setup( name="pypdl", version=VERSION,