fix image suffix and add readme entry of --format
This commit is contained in:
parent
95ed20dde6
commit
10c9fc47b7
2 changed files with 36 additions and 10 deletions
30
README.md
30
README.md
|
@ -60,9 +60,6 @@ See the docker [README](./docker/README.md)
|
|||
|
||||
## Options
|
||||
|
||||
> "--format" currently only works with "", "pdf", "zip", "rar" and "cbz". As it just renames the zip file with the new
|
||||
> suffix (except pdf). For pdf creation you have to install img2pdf.
|
||||
|
||||
```txt
|
||||
usage: manga-dlp.py [-h] (-u URL_UUID | --read READ | -v) [-c CHAPTERS] [-p PATH] [-l LANG] [--list] [--format FORMAT] [--forcevol] [--wait WAIT] [--verbose]
|
||||
|
||||
|
@ -169,6 +166,33 @@ is `<script_dir>/downloads`. Absolute and relative paths are supported.
|
|||
|
||||
This will save all mangas/chapters in the path `/media/mangas/<manga title>/<chapter name>`
|
||||
|
||||
### Set output format
|
||||
|
||||
> `--format` currently only works with `""`, `"pdf"`, `"zip"`, `"rar"` and `"cbz"`.
|
||||
> As it just renames the zip file with the new
|
||||
> suffix (except pdf).
|
||||
|
||||
You can specify the output format of the manga images with the `--format` option.
|
||||
The default is set to `.cbz`, so if no format is given it falls back to `<manga-name>/<chapter_name>.cbz`
|
||||
|
||||
For pdf creation you have to install [img2pdf](https://pypi.org/project/img2pdf/).
|
||||
With the amd64 docker image it is already installed
|
||||
see more in the Docker [README.md](docker/README.md).
|
||||
|
||||
#### Supported format options are:
|
||||
|
||||
* cbz - `--format "cbz"` or `--format ".cbz"` **- default**
|
||||
* cbr - `--format "cbr"` or `--format ".cbr"`
|
||||
* zip - `--format "zip"` or `--format ".zip"`
|
||||
* pdf - `--format "pdf"` or `--format ".pdf"`
|
||||
* _none_ - `--format ""` - this saves the images just in a folder
|
||||
|
||||
#### Example:
|
||||
|
||||
`python3 manga-dlp.py <other options> --format "zip"`
|
||||
|
||||
This will download the chapter and save it as a zip archive.
|
||||
|
||||
## Contribution / Bugs
|
||||
|
||||
For suggestions for improvement, just open a pull request.
|
||||
|
|
|
@ -13,21 +13,23 @@ def download_chapter(
|
|||
image_urls: list, chapter_path: str or Path, download_wait: float, verbose: bool
|
||||
) -> None:
|
||||
total_img = len(image_urls)
|
||||
for img_num, img in enumerate(image_urls, 1):
|
||||
for image_num, image in enumerate(image_urls, 1):
|
||||
# get image suffix
|
||||
image_suffix = str(Path(image).suffix) or ".png"
|
||||
# set image path
|
||||
image_path = Path(f"{chapter_path}/{img_num:03d}")
|
||||
image_path = Path(f"{chapter_path}/{image_num:03d}{image_suffix}")
|
||||
# show progress bar if verbose logging is not active
|
||||
if verbose:
|
||||
print(f"INFO: Downloading image {img_num}/{total_img}")
|
||||
print(f"INFO: Downloading image {image_num}/{total_img}")
|
||||
else:
|
||||
utils.progress_bar(img_num, total_img)
|
||||
utils.progress_bar(image_num, total_img)
|
||||
|
||||
counter = 1
|
||||
while counter <= 3:
|
||||
try:
|
||||
r = requests.get(img, stream=True)
|
||||
r = requests.get(image, stream=True)
|
||||
if r.status_code != 200:
|
||||
print(f"ERR: Request for image {img} failed, retrying")
|
||||
print(f"ERR: Request for image {image} failed, retrying")
|
||||
raise ConnectionError
|
||||
except KeyboardInterrupt:
|
||||
print("ERR: Stopping")
|
||||
|
@ -50,5 +52,5 @@ def download_chapter(
|
|||
print("ERR: Can't write file")
|
||||
raise IOError
|
||||
|
||||
img_num += 1
|
||||
image_num += 1
|
||||
sleep(download_wait)
|
||||
|
|
Loading…
Reference in a new issue