mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-24 10:31:09 +08:00
Feature 增加内置反代
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.responses import FileResponse, Response
|
||||
|
||||
from module.core import APIProcess
|
||||
from module.conf import DATA_PATH, LOG_PATH, settings
|
||||
@@ -67,3 +67,15 @@ async def get_config():
|
||||
async def update_config(config: Config):
|
||||
return api_func.update_config(config)
|
||||
|
||||
|
||||
@router.get("/RSS/MyBangumi")
|
||||
async def get_rss(token: str):
|
||||
content = api_func.get_rss(token)
|
||||
return Response(content, media_type="application/xml")
|
||||
|
||||
|
||||
@router.get("/Download/{full_path:path}")
|
||||
async def download(full_path: str):
|
||||
torrent = api_func.get_torrent(full_path)
|
||||
return Response(torrent, media_type="application/x-bittorrent")
|
||||
|
||||
|
||||
@@ -5,9 +5,10 @@ from module.core import DownloadClient
|
||||
from module.manager import FullSeasonGet
|
||||
from module.rss import RSSAnalyser
|
||||
from module.utils import json_config
|
||||
from module.conf import DATA_PATH
|
||||
from module.conf import DATA_PATH, settings
|
||||
from module.conf.config import save_config_to_file, CONFIG_PATH
|
||||
from module.models import Config
|
||||
from module.network import RequestContent
|
||||
|
||||
from module.ab_decorator import api_failed
|
||||
|
||||
@@ -82,3 +83,16 @@ class APIProcess:
|
||||
@staticmethod
|
||||
def get_config() -> dict:
|
||||
return json_config.load(CONFIG_PATH)
|
||||
|
||||
@staticmethod
|
||||
def get_rss(token: str):
|
||||
url = f"https://mikanani.me/RSS/MyBangumi?token={token}"
|
||||
with RequestContent() as request:
|
||||
content = request.get_html(url)
|
||||
return re.sub(r"mikanani.me", settings.rss_parser.custom_url, content)
|
||||
|
||||
@staticmethod
|
||||
def get_torrent(full_path):
|
||||
url = f"https://mikanani.me/Downloads/{full_path}"
|
||||
with RequestContent() as request:
|
||||
return request.get_content(url)
|
||||
|
||||
@@ -38,8 +38,8 @@ class RequestContent(RequestURL):
|
||||
enclosure = item.find("enclosure")
|
||||
return TorrentInfo(item.title.string, enclosure["url"])
|
||||
|
||||
def get_xml(self, url):
|
||||
return BeautifulSoup(self.get_url(url).text, "xml")
|
||||
def get_xml(self, _url):
|
||||
return BeautifulSoup(self.get_url(_url).text, "xml")
|
||||
|
||||
# API JSON
|
||||
def get_json(self, _url) -> dict:
|
||||
@@ -50,3 +50,9 @@ class RequestContent(RequestURL):
|
||||
|
||||
def post_data(self, _url, data: dict) -> dict:
|
||||
return self.post_url(_url, data)
|
||||
|
||||
def get_html(self, _url):
|
||||
return self.get_url(_url).text
|
||||
|
||||
def get_content(self, _url):
|
||||
return self.get_url(_url).content
|
||||
|
||||
Reference in New Issue
Block a user