Add socks proxy support
This commit is contained in:
@@ -24,9 +24,14 @@ def getXpathSingle(htmlcode,xpath):
|
||||
return result1
|
||||
|
||||
|
||||
def get_proxy(proxy: str) -> dict:
|
||||
def get_proxy(proxy: str, proxytype: str = None) -> dict:
|
||||
''' 获得代理参数,默认http代理
|
||||
'''
|
||||
if proxy:
|
||||
proxies = {"http": "http://" + proxy, "https": "https://" + proxy}
|
||||
if proxytype.startswith("socks"):
|
||||
proxies = {"http": "socks5://" + proxy, "https": "socks5://" + proxy}
|
||||
else:
|
||||
proxies = {"http": "http://" + proxy, "https": "https://" + proxy}
|
||||
else:
|
||||
proxies = {}
|
||||
|
||||
@@ -35,8 +40,8 @@ def get_proxy(proxy: str) -> dict:
|
||||
|
||||
# 网页请求核心
|
||||
def get_html(url, cookies: dict = None, ua: str = None, return_type: str = None):
|
||||
proxy, timeout, retry_count = config.Config().proxy()
|
||||
proxies = get_proxy(proxy)
|
||||
proxy, timeout, retry_count, proxytype = config.Config().proxy()
|
||||
proxies = get_proxy(proxy, proxytype)
|
||||
|
||||
if ua is None:
|
||||
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36"} # noqa
|
||||
@@ -59,14 +64,16 @@ def get_html(url, cookies: dict = None, ua: str = None, return_type: str = None)
|
||||
|
||||
except requests.exceptions.ProxyError:
|
||||
print("[-]Connect retry {}/{}".format(i + 1, retry_count))
|
||||
except requests.exceptions.ConnectionError:
|
||||
print("[-]Connect retry {}/{}".format(i + 1, retry_count))
|
||||
print('[-]Connect Failed! Please check your Proxy or Network!')
|
||||
input("Press ENTER to exit!")
|
||||
exit()
|
||||
|
||||
|
||||
def post_html(url: str, query: dict) -> requests.Response:
|
||||
proxy, timeout, retry_count = config.Config().proxy()
|
||||
proxies = get_proxy(proxy)
|
||||
proxy, timeout, retry_count, proxytype = config.Config().proxy()
|
||||
proxies = get_proxy(proxy, proxytype)
|
||||
|
||||
for i in range(retry_count):
|
||||
try:
|
||||
@@ -80,8 +87,8 @@ def post_html(url: str, query: dict) -> requests.Response:
|
||||
|
||||
|
||||
def get_javlib_cookie() -> [dict, str]:
|
||||
proxy, timeout, retry_count = config.Config().proxy()
|
||||
proxies = get_proxy(proxy)
|
||||
proxy, timeout, retry_count, proxytype = config.Config().proxy()
|
||||
proxies = get_proxy(proxy, proxytype)
|
||||
|
||||
raw_cookie = {}
|
||||
user_agent = ""
|
||||
|
||||
@@ -5,6 +5,8 @@ success_output_folder=JAV_output
|
||||
soft_link=0
|
||||
|
||||
[proxy]
|
||||
;proxytype: http or socks5
|
||||
type=http
|
||||
proxy=127.0.0.1:1080
|
||||
timeout=10
|
||||
retry=3
|
||||
|
||||
@@ -26,14 +26,15 @@ class Config:
|
||||
def soft_link(self) -> bool:
|
||||
return self.conf.getboolean("common", "soft_link")
|
||||
|
||||
def proxy(self) -> [str, int, int]:
|
||||
def proxy(self) -> [str, int, int, str]:
|
||||
try:
|
||||
sec = "proxy"
|
||||
proxy = self.conf.get(sec, "proxy")
|
||||
timeout = self.conf.getint(sec, "timeout")
|
||||
retry = self.conf.getint(sec, "retry")
|
||||
|
||||
return proxy, timeout, retry
|
||||
proxytype = self.conf.get(sec, "type")
|
||||
|
||||
return proxy, timeout, retry, proxytype
|
||||
except ValueError:
|
||||
self._exit("common")
|
||||
|
||||
|
||||
8
core.py
8
core.py
@@ -196,17 +196,17 @@ def create_folder(success_folder, location_rule, json_data, conf: config.Config)
|
||||
|
||||
# path = examle:photo , video.in the Project Folder!
|
||||
def download_file_with_filename(url, filename, path, conf: config.Config, filepath, failed_folder):
|
||||
proxy, timeout, retry_count = conf.proxy()
|
||||
proxy, timeout, retry_count, proxytype = config.Config().proxy()
|
||||
|
||||
for i in range(retry_count):
|
||||
try:
|
||||
if not proxy == '':
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
proxies = get_proxy(proxy, proxytype)
|
||||
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={"http": "http://" + str(proxy), "https": "https://" + str(proxy)})
|
||||
r = requests.get(url, headers=headers, timeout=timeout, proxies=proxies)
|
||||
if r == '':
|
||||
print('[-]Movie Data not found!')
|
||||
return
|
||||
@@ -248,7 +248,7 @@ def image_download(cover, number, c_word, path, conf: config.Config, filepath, f
|
||||
moveFailedFolder(filepath, failed_folder)
|
||||
return
|
||||
|
||||
_proxy, _timeout, retry = conf.proxy()
|
||||
_proxy, _timeout, retry, _proxytype = conf.proxy()
|
||||
for i in range(retry):
|
||||
if os.path.getsize(path + '/' + number + c_word + '-fanart.jpg') == 0:
|
||||
print('[!]Image Download Failed! Trying again. [{}/3]', i + 1)
|
||||
|
||||
@@ -5,3 +5,4 @@ beautifulsoup4
|
||||
pillow
|
||||
pyinstaller
|
||||
cloudscraper
|
||||
pysocks
|
||||
Reference in New Issue
Block a user