Skip to content

Commit

Permalink
增加代理验证
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLiang-lzm committed Jun 10, 2022
1 parent 83a2b71 commit 7284ace
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 38 deletions.
7 changes: 6 additions & 1 deletion BiliModule/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def __init__(self, parent=None):
indict['dl_err'] = tempr.get('dl_err')
if tempr.get('chunk_size'):
indict['chunk_size'] = tempr.get('chunk_size')
if tempr.get('ProxyAuth'):
indict['ProxyAuth']['inuse'] = tempr['ProxyAuth'].get('inuse', False)
indict['ProxyAuth']['usr'] = tempr['ProxyAuth'].get('usr', '')
indict['ProxyAuth']['pwd'] = tempr['ProxyAuth'].get('pwd', '')
except:
indict["Output"] = DF_Path
indict["sys"] = sys.platform
Expand Down Expand Up @@ -116,7 +120,8 @@ def closeEvent(self, QCloseEvent):
"useProxy": indict["useProxy"],
"Proxy": indict["Proxy"],
"dl_err": indict["dl_err"],
"chunk_size": indict["chunk_size"]
"chunk_size": indict["chunk_size"],
"ProxyAuth": indict["ProxyAuth"]
}
f.write(json.dumps(temp_dict, sort_keys=True, indent=4))
f.close()
Expand Down
32 changes: 27 additions & 5 deletions BiliModule/Setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def __init__(self, ins_dict, parent=None):
self.lineEdit.setText(ins_dict["Proxy"]["http"])
self.dl_err.setValue(ins_dict["dl_err"])
self.chunk_size.setValue(ins_dict["chunk_size"])
if self.ins_dict['ProxyAuth']['inuse']:
self.cb_useAuth.setChecked(True)
self.le_AuthUsr.setEnabled(True)
self.le_AuthPwd.setEnabled(True)
self.le_AuthUsr.setText(ins_dict['ProxyAuth']['usr'])
self.le_AuthPwd.setText(ins_dict['ProxyAuth']['pwd'])
# 设置父窗口阻塞与窗口透明
self.setWindowModality(Qt.ApplicationModal)
self.setWindowFlags(Qt.FramelessWindowHint)
Expand All @@ -40,6 +46,7 @@ def __init__(self, ins_dict, parent=None):
self.btn_wherecookie.clicked.connect(self.forHelp)
self.btn_testProxy.clicked.connect(self.testProxy)
self.btn_huseProxy.clicked.connect(self.ProxyHelp)
self.cb_useAuth.clicked.connect(self.inUseAuth)

# ###################### RW Part ##########################
# 鼠标点击事件产生
Expand Down Expand Up @@ -68,7 +75,13 @@ def closeEvent(self, QCloseEvent):
def testProxy(self):
proxy_url = self.lineEdit.text()
proxy_temp = {'http': proxy_url, 'https': proxy_url, }
self.ts = checkProxy(proxy_temp)
auth_tmp = None
if self.cb_useAuth:
auth_tmp = {
'usr': self.le_AuthUsr,
'pwd': self.le_AuthPwd
}
self.ts = checkProxy(proxy_temp, auth_tmp)
self.lineEdit.setEnabled(False)
self.btn_testProxy.setEnabled(False)
self.btn_testProxy.setText("正在检测")
Expand All @@ -78,14 +91,14 @@ def testProxy(self):
# 确定设置函数
def setConfig(self):
self.ins_dict["cookie"] = self.edit_cookies.toPlainText()
if self.cb_useProxy.isChecked():
self.ins_dict["useProxy"] = True
else:
self.ins_dict["useProxy"] = False
self.ins_dict["useProxy"] = self.cb_useProxy.isChecked()
proxy_url = self.lineEdit.text()
self.ins_dict["Proxy"] = {'http': proxy_url, 'https': proxy_url, }
self.ins_dict["dl_err"] = self.dl_err.value()
self.ins_dict["chunk_size"] = self.chunk_size.value()
self.ins_dict["ProxyAuth"]["inuse"] = self.cb_useAuth.isChecked()
self.ins_dict["ProxyAuth"]["usr"] = self.le_AuthUsr.text()
self.ins_dict["ProxyAuth"]["pwd"] = self.le_AuthPwd.text()
self._signal.emit({"code": 1, "indict": self.ins_dict})
self.close()

Expand All @@ -101,6 +114,15 @@ def forHelp(self):
def ProxyHelp(self):
webbrowser.open("https://jimmyliang-lzm.github.io/2021/10/07/bilid_GUI_help/#3-5-“僅限港澳台地區”视频下载")

# 使用代理检查框按下事件
def inUseAuth(self):
if self.cb_useAuth.isChecked():
self.le_AuthUsr.setEnabled(True)
self.le_AuthPwd.setEnabled(True)
else:
self.le_AuthUsr.setEnabled(False)
self.le_AuthPwd.setEnabled(False)

# ########################## 槽函数 ################################
# 代理地址测试线程槽函数
def proxy_catch(self, in_dict):
Expand Down
80 changes: 65 additions & 15 deletions BiliWorker/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,28 @@ def run(self):
class checkProxy(QThread):
_feedback = Signal(dict)

def __init__(self, in_Proxy):
def __init__(self, in_Proxy, auth=None):
super(checkProxy, self).__init__()
self.use_Proxy = in_Proxy
self.index_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/72.0.3626.121 Safari/537.36 "
}
self.Auth = auth
if auth:
from requests.auth import HTTPProxyAuth
self.Auth = HTTPProxyAuth(auth.get('usr'), auth.get('pwd'))

def run(self):
try:
temp = {"code": 1}
des = request.get("https://api.live.bilibili.com/xlive/web-room/v1/index/getIpInfo",
headers=self.index_headers, timeout=10, stream=False, proxies=self.use_Proxy)
headers=self.index_headers,
timeout=10,
stream=False,
proxies=self.use_Proxy,
auth=self.Auth
)
res = json.loads(des.content.decode('utf-8'))["data"]
temp["ip"] = res["addr"]
temp["area"] = res["country"]
Expand Down Expand Up @@ -96,14 +105,17 @@ def __init__(self, args, model=0, parent=None):
self.re_INITIAL_STATE = 'window.__INITIAL_STATE__=([\s\S]*?);\(function'
if args["useCookie"]:
self.index_headers["cookie"] = args["cookie"]
# self.second_headers["cookie"] = args["cookie"]
else:
self.index_headers["cookie"] = ""
# self.second_headers["cookie"] = ""
# 使用代理
self.Proxy = None
if args["useProxy"]:
self.Proxy = args["Proxy"]
else:
self.Proxy = {}
# 若使用代理验证
self.ProxyAuth = None
if args["ProxyAuth"]["inuse"]:
from requests.auth import HTTPProxyAuth
self.ProxyAuth = HTTPProxyAuth(args['ProxyAuth']['usr'], args['ProxyAuth']['pwd'])
self.iscache = args['imgcache']
self.cache_path = args['cache_path'] + "/temp"
# 初始化缓存图片下载类
Expand Down Expand Up @@ -187,7 +199,14 @@ def change_method(self, mode: int, **kwargs):
# Interactive video initial information
def Get_Init_Info(self, url):
try:
res = request.get(url, headers=self.index_headers, stream=False, timeout=10, proxies=self.Proxy)
res = request.get(
url,
headers=self.index_headers,
stream=False,
timeout=10,
proxies=self.Proxy,
auth=self.ProxyAuth
)
dec = res.content.decode('utf-8')
playinfo = re.findall(self.re_playinfo, dec, re.S)
INITIAL_STATE = re.findall(self.re_INITIAL_STATE, dec, re.S)
Expand All @@ -211,7 +230,14 @@ def isInteract(self):
'bvid': self.now_interact["bvid"],
}
try:
res = request.get(make_API, headers=self.index_headers, params=param, timeout=10, proxies=self.Proxy)
res = request.get(
make_API,
headers=self.index_headers,
params=param,
timeout=10,
proxies=self.Proxy,
auth=self.ProxyAuth
)
des = res.json()
if "interaction" not in des["data"]:
raise Exception("非交互视频")
Expand All @@ -230,7 +256,14 @@ def Get_Edge(self):
'node_id': self.now_interact["node_id"],
}
try:
des = request.get(make_API, headers=self.index_headers, params=param, timeout=10, proxies=self.Proxy)
des = request.get(
make_API,
headers=self.index_headers,
params=param,
timeout=10,
proxies=self.Proxy,
auth=self.ProxyAuth
)
res = des.json()
except Exception as e:
print("Get Edges:", e)
Expand Down Expand Up @@ -282,7 +315,14 @@ def recursion_GET_List(self, inword):
'node_id': self.now_interact["node_id"],
}
try:
des = request.get(make_API, headers=self.index_headers, params=param, timeout=10, proxies=self.Proxy)
des = request.get(
make_API,
headers=self.index_headers,
params=param,
timeout=10,
proxies=self.Proxy,
auth=self.ProxyAuth
)
desp = des.json()
except Exception as e:
self.business_info.emit("获取节点信息出现网络问题:节点提取可能不全")
Expand Down Expand Up @@ -345,14 +385,18 @@ def __init__(self, req_dict: dict):
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/72.0.3626.121 Safari/537.36 "
}
self.index_headers["cookie"] = ""
if req_dict["useCookie"]:
self.index_headers["cookie"] = req_dict["cookie"]
else:
self.index_headers["cookie"] = ""
# 使用代理
self.Proxy = None
if req_dict["useProxy"]:
self.Proxy = req_dict["Proxy"]
else:
self.Proxy = {}
# 若使用代理验证
self.ProxyAuth = None
if req_dict["ProxyAuth"]["inuse"]:
from requests.auth import HTTPProxyAuth
self.ProxyAuth = HTTPProxyAuth(req_dict['ProxyAuth']['usr'], req_dict['ProxyAuth']['pwd'])
self.cache_path = req_dict['cache_path'] + "/temp"
# 初始化递归字典
self.recur_dict = {}
Expand All @@ -379,7 +423,13 @@ def img_cache(self, cid):
if Path(output_file).is_file():
return 0
try:
res = request.get(url, headers=self.index_headers, timeout=10, proxies=self.Proxy)
res = request.get(
url,
headers=self.index_headers,
timeout=10,
proxies=self.Proxy,
auth=self.ProxyAuth
)
file = res.content
with open(output_file, 'wb') as f:
f.write(file)
Expand Down
Loading

0 comments on commit 7284ace

Please sign in to comment.