mirror of
https://github.com/PaiGramTeam/FixMiYouShe.git
synced 2024-11-16 12:51:53 +00:00
🐛 Fix cover is too big
This commit is contained in:
parent
8f34ecbb5b
commit
c5db80b54d
@ -28,29 +28,6 @@ class Hyperion:
|
|||||||
def get_headers(self, referer: str = "https://www.miyoushe.com/ys/"):
|
def get_headers(self, referer: str = "https://www.miyoushe.com/ys/"):
|
||||||
return {"User-Agent": self.USER_AGENT, "Referer": referer}
|
return {"User-Agent": self.USER_AGENT, "Referer": referer}
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_images_params(
|
|
||||||
resize: int = 600,
|
|
||||||
quality: int = 80,
|
|
||||||
auto_orient: int = 0,
|
|
||||||
interlace: int = 1,
|
|
||||||
images_format: str = "jpg",
|
|
||||||
) -> str:
|
|
||||||
"""
|
|
||||||
image/resize,s_600/quality,q_80/auto-orient,0/interlace,1/format,jpg
|
|
||||||
:param resize: 图片大小
|
|
||||||
:param quality: 图片质量
|
|
||||||
:param auto_orient: 自适应
|
|
||||||
:param interlace: 未知
|
|
||||||
:param images_format: 图片格式
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
params = (
|
|
||||||
f"image/resize,s_{resize}/quality,q_{quality}/auto-orient,"
|
|
||||||
f"{auto_orient}/interlace,{interlace}/format,{images_format}"
|
|
||||||
)
|
|
||||||
return f"?x-oss-process={params}"
|
|
||||||
|
|
||||||
async def get_official_recommended_posts(self, gids: int) -> List[PostRecommend]:
|
async def get_official_recommended_posts(self, gids: int) -> List[PostRecommend]:
|
||||||
params = {"gids": gids}
|
params = {"gids": gids}
|
||||||
response = await self.client.get(
|
response = await self.client.get(
|
||||||
|
@ -11,6 +11,8 @@ __all__ = (
|
|||||||
"GAME_ID_MAP",
|
"GAME_ID_MAP",
|
||||||
"GAME_STR_MAP",
|
"GAME_STR_MAP",
|
||||||
"CHANNEL_MAP",
|
"CHANNEL_MAP",
|
||||||
|
"clean_url",
|
||||||
|
"get_images_params",
|
||||||
"PostStat",
|
"PostStat",
|
||||||
"PostType",
|
"PostType",
|
||||||
"HoYoPostMultiLang",
|
"HoYoPostMultiLang",
|
||||||
@ -19,6 +21,37 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def clean_url(url: str) -> str:
|
||||||
|
if not url:
|
||||||
|
return ""
|
||||||
|
return url.replace(
|
||||||
|
"hoyolab-upload-private.hoyolab.com", "upload-os-bbs.hoyolab.com"
|
||||||
|
).split("?")[0]
|
||||||
|
|
||||||
|
|
||||||
|
def get_images_params(
|
||||||
|
resize: int = 600,
|
||||||
|
quality: int = 80,
|
||||||
|
auto_orient: int = 0,
|
||||||
|
interlace: int = 1,
|
||||||
|
images_format: str = "jpg",
|
||||||
|
) -> str:
|
||||||
|
"""
|
||||||
|
image/resize,s_600/quality,q_80/auto-orient,0/interlace,1/format,jpg
|
||||||
|
:param resize: 图片大小
|
||||||
|
:param quality: 图片质量
|
||||||
|
:param auto_orient: 自适应
|
||||||
|
:param interlace: 未知
|
||||||
|
:param images_format: 图片格式
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
params = (
|
||||||
|
f"image/resize,s_{resize}/quality,q_{quality}/auto-orient,"
|
||||||
|
f"{auto_orient}/interlace,{interlace}/format,{images_format}"
|
||||||
|
)
|
||||||
|
return f"?x-oss-process={params}"
|
||||||
|
|
||||||
|
|
||||||
class PostStat(BaseModel):
|
class PostStat(BaseModel):
|
||||||
reply_num: int = 0
|
reply_num: int = 0
|
||||||
forward_num: int = Field(
|
forward_num: int = Field(
|
||||||
@ -136,6 +169,8 @@ class PostInfo(BaseModel):
|
|||||||
cover = cover_list[0]["url"]
|
cover = cover_list[0]["url"]
|
||||||
if (not cover) and image_urls:
|
if (not cover) and image_urls:
|
||||||
cover = image_urls[0]
|
cover = image_urls[0]
|
||||||
|
if cover:
|
||||||
|
cover = clean_url(cover) + get_images_params()
|
||||||
game_id = post["game_id"]
|
game_id = post["game_id"]
|
||||||
topics = [
|
topics = [
|
||||||
PostTopic(game_id_=game_id, hoyolab=hoyolab, **topic)
|
PostTopic(game_id_=game_id, hoyolab=hoyolab, **topic)
|
||||||
|
@ -13,6 +13,8 @@ from src.api.models import (
|
|||||||
PostRecommend,
|
PostRecommend,
|
||||||
CHANNEL_MAP,
|
CHANNEL_MAP,
|
||||||
GAME_ID_MAP,
|
GAME_ID_MAP,
|
||||||
|
get_images_params,
|
||||||
|
clean_url,
|
||||||
)
|
)
|
||||||
from src.env import DOMAIN, MIYOUSHE
|
from src.env import DOMAIN, MIYOUSHE
|
||||||
from src.error import ArticleNotFoundError
|
from src.error import ArticleNotFoundError
|
||||||
@ -42,17 +44,9 @@ def get_description(soup: BeautifulSoup) -> str:
|
|||||||
return post_text
|
return post_text
|
||||||
|
|
||||||
|
|
||||||
def clean_url(url: str) -> str:
|
|
||||||
if not url:
|
|
||||||
return ""
|
|
||||||
return url.replace(
|
|
||||||
"hoyolab-upload-private.hoyolab.com", "upload-os-bbs.hoyolab.com"
|
|
||||||
).split("?")[0]
|
|
||||||
|
|
||||||
|
|
||||||
def format_image_url(url: str) -> str:
|
def format_image_url(url: str) -> str:
|
||||||
if url.endswith(".png") or url.endswith(".jpg"):
|
if url.endswith(".png") or url.endswith(".jpg"):
|
||||||
url += Hyperion.get_images_params()
|
url += get_images_params()
|
||||||
return f'<img src="{url}"/>'
|
return f'<img src="{url}"/>'
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user