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

Commit 3316c25

Browse files
committed
cbz creation with zipfile
1 parent aa409aa commit 3316c25

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

comic-scrapper.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import shutil
77
import os
88
import concurrent.futures
9-
import subprocess
9+
from zipfile import ZipFile, ZIP_DEFLATED
1010

1111

1212
def download_image(url, filename):
@@ -16,6 +16,18 @@ def download_image(url, filename):
1616
del response
1717

1818

19+
def zipdir(folder, filename):
20+
assert os.path.isdir(folder)
21+
zipf = ZipFile(filename, 'w', ZIP_DEFLATED)
22+
for root, dirs, files in os.walk(folder):
23+
# note: ignore empty directories
24+
for fn in files:
25+
zipf.write(
26+
os.path.join(root, fn),
27+
os.path.relpath(os.path.join(root, fn), folder))
28+
zipf.close()
29+
30+
1931
def readcomics_extract_chapters(url):
2032
comic = url.split('/')[-1]
2133
r = requests.get(url)
@@ -53,9 +65,7 @@ def readcomics_download_chapter(url, chapter_num, download_location):
5365
for image, filename in urls:
5466
executor.submit(download_image, image, filename)
5567
# Convert the folder to a comic book zip filename
56-
subprocess.check_output(
57-
['zip', '-r', chapter_location + '.cbz', chapter_location],
58-
stderr=subprocess.STDOUT)
68+
zipdir(chapter_location, chapter_location + '.cbz')
5969
shutil.rmtree(chapter_location)
6070
print(chapter_name + ': Downloaded')
6171

@@ -110,7 +120,8 @@ def main():
110120
# Download chapters
111121
if 'readcomics.tv' in url:
112122
for k in keys:
113-
download_location = os.path.join(args.location, comic)
123+
download_location = os.path.abspath(
124+
os.path.join(args.location, comic))
114125
if not os.path.exists(download_location):
115126
os.makedirs(download_location)
116127
readcomics_download_chapter(chapters[k], k, download_location)

0 commit comments

Comments
 (0)