Metadata-Version: 2.4
Name: parallelmediadownloader
Version: 0.2.0
Summary: This project helps you to download media file.
Author-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
Maintainer-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
License: MIT License
        
        Copyright (c) 2019 Yukihiko Shinoda
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepage, https://github.com/yukihiko-shinoda/parallel-media-downloader
Project-URL: repository, https://github.com/yukihiko-shinoda/parallel-media-downloader
Keywords: parallel,media,download,downloader,image,jpg,jpeg,png,gif,aiohttp
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: AsyncIO
Classifier: Framework :: aiohttp
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: System :: Archiving
Classifier: Topic :: System :: Archiving :: Backup
Classifier: Typing :: Typed
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp
Dynamic: license-file

# Parallel Media Downloader

[![Test](https://github.com/yukihiko-shinoda/parallel-media-downloader/workflows/Test/badge.svg)](https://github.com/yukihiko-shinoda/parallel-media-downloader/actions?query=workflow%3ATest)
[![Test Coverage](https://api.codeclimate.com/v1/badges/d8aa182721f860764d4d/test_coverage)](https://codeclimate.com/github/yukihiko-shinoda/parallel-media-downloader/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/d8aa182721f860764d4d/maintainability)](https://codeclimate.com/github/yukihiko-shinoda/parallel-media-downloader/maintainability)
[![Code Climate technical debt](https://img.shields.io/codeclimate/tech-debt/yukihiko-shinoda/parallel-media-downloader)](https://codeclimate.com/github/yukihiko-shinoda/parallel-media-downloader)
[![Updates](https://pyup.io/repos/github/yukihiko-shinoda/parallel-media-downloader/shield.svg)](https://pyup.io/repos/github/yukihiko-shinoda/parallel-media-downloader/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/parallelmediadownloader)](https://pypi.org/project/parallelmediadownloader/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/parallelmediadownloader)](https://pypi.org/project/parallelmediadownloader/)
[![Twitter URL](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fyukihiko-shinoda%2Fparallel-media-downloader)](http://twitter.com/share?text=Parallel%20Media%20Downloader&url=https://pypi.org/project/parallelmediadownloader/&hashtags=python)

Helps you to download media file in parallel without async / await syntax.

## Feature

This project helps you to download media files in parallel without async / await syntax.

## Installation

```console
pip install parallelmediadownloader
```

## Usage

Minimum example:

```python
from datetime import datetime

from parallelmediadownloader.media_download_coroutine import DownloadOrder
from parallelmediadownloader.media_file import SaveOrder
from parallelmediadownloader.parallel_media_downloader import ParallelMediaDownloader

path_directory_download = "path/directory/download"
created_date_time = datetime.now()
list_download_order = [
    DownloadOrder(
        "https://example.com/test01.png",
        SaveOrder(
            path_directory_download,
            "test01.png",
            created_date_time,
        ),
    ),
    DownloadOrder(
        "https://example.com/test02.png",
        SaveOrder(
            path_directory_download,
            "test02.png",
            created_date_time,
        ),
    ),
    DownloadOrder(
        "https://example.com/test03.png",
        SaveOrder(
            path_directory_download,
            "test03.png",
            created_date_time,
        ),
    ),
]
list_media_download_result = ParallelMediaDownloader.execute(list_download_order)
```

## API

### ParallelMediaDownloader.execute

```python
class ParallelMediaDownloader:
    """API of parallel media downloading."""

    @staticmethod
    def execute(
        list_download_order: Iterable[DownloadOrder],
        *,
        limit: int = 5,
        media_filter: Optional[MediaFilter] = None,
        allow_http_status: List[int] = None
    ) -> List[MediaDownloadResult]:
```

#### list_download_order: Iterable[DownloadOrder]

List of `DownloadOrder`. Method will download them in parallel.

#### limit: int = 5

Limit number of parallel processes.

#### media_filter: Optional[MediaFilter] = None

Filter extends `MediaFilter` to remove downloaded media file depending on file or content of media.
`NotImageFilter` will be help to understand its roll:

```python
class NotImageFilter(MediaFilter):
    def _filter(self, media_file: MediaFile) -> bool:
        return not str(media_file.path_file).lower().endswith((".png", ".jpg", ".jpeg", ".gif"))
```

#### allow_http_status: List[int] = None

By default, ParallelMediaDownloader.execute will check HTTP status code by [Response.raise_for_status](https://requests.readthedocs.io/en/master/_modules/requests/models/#Response.raise_for_status) and whole process will stop.
When HTTP status applies allow_http_status, process will continue.
Then, `MediaDownloadResult.media_file` will be `None`.
