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