Skip to content

Commit

Permalink
add data-saver flag (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
frozenpandaman committed Jul 3, 2021
1 parent d8b3a4d commit 3883aa4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ A Python script to download manga from [MangaDex.org](https://mangadex.org/).
```
$ git clone https://github.com/frozenpandaman/mangadex-dl
$ cd mangadex-dl/
$ python mangadex-dl.py [-l language_code] [-a]
$ python mangadex-dl.py [-l language_code] [-d] [-a]
```

The `-l` flag allows you to download releases in languages other than English. For a list of language codes, see [the wiki page](https://github.com/frozenpandaman/mangadex-dl/wiki/language-codes).

The `-d` flag, if present, downloads page images in lower quality (higher JPG compression/"data saver").

The `-a` flag, if present, packages downloaded chapters into .cbz [comic book archive](https://en.wikipedia.org/wiki/Comic_book_archive) files.

You can also execute the script via `./mangadex-dl.py` on macOS and Linux. On Windows, use a backslash.

### Example usage
```
$ ./mangadex-dl.py
mangadex-dl v0.4.1
Enter manga URL: https://mangadex.org/title/311/yotsuba-to
mangadex-dl v0.5.0
Enter manga URL: https://mangadex.org/title/58be6aa6-06cb-4ca5-bd20-f1392ce451fb
Title: Yotsuba to!
Available chapters:
Expand Down
16 changes: 11 additions & 5 deletions mangadex-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import requests, time, os, sys, re, json, html, zipfile, argparse, shutil

A_VERSION = "0.4.1"
A_VERSION = "0.5.0"

def pad_filename(str):
digits = re.compile('(\\d+)')
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_title(uuid, lang_code):
exit(1)
return title

def dl(manga_id, lang_code, zip_up):
def dl(manga_id, lang_code, zip_up, ds):
uuid = manga_id

if manga_id.isnumeric():
Expand Down Expand Up @@ -162,8 +162,11 @@ def dl(manga_id, lang_code, zip_up):
images = []
accesstoken = ""
chaphash = chapter["data"]["attributes"]["hash"]
for page_filename in chapter["data"]["attributes"]["data"]:
images.append("{}/data/{}/{}".format(baseurl, chaphash, page_filename))
datamode = "dataSaver" if ds else "data"
datamode2 = "data-saver" if ds else "data"

for page_filename in chapter["data"]["attributes"][datamode]:
images.append("{}/{}/{}/{}".format(baseurl, datamode2, chaphash, page_filename))

# get group names & make combined name
group_uuids = []
Expand Down Expand Up @@ -232,12 +235,15 @@ def dl(manga_id, lang_code, zip_up):
parser = argparse.ArgumentParser()
parser.add_argument("-l", dest="lang", required=False, action="store",
help="download in specified language code (default: en)", default="en")
parser.add_argument("-d", dest="datasaver", required=False, action="store_true",
help="downloads images in lower quality")
parser.add_argument("-a", dest="cbz", required=False, action="store_true",
help="packages chapters into .cbz format")
args = parser.parse_args()

lang_code = "en" if args.lang is None else str(args.lang)
zip_up = args.cbz
ds = args.datasaver

# prompt for manga
url = ""
Expand All @@ -250,4 +256,4 @@ def dl(manga_id, lang_code, zip_up):
print("Error with URL.")
exit(1)

dl(manga_id, lang_code, zip_up)
dl(manga_id, lang_code, zip_up, ds)

0 comments on commit 3883aa4

Please sign in to comment.