Refine Proxy

This commit is contained in:
Mathhew
2021-06-04 13:43:55 +08:00
parent 863dd3bb81
commit 7fe5b69ad2
3 changed files with 72 additions and 49 deletions

32
core.py
View File

@@ -351,17 +351,17 @@ def trimblank(s: str):
# path = examle:photo , video.in the Project Folder!
def download_file_with_filename(url, filename, path, conf: config.Config, filepath, failed_folder):
switch, proxy, timeout, retry_count, proxytype = config.Config().proxy()
configProxy = conf.proxy()
for i in range(retry_count):
for i in range(configProxy.retry):
try:
if switch == 1 or switch == '1':
if configProxy.enable:
if not os.path.exists(path):
os.makedirs(path)
proxies = get_proxy(proxy, proxytype)
proxies = configProxy.proxies()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'}
r = requests.get(url, headers=headers, timeout=timeout, proxies=proxies)
r = requests.get(url, headers=headers, timeout=configProxy.timeout, proxies=proxies)
if r == '':
print('[-]Movie Data not found!')
return
@@ -373,7 +373,7 @@ def download_file_with_filename(url, filename, path, conf: config.Config, filepa
os.makedirs(path)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'}
r = requests.get(url, timeout=timeout, headers=headers)
r = requests.get(url, timeout=configProxy.timeout, headers=headers)
if r == '':
print('[-]Movie Data not found!')
return
@@ -382,16 +382,16 @@ def download_file_with_filename(url, filename, path, conf: config.Config, filepa
return
except requests.exceptions.RequestException:
i += 1
print('[-]Image Download : Connect retry ' + str(i) + '/' + str(retry_count))
print('[-]Image Download : Connect retry ' + str(i) + '/' + str(configProxy.retry))
except requests.exceptions.ConnectionError:
i += 1
print('[-]Image Download : Connect retry ' + str(i) + '/' + str(retry_count))
print('[-]Image Download : Connect retry ' + str(i) + '/' + str(configProxy.retry))
except requests.exceptions.ProxyError:
i += 1
print('[-]Image Download : Connect retry ' + str(i) + '/' + str(retry_count))
print('[-]Image Download : Connect retry ' + str(i) + '/' + str(configProxy.retry))
except requests.exceptions.ConnectTimeout:
i += 1
print('[-]Image Download : Connect retry ' + str(i) + '/' + str(retry_count))
print('[-]Image Download : Connect retry ' + str(i) + '/' + str(configProxy.retry))
print('[-]Connect Failed! Please check your Proxy or Network!')
moveFailedFolder(filepath, failed_folder)
return
@@ -399,8 +399,8 @@ def download_file_with_filename(url, filename, path, conf: config.Config, filepa
def trailer_download(trailer, leak_word, c_word, number, path, filepath, conf: config.Config, failed_folder):
if download_file_with_filename(trailer, number + leak_word + c_word + '-trailer.mp4', path, conf, filepath, failed_folder) == 'failed':
return
switch, _proxy, _timeout, retry, _proxytype = conf.proxy()
for i in range(retry):
configProxy = conf.proxy()
for i in range(configProxy.retry):
if os.path.getsize(path+'/' + number + leak_word + c_word + '-trailer.mp4') == 0:
print('[!]Video Download Failed! Trying again. [{}/3]', i + 1)
download_file_with_filename(trailer, number + leak_word + c_word + '-trailer.mp4', path, conf, filepath, failed_folder)
@@ -419,8 +419,8 @@ def extrafanart_download(data, path, conf: config.Config, filepath, failed_folde
if download_file_with_filename(url, '/extrafanart-' + str(j)+'.jpg', path, conf, filepath, failed_folder) == 'failed':
moveFailedFolder(filepath, failed_folder)
return
switch, _proxy, _timeout, retry, _proxytype = conf.proxy()
for i in range(retry):
configProxy = conf.proxy()
for i in range(configProxy.retry):
if os.path.getsize(path + '/extrafanart-' + str(j) + '.jpg') == 0:
print('[!]Image Download Failed! Trying again. [{}/3]', i + 1)
download_file_with_filename(url, '/extrafanart-' + str(j)+'.jpg', path, conf, filepath,
@@ -441,8 +441,8 @@ def image_download(cover, number, leak_word, c_word, path, conf: config.Config,
moveFailedFolder(filepath, failed_folder)
return
switch, _proxy, _timeout, retry, _proxytype = conf.proxy()
for i in range(retry):
configProxy = conf.proxy()
for i in range(configProxy.retry):
if os.path.getsize(path + '/' + number + leak_word + c_word + '-fanart.jpg') == 0:
print('[!]Image Download Failed! Trying again. [{}/3]', i + 1)
download_file_with_filename(cover, number + leak_word + c_word + '-fanart.jpg', path, conf, filepath, failed_folder)