mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-06 16:07:01 +08:00
fix TVDB代理与SSL校验 #4356
This commit is contained in:
@@ -18,7 +18,9 @@ class TheTvDbModule(_ModuleBase):
|
|||||||
创建或刷新 TVDB 登录会话
|
创建或刷新 TVDB 登录会话
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.tvdb = tvdb_v4_official.TVDB(apikey=settings.TVDB_V4_API_KEY, pin=settings.TVDB_V4_API_PIN)
|
self.tvdb = tvdb_v4_official.TVDB(apikey=settings.TVDB_V4_API_KEY,
|
||||||
|
pin=settings.TVDB_V4_API_PIN,
|
||||||
|
proxy=settings.PROXY)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"TVDB 登录失败: {str(e)}")
|
logger.error(f"TVDB 登录失败: {str(e)}")
|
||||||
|
|
||||||
@@ -75,6 +77,8 @@ class TheTvDbModule(_ModuleBase):
|
|||||||
"""
|
"""
|
||||||
测试模块连接性
|
测试模块连接性
|
||||||
"""
|
"""
|
||||||
|
if not self.tvdb:
|
||||||
|
return False, "TheTVDB 连接失败"
|
||||||
try:
|
try:
|
||||||
self._handle_tvdb_call(self.tvdb.get_series, 81189)
|
self._handle_tvdb_call(self.tvdb.get_series, 81189)
|
||||||
return True, ""
|
return True, ""
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ __author__ = "Weylin Wagnon"
|
|||||||
__version__ = "1.0.12"
|
__version__ = "1.0.12"
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import ssl
|
||||||
import string
|
import string
|
||||||
import urllib
|
import urllib
|
||||||
import urllib.request
|
import urllib.request
|
||||||
@@ -12,16 +13,21 @@ from urllib.error import HTTPError
|
|||||||
|
|
||||||
|
|
||||||
class Auth:
|
class Auth:
|
||||||
def __init__(self, url, apikey, pin=""):
|
def __init__(self, url, apikey, pin="", proxy=None):
|
||||||
loginInfo = {"apikey": apikey}
|
loginInfo = {"apikey": apikey}
|
||||||
if pin != "":
|
if pin != "":
|
||||||
loginInfo["pin"] = pin
|
loginInfo["pin"] = pin
|
||||||
|
|
||||||
loginInfoBytes = json.dumps(loginInfo, indent=2).encode("utf-8")
|
loginInfoBytes = json.dumps(loginInfo, indent=2).encode("utf-8")
|
||||||
|
if proxy:
|
||||||
|
proxy_handler = urllib.request.ProxyHandler(proxy)
|
||||||
|
opener = urllib.request.build_opener(proxy_handler)
|
||||||
|
urllib.request.install_opener(opener)
|
||||||
req = urllib.request.Request(url, data=loginInfoBytes)
|
req = urllib.request.Request(url, data=loginInfoBytes)
|
||||||
req.add_header("Content-Type", "application/json")
|
req.add_header("Content-Type", "application/json")
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(req, data=loginInfoBytes) as response:
|
context = ssl._create_unverified_context()
|
||||||
|
with urllib.request.urlopen(req, context=context, data=loginInfoBytes) as response:
|
||||||
res = json.load(response)
|
res = json.load(response)
|
||||||
self.token = res["data"]["token"]
|
self.token = res["data"]["token"]
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
@@ -33,17 +39,24 @@ class Auth:
|
|||||||
|
|
||||||
|
|
||||||
class Request:
|
class Request:
|
||||||
def __init__(self, auth_token):
|
def __init__(self, auth_token, proxy=None):
|
||||||
self.auth_token = auth_token
|
self.auth_token = auth_token
|
||||||
self.links = None
|
self.links = None
|
||||||
|
self.proxy = proxy
|
||||||
|
|
||||||
def make_request(self, url, if_modified_since=None):
|
def make_request(self, url, if_modified_since=None):
|
||||||
|
"""Makes a request to the given URL and returns the data"""
|
||||||
|
if self.proxy:
|
||||||
|
proxy_handler = urllib.request.ProxyHandler(self.proxy)
|
||||||
|
opener = urllib.request.build_opener(proxy_handler)
|
||||||
|
urllib.request.install_opener(opener)
|
||||||
req = urllib.request.Request(url)
|
req = urllib.request.Request(url)
|
||||||
req.add_header("Authorization", "Bearer {}".format(self.auth_token))
|
req.add_header("Authorization", "Bearer {}".format(self.auth_token))
|
||||||
if if_modified_since:
|
if if_modified_since:
|
||||||
req.add_header("If-Modified-Since", "{}".format(if_modified_since))
|
req.add_header("If-Modified-Since", "{}".format(if_modified_since))
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(req) as response:
|
context = ssl._create_unverified_context()
|
||||||
|
with urllib.request.urlopen(req, context=context) as response:
|
||||||
res = json.load(response)
|
res = json.load(response)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
try:
|
try:
|
||||||
@@ -87,12 +100,12 @@ class Url:
|
|||||||
|
|
||||||
|
|
||||||
class TVDB:
|
class TVDB:
|
||||||
def __init__(self, apikey: str, pin=""):
|
def __init__(self, apikey: str, pin="", proxy=None):
|
||||||
self.url = Url()
|
self.url = Url()
|
||||||
login_url = self.url.construct("login")
|
login_url = self.url.construct("login")
|
||||||
self.auth = Auth(login_url, apikey, pin)
|
self.auth = Auth(login_url, apikey, pin, proxy)
|
||||||
auth_token = self.auth.get_token()
|
auth_token = self.auth.get_token()
|
||||||
self.request = Request(auth_token)
|
self.request = Request(auth_token, proxy)
|
||||||
|
|
||||||
def get_req_links(self) -> dict:
|
def get_req_links(self) -> dict:
|
||||||
return self.request.links
|
return self.request.links
|
||||||
|
|||||||
Reference in New Issue
Block a user