Skip to content

Commit

Permalink
fix: #285, rss_feed 添加逻辑,启动逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
EstrellaXD committed Jun 3, 2023
1 parent 049ae74 commit 7676b12
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/wiki
Submodule wiki updated from 4311a8 to 519e38
4 changes: 2 additions & 2 deletions src/module/api/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ async def get_search_result(searchstr: str):


@router.get("/RSS/Bangumi", tags=["proxy"])
async def get_bangumi(bangumiId: str, groupid: str):
full_path = "Bangumi?bangumiId=" + bangumiId + "&groupid=" + groupid
async def get_bangumi(bangumiId: str, subgroupid: str):
full_path = "Bangumi?bangumiId=" + bangumiId + "&subgroupid=" + subgroupid
content = get_rss_content(full_path)
return Response(content, media_type="application/xml")

Expand Down
10 changes: 6 additions & 4 deletions src/module/checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ class Checker:
def __init__(self):
pass

def check_renamer(self) -> bool:
if self.check_downloader() and settings.bangumi_manage.enable:
@staticmethod
def check_renamer() -> bool:
if settings.bangumi_manage.enable:
return True
else:
return False

def check_analyser(self) -> bool:
if self.check_downloader() and settings.rss_parser.enable:
@staticmethod
def check_analyser() -> bool:
if settings.rss_parser.enable:
return True
else:
return False
Expand Down
17 changes: 10 additions & 7 deletions src/module/core/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@ def startup(self):
"Legacy data detected, starting data migration, please wait patiently."
)
data_migration()
add_rss_feed()
self.start()

def start(self):
if self.first_run:
return {"status": "Not ready to start."}
self.stop_event.clear()
settings.load()
if self.enable_renamer:
self.rename_start()
if self.enable_rss:
self.rss_start()
logger.info("Program running.")
return {"status": "Program started."}
if self.downloader_status:
if self.enable_renamer:
self.rename_start()
if self.enable_rss:
add_rss_feed()
self.rss_start()
logger.info("Program running.")
return {"status": "Program started."}
else:
return {"status": "Can't connect to downloader. Program not paused."}

def stop(self):
if self.is_running:
Expand Down
18 changes: 14 additions & 4 deletions src/module/downloader/client/qb_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
)

from module.ab_decorator import qb_connect_failed_wait
from module.downloader.exceptions import ConflictError

logger = logging.getLogger(__name__)

Expand All @@ -27,9 +26,9 @@ def __init__(self, host: str, username: str, password: str, ssl: bool):
self.host = host
self.username = username

def auth(self):
def auth(self, retry=3):
times = 0
while times < 3:
while times < retry:
try:
self._client.auth_log_in()
return True
Expand All @@ -46,7 +45,8 @@ def auth(self):
except APIConnectionError:
logger.error(f"Cannot connect to qBittorrent Server")
logger.info(f"Please check the IP and port in WebUI settings")
time.sleep(30)
time.sleep(10)
times += 1
except Exception as e:
logger.error(f"Unknown error: {e}")
break
Expand All @@ -55,6 +55,16 @@ def auth(self):
def logout(self):
self._client.auth_log_out()

def check_host(self):
try:
self._client.app_version()
return True
except APIConnectionError:
return False

def check_rss(self, rss_link: str):
pass

@qb_connect_failed_wait
def prefs_init(self, prefs):
return self._client.app_set_preferences(prefs=prefs)
Expand Down
10 changes: 9 additions & 1 deletion src/module/downloader/download_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __getClient():
def __enter__(self):
if not self.authed:
self.auth()
else:
logger.error("[Downloader] Already authed.")
return self

def __exit__(self, exc_type, exc_val, exc_tb):
Expand All @@ -42,7 +44,13 @@ def __exit__(self, exc_type, exc_val, exc_tb):

def auth(self):
self.authed = self.client.auth()
logger.debug("Authed.")
if self.authed:
logger.info("[Downloader] Authed.")
else:
logger.error("[Downloader] Auth failed.")

def check_host(self):
return self.client.check_host()

def init_downloader(self):
prefs = {
Expand Down

0 comments on commit 7676b12

Please sign in to comment.