fix: version update. rss add bugs.

This commit is contained in:
EstrellaXD
2023-09-06 23:49:20 +08:00
parent 2e4cf0d621
commit aeac217138
14 changed files with 42 additions and 34 deletions

View File

@@ -31,7 +31,7 @@ async def login(response: Response, form_data=Depends(OAuth2PasswordRequestForm)
@router.get("/refresh_token", response_model=dict, dependencies=[Depends(get_current_user)])
async def refresh(response: Response):
token = create_access_token(
data={"sub": get_current_user()}, expires_delta=timedelta(days=1)
data={"sub": active_user[0]}, expires_delta=timedelta(days=1)
)
response.set_cookie(key="token", value=token, httponly=True, max_age=86400)
return {"access_token": token, "token_type": "bearer"}

View File

@@ -22,7 +22,7 @@ async def get_rss():
@router.post(path="/add", response_model=APIResponse, dependencies=[Depends(get_current_user)])
async def add_rss(rss: RSSItem, ):
with RSSEngine() as engine:
result = engine.add_rss(rss.url, rss.name, rss.aggregate)
result = engine.add_rss(rss.url, rss.name, rss.aggregate, rss.parser)
return u_response(result)

View File

@@ -5,6 +5,7 @@ from module.conf import settings, VERSION
from module.downloader import DownloadClient
from module.models import Config
from module.network import RequestContent
from module.update import version_check
class Checker:
@@ -42,17 +43,7 @@ class Checker:
@staticmethod
def check_version() -> bool:
if not os.path.exists("config/version.info"):
with open("config/version.info", "w+") as f:
f.writelines(VERSION)
return True
with open("config/version.info", "r+") as f:
legacy_version = f.readlines()[-1]
if VERSION == legacy_version:
return False
else:
f.writelines(VERSION)
return True
return version_check()
@staticmethod
def check_database() -> bool:

View File

@@ -7,5 +7,6 @@ from .search_provider import SEARCH_CONFIG
TMDB_API = "32b19d6a05b512190a056fa4e747cbbc"
DATA_PATH = "sqlite:///data/data.db"
LEGACY_DATA_PATH = Path("data/data.json")
VERSION_PATH = Path("config/version.info")
PLATFORM = "Windows" if "\\" in settings.downloader.path else "Unix"

View File

@@ -1,7 +1,7 @@
import logging
from module.conf import VERSION, settings
from module.update import data_migration, database_migration, start_up, first_run
from module.update import data_migration, from_30_to_31, start_up, first_run
from .sub_thread import RenameThread, RSSThread
@@ -43,7 +43,7 @@ class Program(RenameThread, RSSThread):
data_migration()
elif self.version_update:
# Update database
database_migration()
from_30_to_31()
logger.info("Database updated.")
self.start()

View File

@@ -49,7 +49,7 @@ class ProgramStatus(Checker):
@property
def version_update(self):
return self.check_version()
return not self.check_version()
@property
def database(self):

View File

@@ -111,8 +111,8 @@ class BangumiDatabase:
if rss_link not in match_data.rss_link:
match_data.rss_link += f",{rss_link}"
self.update_rss(match_data.title_raw, match_data.rss_link)
if not match_data.poster_link:
self.update_poster(match_data.title_raw, torrent.poster_link)
# if not match_data.poster_link:
# self.update_poster(match_data.title_raw, torrent.poster_link)
torrent_list.pop(i)
break
else:

View File

@@ -1,9 +1,11 @@
from bs4 import BeautifulSoup
from urllib3.util import parse_url
from module.network import RequestContent
def mikan_parser(homepage: str):
root_path = parse_url(homepage).host
with RequestContent() as req:
content = req.get_html(homepage)
soup = BeautifulSoup(content, "html.parser")
@@ -14,5 +16,6 @@ def mikan_parser(homepage: str):
).text
if poster_style:
poster_path = poster_style.split("url('")[1].split("')")[0]
return poster_path, official_title
poster_link = f"https://{root_path}{poster_path}"
return poster_link, official_title
return "", ""

View File

@@ -18,12 +18,13 @@ class RSSAnalyser(TitleParser):
torrent.homepage
)
elif rss.parser == "tmdb":
tmdb_title, season, year = self.tmdb_parser(
tmdb_title, season, year, poster_link = self.tmdb_parser(
bangumi.official_title, bangumi.season, settings.rss_parser.language
)
bangumi.official_title = tmdb_title
bangumi.year = year
bangumi.season = season
bangumi.poster_link = poster_link
else:
pass
bangumi.official_title = re.sub(r"[/:.\\]", " ", bangumi.official_title)

View File

@@ -32,7 +32,7 @@ class RSSEngine(Database):
else:
return []
def add_rss(self, rss_link: str, name: str | None = None, aggregate: bool = True):
def add_rss(self, rss_link: str, name: str | None = None, aggregate: bool = True, parser: str = "mikan"):
if not name:
with RequestContent() as req:
name = req.get_rss_title(rss_link)
@@ -43,7 +43,7 @@ class RSSEngine(Database):
msg_en="Failed to get RSS title.",
msg_zh="无法获取 RSS 标题。",
)
rss_data = RSSItem(name=name, url=rss_link, aggregate=aggregate)
rss_data = RSSItem(name=name, url=rss_link, aggregate=aggregate, parser=parser)
if self.rss.add(rss_data):
return ResponseModel(
status=True,

View File

@@ -1,2 +1,4 @@
from .data_migration import data_migration, database_migration
from .data_migration import data_migration
from .startup import start_up, first_run
from .version_check import version_check
from .cross_version import from_30_to_31

View File

@@ -12,7 +12,7 @@ def data_migration():
rss_link = old_data["rss_link"]
new_data = []
for info in infos:
new_data.append(Bangumi(**info, rss_link=[rss_link]))
new_data.append(Bangumi(**info, rss_link=rss_link))
with RSSEngine() as engine:
engine.bangumi.add_all(new_data)
engine.add_rss(rss_link)

View File

@@ -1,7 +1,6 @@
import logging
from module.rss import RSSEngine
from module.conf import settings
logger = logging.getLogger(__name__)

View File

@@ -1,12 +1,23 @@
from module.conf import VERSION
from module.conf import VERSION, VERSION_PATH
def version_check() -> bool:
with open("config/version.txt", "rw") as f:
# Read last version
versions = f.readlines()
if VERSION[:3] > versions[-1][:3]:
f.write(VERSION[:3] + "\n")
return False
else:
return True
if not VERSION_PATH.exists():
with open(VERSION_PATH, "w") as f:
f.write(VERSION + "\n")
return False
else:
with open(VERSION_PATH, "r+") as f:
# Read last version
versions = f.readlines()
last_version = versions[-1]
if VERSION == last_version:
return True
else:
if VERSION[:3] > versions[-1][:3]:
f.write(VERSION[:3] + "\n")
return False
else:
return True