-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest.py
41 lines (30 loc) · 1.03 KB
/
request.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from settings import *
from stringHelpers import *
import requests
import shutil
import os
import threading
def send_request(url, binary=False):
try:
request = requests.get(url, stream=binary)
except:
print(REQUEST_ERROR + " " + url)
exit()
return request
def not_released_yet(seriesName, chpNum):
manga_url = get_url(seriesName, chpNum)
html = send_request(manga_url).text
return NOT_RELEASED_MSG in html
# Add a lock for synchronizing access to os.makedirs
download_lock = threading.Lock()
def download_img(url, download_path, pgNum, chpNum):
with download_lock:
if not os.path.exists(download_path):
os.makedirs(download_path)
img_name = add_zeros(str(pgNum)) + FILE_EXT
img_path = os.path.join(download_path, img_name)
request = send_request(url, True)
with open(img_path, 'wb') as file_path:
request.raw.decode_content = True
shutil.copyfileobj(request.raw, file_path)
print(DOWNLOADING_MSG + str(pgNum) + " Chapter " + str(chpNum))