mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-13 15:29:54 +08:00
2.5.10 修复APIbug,开通打赏
This commit is contained in:
10
README.md
10
README.md
@@ -13,11 +13,9 @@
|
||||
|
||||
# 如何开始
|
||||
|
||||
- **[部署说明 (Official)](https://github.com/EstrellaXD/Auto_Bangumi/blob/main/docs/部署说明.md)**
|
||||
- **[部署说明 (Official)](https://github.com/EstrellaXD/Auto_Bangumi/wiki)**
|
||||
- **[部署说明 (手把手)](https://www.himiku.com/archives/auto-bangumi.html)**
|
||||
|
||||
- **[常见问题排错](https://github.com/EstrellaXD/Auto_Bangumi/blob/main/docs/常见错误解决.md)**
|
||||
|
||||
# 项目说明
|
||||
|
||||
<p align="center">
|
||||
@@ -82,9 +80,13 @@
|
||||
- 更为智能细致的分类预设。
|
||||
|
||||
# 声明
|
||||
## 致谢
|
||||
感谢 [Sean](https://github.com/findix) 提供的大量帮助
|
||||
|
||||
# Licence
|
||||
## 请我喝一杯咖啡
|
||||
<img src="https://tva1.sinaimg.cn/large/e6c9d24ely1h425na5hldj20u019077h.jpg" width=50%/>
|
||||
|
||||
## Licence
|
||||
[MIT licence](https://github.com/EstrellaXD/Auto_Bangumi/blob/main/LICENSE)
|
||||
|
||||
|
||||
|
||||
@@ -21,3 +21,14 @@ def qb_connect_failed_wait(func):
|
||||
time.sleep(300)
|
||||
times += 1
|
||||
return wrapper
|
||||
|
||||
|
||||
def api_failed(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
logger.debug(f"URL: {args[0]}")
|
||||
logger.warning("Wrong API response.")
|
||||
logger.debug(e)
|
||||
return wrapper
|
||||
|
||||
@@ -8,12 +8,24 @@ from fastapi.templating import Jinja2Templates
|
||||
from pydantic import BaseModel
|
||||
import logging
|
||||
|
||||
from core import RSSAnalyser, DownloadClient, FullSeasonGet
|
||||
from core import APIProcess
|
||||
from conf import settings, parse
|
||||
from utils import json_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
args = parse()
|
||||
if args.debug:
|
||||
try:
|
||||
from conf.const_dev import DEV_SETTINGS
|
||||
|
||||
settings.init(DEV_SETTINGS)
|
||||
except ModuleNotFoundError:
|
||||
logger.debug("Please copy `const_dev.py` to `const_dev.py` to use custom settings")
|
||||
else:
|
||||
settings.init()
|
||||
app = FastAPI()
|
||||
api_func = APIProcess()
|
||||
|
||||
|
||||
|
||||
# templates = Jinja2Templates(directory="templates")
|
||||
@@ -38,45 +50,26 @@ async def get_log():
|
||||
|
||||
@app.get("/api/v1/resetRule")
|
||||
def reset_rule():
|
||||
data = json_config.load(settings.info_path)
|
||||
data["bangumi_info"] = []
|
||||
json_config.save(settings.info_path, data)
|
||||
return "Success"
|
||||
return api_func.reset_rule()
|
||||
|
||||
|
||||
@app.get("api/v1/removeRule/{name}")
|
||||
def remove_rule(name: str):
|
||||
datas = json_config.load(settings.info_path)["bangumi_info"]
|
||||
for data in datas:
|
||||
if re.search(name.name.lower(), data["title_raw"].lower()) is not None:
|
||||
datas.remove(data)
|
||||
json_config.save(settings.info_path, datas)
|
||||
return "Success"
|
||||
return "Not matched"
|
||||
return api_func.remove_rule(name)
|
||||
|
||||
|
||||
@app.get("/api/v1/collection/{link}")
|
||||
async def receive(link: str):
|
||||
client = DownloadClient()
|
||||
try:
|
||||
data = RSSAnalyser().rss_to_data(link.link)
|
||||
FullSeasonGet().download_collection(data, link.link, client)
|
||||
return data
|
||||
except Exception as e:
|
||||
logger.debug(e)
|
||||
return "Error"
|
||||
class RssLink(BaseModel):
|
||||
rss_link: str
|
||||
|
||||
|
||||
@app.get("/api/v1/subscribe/{link}")
|
||||
async def add_link(link: str):
|
||||
client = DownloadClient()
|
||||
try:
|
||||
data = RSSAnalyser().rss_to_data(link.link)
|
||||
client.set_rule(data, link.link)
|
||||
return data
|
||||
except Exception as e:
|
||||
logger.debug(e)
|
||||
return "Error"
|
||||
@app.post("/api/v1/collection")
|
||||
async def collection(link: RssLink):
|
||||
return api_func.download_collection(link.rss_link)
|
||||
|
||||
|
||||
@app.post("/api/v1/subscribe")
|
||||
async def subscribe(link: RssLink):
|
||||
return api_func.add_subscribe(link.rss_link)
|
||||
|
||||
|
||||
class AddRule(BaseModel):
|
||||
@@ -86,19 +79,10 @@ class AddRule(BaseModel):
|
||||
|
||||
@app.post("/api/v1/addRule")
|
||||
async def add_rule(info: AddRule):
|
||||
return "Not complete"
|
||||
return api_func.add_rule(info.title, info.season)
|
||||
|
||||
|
||||
def run():
|
||||
args = parse()
|
||||
if args.debug:
|
||||
try:
|
||||
from conf.const_dev import DEV_SETTINGS
|
||||
settings.init(DEV_SETTINGS)
|
||||
except ModuleNotFoundError:
|
||||
logger.debug("Please copy `const_dev.py` to `const_dev.py` to use custom settings")
|
||||
else:
|
||||
settings.init()
|
||||
LOGGING_CONFIG["formatters"]["default"]["fmt"] = "[%(asctime)s] %(levelprefix)s %(message)s"
|
||||
uvicorn.run(app, host="0.0.0.0", port=settings.webui_port)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
DEFAULT_SETTINGS = {
|
||||
"version": "2.5.9",
|
||||
"version": "2.5.10",
|
||||
"data_version": 4.0,
|
||||
"host_ip": "localhost:8080",
|
||||
"sleep_time": 7200,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .download_client import DownloadClient
|
||||
from .eps_complete import FullSeasonGet
|
||||
from .renamer import Renamer
|
||||
from .rss_analyser import RSSAnalyser
|
||||
from .rss_analyser import RSSAnalyser
|
||||
from .api_func import APIProcess
|
||||
|
||||
72
auto_bangumi/core/api_func.py
Normal file
72
auto_bangumi/core/api_func.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import re
|
||||
|
||||
from core import FullSeasonGet, DownloadClient, RSSAnalyser
|
||||
from utils import json_config
|
||||
from conf import settings
|
||||
|
||||
from ab_decorator import api_failed
|
||||
|
||||
|
||||
class APIProcess:
|
||||
def __init__(self):
|
||||
self._rss_analyser = RSSAnalyser()
|
||||
self._download_client = DownloadClient()
|
||||
self._full_season_get = FullSeasonGet()
|
||||
|
||||
def link_process(self, link):
|
||||
data = self._rss_analyser.rss_to_data(link)
|
||||
return data
|
||||
|
||||
@api_failed
|
||||
def download_collection(self, link):
|
||||
data = self.link_process(link)
|
||||
self._full_season_get.download_collection(data, link, self._download_client)
|
||||
return data
|
||||
|
||||
@api_failed
|
||||
def add_subscribe(self, link):
|
||||
data = self.link_process(link)
|
||||
self._download_client.add_rss_feed(link, data.get("official_title"))
|
||||
self._download_client.set_rule(data, link)
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def reset_rule():
|
||||
data = json_config.load(settings.info_path)
|
||||
data["bangumi_info"] = []
|
||||
json_config.save(settings.info_path, data)
|
||||
return "Success"
|
||||
|
||||
@staticmethod
|
||||
def remove_rule(name):
|
||||
datas = json_config.load(settings.info_path)["bangumi_info"]
|
||||
for data in datas:
|
||||
if re.search(name.lower(), data["title_raw"].lower()) is not None:
|
||||
datas.remove(data)
|
||||
json_config.save(settings.info_path, datas)
|
||||
return "Success"
|
||||
return "Not matched"
|
||||
|
||||
@staticmethod
|
||||
def add_rule(title, season):
|
||||
data = json_config.load(settings.info_path)
|
||||
extra_data = {
|
||||
"official_title": title,
|
||||
"title_raw": title,
|
||||
"season": season,
|
||||
"season_raw": "",
|
||||
"dpi": "",
|
||||
"group": "",
|
||||
"eps_complete": False,
|
||||
"added": False,
|
||||
}
|
||||
data["bangumi_info"].append(extra_data)
|
||||
json_config.save(settings.info_path, data)
|
||||
return "Success"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from conf.const_dev import DEV_SETTINGS
|
||||
settings.init(DEV_SETTINGS)
|
||||
API = APIProcess()
|
||||
API.add_subscribe("http://dmhy.org/topics/rss/rss.xml?keyword=彻夜之歌+星空+简")
|
||||
@@ -109,6 +109,9 @@ class DownloadClient:
|
||||
new_location=location
|
||||
)
|
||||
|
||||
def add_rss_feed(self, rss_link, item_path):
|
||||
self.client.rss_add_feed(url=rss_link, item_path=item_path)
|
||||
logger.info("Add RSS Feed successfully.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
put = DownloadClient()
|
||||
|
||||
Reference in New Issue
Block a user