mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-12 15:20:44 +08:00
优化 emby 连接,修复报错
This commit is contained in:
parent
c89ce5ab0c
commit
86f83e900c
@ -25,7 +25,7 @@ script_path = os.environ.get("SCRIPT_PATH", "./quark_auto_save.py")
|
|||||||
config_path = os.environ.get("CONFIG_PATH", "./config/quark_config.json")
|
config_path = os.environ.get("CONFIG_PATH", "./config/quark_config.json")
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config["APP_VERSION"] = "0.2.7.1"
|
app.config["APP_VERSION"] = "0.2.7.2"
|
||||||
app.secret_key = "ca943f6db6dd34823d36ab08d8d6f65d"
|
app.secret_key = "ca943f6db6dd34823d36ab08d8d6f65d"
|
||||||
app.json.ensure_ascii = False
|
app.json.ensure_ascii = False
|
||||||
app.json.sort_keys = False
|
app.json.sort_keys = False
|
||||||
|
|||||||
@ -95,7 +95,7 @@ class Quark:
|
|||||||
self.st = self.match_st_form_cookie(cookie)
|
self.st = self.match_st_form_cookie(cookie)
|
||||||
|
|
||||||
def match_st_form_cookie(self, cookie):
|
def match_st_form_cookie(self, cookie):
|
||||||
match = re.search(r'=(st[a-zA-Z0-9]+);', cookie)
|
match = re.search(r"=(st[a-zA-Z0-9]+);", cookie)
|
||||||
return match.group(1) if match else False
|
return match.group(1) if match else False
|
||||||
|
|
||||||
def common_headers(self):
|
def common_headers(self):
|
||||||
@ -578,13 +578,27 @@ class Quark:
|
|||||||
|
|
||||||
class Emby:
|
class Emby:
|
||||||
def __init__(self, emby_url, emby_apikey):
|
def __init__(self, emby_url, emby_apikey):
|
||||||
|
self.is_active = False
|
||||||
if emby_url and emby_apikey:
|
if emby_url and emby_apikey:
|
||||||
self.emby_url = emby_url
|
self.emby_url = emby_url
|
||||||
self.emby_apikey = emby_apikey
|
self.emby_apikey = emby_apikey
|
||||||
|
if self.get_info():
|
||||||
|
self.is_active = True
|
||||||
|
|
||||||
|
def get_info(self):
|
||||||
|
url = f"{self.emby_url}/emby/System/Info"
|
||||||
|
headers = {"X-Emby-Token": self.emby_apikey}
|
||||||
|
querystring = {}
|
||||||
|
response = requests.request("GET", url, headers=headers, params=querystring)
|
||||||
|
if "application/json" in response.headers["Content-Type"]:
|
||||||
|
response = response.json()
|
||||||
|
print(f"Emby媒体库: {response.get("ServerName","")} v{response.get("Version","")}")
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
|
print(f"Emby媒体库: 连接失败❌ {response.text}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def emby_refresh(self, emby_id):
|
def refresh(self, emby_id):
|
||||||
if emby_id:
|
if emby_id:
|
||||||
url = f"{self.emby_url}/emby/Items/{emby_id}/Refresh"
|
url = f"{self.emby_url}/emby/Items/{emby_id}/Refresh"
|
||||||
headers = {"X-Emby-Token": self.emby_apikey}
|
headers = {"X-Emby-Token": self.emby_apikey}
|
||||||
@ -605,7 +619,7 @@ class Emby:
|
|||||||
print(f"🎞 刷新Emby媒体库:{response.text}❌")
|
print(f"🎞 刷新Emby媒体库:{response.text}❌")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def emby_search(self, media_name):
|
def search(self, media_name):
|
||||||
if media_name:
|
if media_name:
|
||||||
url = f"{self.emby_url}/emby/Items"
|
url = f"{self.emby_url}/emby/Items"
|
||||||
headers = {"X-Emby-Token": self.emby_apikey}
|
headers = {"X-Emby-Token": self.emby_apikey}
|
||||||
@ -697,7 +711,8 @@ def do_save(account):
|
|||||||
# 获取全部保存目录fid
|
# 获取全部保存目录fid
|
||||||
account.update_savepath_fid(tasklist)
|
account.update_savepath_fid(tasklist)
|
||||||
emby = Emby(
|
emby = Emby(
|
||||||
config_data.get("emby").get("url"), config_data.get("emby").get("apikey")
|
config_data.get("emby", {}).get("url", ""),
|
||||||
|
config_data.get("emby", {}).get("apikey", ""),
|
||||||
)
|
)
|
||||||
|
|
||||||
def check_date(task):
|
def check_date(task):
|
||||||
@ -734,14 +749,14 @@ def do_save(account):
|
|||||||
is_new = account.do_save_task(task)
|
is_new = account.do_save_task(task)
|
||||||
is_rename = account.do_rename_task(task)
|
is_rename = account.do_rename_task(task)
|
||||||
# 刷新媒体库
|
# 刷新媒体库
|
||||||
if emby and (is_new or is_rename) and task.get("emby_id") != "0":
|
if emby.is_active and (is_new or is_rename) and task.get("emby_id") != "0":
|
||||||
if task.get("emby_id"):
|
if task.get("emby_id"):
|
||||||
emby.emby_refresh(task["emby_id"])
|
emby.refresh(task["emby_id"])
|
||||||
else:
|
else:
|
||||||
match_emby_id = emby.emby_search(task["taskname"])
|
match_emby_id = emby.search(task["taskname"])
|
||||||
if match_emby_id:
|
if match_emby_id:
|
||||||
task["emby_id"] = match_emby_id
|
task["emby_id"] = match_emby_id
|
||||||
emby.emby_refresh(match_emby_id)
|
emby.refresh(match_emby_id)
|
||||||
print(f"")
|
print(f"")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user