Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit aa409aa

Browse files
committed
Added custom chapter download
1 parent bb0b6bb commit aa409aa

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ If you want to set a custom location, add -l and input the location
2828
python comic-scrapper -l ~/Comics/ http://www.readcomics.tv/comic/spider-man-2016
2929
```
3030

31+
If you want to download a select few chapters, add -c and input the chapter numbers.
32+
For example, if I want to download chapters 10-20, I use the following command
33+
```
34+
python comic-scrapper -l ~/Comics/ -c 10:20 http://www.readcomics.tv/comic/spider-man-2016
35+
```
36+
Note: Only individual chapters or sequential chunks (start:stop) can currently be downloaded.
37+
3138
You can also make the comic-scrapper script an executable and call it directly
3239
```
3340
chmod +x comic-scrapper
3441
./comic-scrapper -l ~/Comics/ http://www.readcomics.tv/comic/spider-man-2016
3542
```
36-
37-
(Chapter selection option coming up soon)

comic-scrapper.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import bs4 as bsoup
44
import requests
55
from collections import defaultdict
6-
# from pprint import pprint
76
import shutil
87
import os
98
import concurrent.futures
@@ -50,7 +49,7 @@ def readcomics_download_chapter(url, chapter_num, download_location):
5049
if not os.path.exists(chapter_location):
5150
os.makedirs(chapter_location)
5251
# Start downloading the urls
53-
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
52+
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
5453
for image, filename in urls:
5554
executor.submit(download_image, image, filename)
5655
# Convert the folder to a comic book zip filename
@@ -76,17 +75,41 @@ def main():
7675
help='Comic urls to download')
7776
parser.add_argument(
7877
"-l", "--location", default=os.getcwd(), help="set download location")
78+
parser.add_argument(
79+
"-c", "--chapters", default=False,
80+
help="Specify chapters to download separated by : (10:20).")
7981

8082
args = parser.parse_args()
8183

8284
for url in args.urls:
8385
comic = url.split('/')[-1]
8486
print('Downloading comic: ' + comic)
87+
88+
# Extract chapters
8589
if 'readcomics.tv' in url:
8690
chapters = readcomics_extract_chapters(url)
8791

92+
# Get chapters to download
93+
if args.chapters:
94+
try:
95+
start_stop = args.chapters.split(':')
96+
if len(start_stop) == 1:
97+
keys = [int(start_stop)]
98+
elif len(start_stop) == 2:
99+
keys = list(range(
100+
int(start_stop[0]), int(start_stop[1])+1, 1))
101+
else:
102+
raise SyntaxError(
103+
"Chapter inputs should be separated by ':'")
104+
except TypeError:
105+
raise SyntaxError("Chapter inputs should be separated by ':'")
106+
exit()
107+
else:
108+
keys = chapters.keys
109+
110+
# Download chapters
88111
if 'readcomics.tv' in url:
89-
for k in chapters:
112+
for k in keys:
90113
download_location = os.path.join(args.location, comic)
91114
if not os.path.exists(download_location):
92115
os.makedirs(download_location)

0 commit comments

Comments
 (0)