feat: add local cache poster.

This commit is contained in:
EstrellaXD
2023-10-04 16:56:07 +08:00
parent efa199979e
commit fb721d25dc
11 changed files with 64 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ from bs4 import BeautifulSoup
from urllib3.util import parse_url
from module.network import RequestContent
from module.utils import save_image
def mikan_parser(homepage: str):
@@ -9,13 +10,14 @@ def mikan_parser(homepage: str):
with RequestContent() as req:
content = req.get_html(homepage)
soup = BeautifulSoup(content, "html.parser")
poster_div = soup.find("div", {"class": "bangumi-poster"})
poster_style = poster_div.get("style")
poster_div = soup.find("div", {"class": "bangumi-poster"}).get("style")
official_title = soup.select_one(
'p.bangumi-title a[href^="/Home/Bangumi/"]'
).text
if poster_style:
poster_path = poster_style.split("url('")[1].split("')")[0]
poster_link = f"https://{root_path}{poster_path}"
if poster_div:
poster_path = poster_div.split("url('")[1].split("')")[0]
img = req.get_content(f"https://{root_path}{poster_path}")
suffix = poster_path.split(".")[-1]
poster_link = save_image(img, suffix)
return poster_link, official_title
return "", ""

View File

@@ -4,6 +4,7 @@ from dataclasses import dataclass
from module.conf import TMDB_API
from module.network import RequestContent
from module.utils import save_image
TMDB_URL = "https://api.themoviedb.org"
@@ -85,7 +86,8 @@ def tmdb_parser(title, language) -> TMDBInfo | None:
official_title = info_content.get("name")
year_number = info_content.get("first_air_date").split("-")[0]
if poster_path:
poster_link = "https://image.tmdb.org/t/p/w300" + poster_path
img = req.get_content(f"https://image.tmdb.org/t/p/w780{poster_path}")
poster_link = save_image(img, "jpg")
else:
poster_link = None
return TMDBInfo(