Add RSS Link refresh

This commit is contained in:
EstrellaXD
2023-04-25 14:46:45 +08:00
parent 43da3808ec
commit 6f438be19a
13 changed files with 74 additions and 39 deletions

View File

@@ -22,6 +22,8 @@ main_process = multiprocessing.Process(target=app.run)
@router.get("/api/v1/restart", tags=["program"])
async def restart():
global main_process
if not main_process.is_alive():
return {"status": "failed", "reason": "Already stopped"}
logger.info("Restarting...")
os.kill(main_process.pid, signal.SIGTERM)
main_process = multiprocessing.Process(target=app.run)
@@ -30,6 +32,28 @@ async def restart():
return {"status": "success"}
@router.get("/api/v1/stop", tags=["program"])
async def stop():
global main_process
if not main_process.is_alive():
return {"status": "failed", "reason": "Already stopped"}
logger.info("Stopping...")
os.kill(main_process.pid, signal.SIGTERM)
logger.info("Stopped")
return {"status": "success"}
@router.get("/api/v1/start", tags=["program"])
async def start():
global main_process
if main_process.is_alive():
return {"status": "failed", "reason": "Already started"}
logger.info("Starting...")
main_process.start()
logger.info("Started")
return {"status": "success"}
if VERSION != "DEV_VERSION":
router.mount("/assets", StaticFiles(directory="templates/assets"), name="assets")
templates = Jinja2Templates(directory="templates")

View File

@@ -12,6 +12,7 @@ def qb_connect_failed_wait(func):
return func(*args, **kwargs)
except Exception as e:
logger.debug(f"URL: {args[0]}")
logger.warning(e)
logger.warning("Cannot connect to qBittorrent. Wait 5 min and retry...")
time.sleep(300)
times += 1

View File

@@ -77,8 +77,9 @@ def run():
setup_logger()
show_info()
download_client = DownloadClient()
download_client.auth()
download_client.init_downloader()
if settings.rss_parser.token is None:
if settings.rss_parser.token in ["", "token", None]:
logger.error("Please set your RSS token in config file.")
quit()
download_client.rss_feed()

View File

@@ -4,4 +4,8 @@ from .config import settings, VERSION
TMDB_API = "32b19d6a05b512190a056fa4e747cbbc"
DATA_PATH = "data/data.json"
RSS_LINK = f"https://{settings.rss_parser.custom_url}/RSS/MyBangumi?token={settings.rss_parser.token}"
class RSSLink(str):
def __new__(cls):
return f"https://{settings.rss_parser.custom_url}/RSS/MyBangumi?token={settings.rss_parser.token}"

View File

@@ -31,11 +31,8 @@ DEFAULT_SETTINGS = {
"group_tag": False,
"remove_bad_torrent": False
},
"debug": {
"enable": False,
"level": "info",
"file": "bangumi.log",
"dev_debug": False
"log": {
"debug_enable": False,
},
"proxy": {
"enable": False,
@@ -56,9 +53,9 @@ DEFAULT_SETTINGS = {
ENV_TO_ATTR = {
"program": {
"AB_INTERVAL_TIME": ("sleep_time", int),
"AB_RENAME_FREQ": ("times", int),
"AB_WEBUI_PORT": ("webui_port", int),
"AB_INTERVAL_TIME": ("sleep_time", lambda e: int(e)),
"AB_RENAME_FREQ": ("times", lambda e: int(e)),
"AB_WEBUI_PORT": ("webui_port", lambda e: int(e)),
},
"downloader": {
"AB_DOWNLOADER_HOST": "host",
@@ -80,8 +77,8 @@ ENV_TO_ATTR = {
"AB_EP_COMPLETE": ("eps_complete", lambda e: e.lower() in ("true", "1", "t")),
"AB_REMOVE_BAD_BT": ("remove_bad_torrent", lambda e: e.lower() in ("true", "1", "t")),
},
"debug": {
"AB_DEBUG_MODE": ("enable", lambda e: e.lower() in ("true", "1", "t")),
"log": {
"AB_DEBUG_MODE": ("debug_enable", lambda e: e.lower() in ("true", "1", "t")),
},
}

View File

@@ -6,7 +6,7 @@ LOG_PATH = "data/log.txt"
def setup_logger():
level = logging.DEBUG if settings.debug.enable else logging.INFO
level = logging.DEBUG if settings.log.debug_enable else logging.INFO
logging.addLevelName(logging.DEBUG, 'DEBUG:')
logging.addLevelName(logging.INFO, 'INFO:')
logging.addLevelName(logging.WARNING, 'WARNING:')

View File

@@ -17,7 +17,7 @@ logger = logging.getLogger(__name__)
class APIProcess:
def __init__(self):
self._rss_analyser = RSSAnalyser()
self._download_client = DownloadClient()
self._client = DownloadClient()
self._full_season_get = FullSeasonGet()
def link_process(self, link):
@@ -25,15 +25,19 @@ class APIProcess:
@api_failed
def download_collection(self, link):
if not self._client.authed:
self._client.auth()
data = self.link_process(link)
self._full_season_get.download_collection(data, link, self._download_client)
self._full_season_get.download_collection(data, link, self._client)
return data
@api_failed
def add_subscribe(self, link):
if not self._client.authed:
self._client.auth()
data = self.link_process(link)
self._download_client.add_rss_feed(link, data.get("official_title"))
self._download_client.set_rule(data, link)
self._client.add_rss_feed(link, data.get("official_title"))
self._client.set_rule(data, link)
return data
@staticmethod

View File

@@ -4,7 +4,9 @@ import os
from module.downloader import getClient
from module.conf import settings, RSS_LINK
from module.conf import settings, RSSLink
RSS_LINK = RSSLink()
logger = logging.getLogger(__name__)
@@ -12,10 +14,15 @@ logger = logging.getLogger(__name__)
class DownloadClient:
def __init__(self):
self.client = getClient()
self.authed = False
def auth(self):
host, username, password = settings.downloader.host, settings.downloader.username, settings.downloader.password
self.client.auth(host, username, password)
try:
self.client.auth(host, username, password)
self.authed = True
except Exception as e:
logger.error(f"Can't login {host} by {username}, {e}")
def init_downloader(self):
prefs = {

View File

@@ -1,5 +1,11 @@
from module.conf import settings
def getClient():
# TODO 多下载器支持
# 从 settings 里读取下载器名称,然后返回对应 Client
from .qb_downloader import QbDownloader
return QbDownloader()
if settings.downloader.type == "qbittorrent":
from .qb_downloader import QbDownloader
return QbDownloader()
else:
raise Exception(f"Unsupported downloader type: {settings.downloader.type}")

View File

@@ -13,7 +13,6 @@ logger = logging.getLogger(__name__)
class QbDownloader:
@qb_connect_failed_wait
def __init__(self):
self._client: Client | None = None
@@ -101,3 +100,6 @@ class QbDownloader:
def set_category(self, _hash, category):
self._client.torrents_set_category(category, hashes=_hash)
def check_connection(self):
return self._client.app_version()

View File

@@ -17,6 +17,7 @@ class Downloader(BaseModel):
path: str = Field("/downloads/Bangumi", description="Downloader path")
ssl: bool = Field(False, description="Downloader ssl")
class RSSParser(BaseModel):
enable: bool = Field(True, description="Enable RSS parser")
type: str = Field("mikan", description="RSS parser type")
@@ -35,11 +36,8 @@ class BangumiManage(BaseModel):
remove_bad_torrent: bool = Field(False, description="Remove bad torrent")
class Debug(BaseModel):
enable: bool = Field(False, description="Enable debug")
level: str = Field("debug", description="Debug level")
file: str = Field("debug.log", description="Debug file")
dev_debug: bool = Field(False, description="Enable dev debug")
class Log(BaseModel):
debug_enable: bool = Field(False, description="Enable debug")
class Proxy(BaseModel):
@@ -64,6 +62,6 @@ class Config(BaseModel):
downloader: Downloader = Downloader()
rss_parser: RSSParser = RSSParser()
bangumi_manage: BangumiManage = BangumiManage()
debug: Debug = Debug()
log: Log = Log()
proxy: Proxy = Proxy()
notification: Notification = Notification()

View File

@@ -3,11 +3,12 @@ import logging
from module.network import RequestContent
from module.parser import TitleParser
from module.conf import settings, RSS_LINK
from module.conf import RSSLink
from module.core import DownloadClient
logger = logging.getLogger(__name__)
RSS_LINK = RSSLink()
class RSSAnalyser:

View File

@@ -1,10 +0,0 @@
#!/bin/bash
echo "设置文件夹权限"
echo "PUID=${PUID}"
echo "PGID=${PGID}"
groupmod -o -g "$PGID" auto_bangumi
usermod -o -u "$PUID" auto_bangumi
chown -R auto_bangumi:auto_bangumi /src /templates /config