mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2026-03-22 06:57:16 +08:00
feat(image): 增加对 JPEG 和 HEIC 图片格式的支持
- 在图片下载功能中添加了对 JPEG 和 HEIC 格式的支持 - 更新了相关模块和文档以支持新功能 Closes #229
This commit is contained in:
@@ -173,7 +173,7 @@ class Setting(Screen):
|
||||
Label(),
|
||||
Container(
|
||||
Select.from_values(
|
||||
("PNG", "WEBP"),
|
||||
("AUTO", "PNG", "WEBP", "JPEG", "HEIC"),
|
||||
value=self.data["image_format"].upper(),
|
||||
allow_blank=False,
|
||||
id="image_format",
|
||||
|
||||
@@ -34,6 +34,7 @@ from source.module import (
|
||||
VERSION_MAJOR,
|
||||
VERSION_MINOR,
|
||||
VERSION_BETA,
|
||||
__VERSION__
|
||||
)
|
||||
from source.module import logging
|
||||
from source.module import sleep_time
|
||||
@@ -47,7 +48,7 @@ from .video import Video
|
||||
__all__ = ["XHS"]
|
||||
|
||||
|
||||
def _data_cache(function):
|
||||
def data_cache(function):
|
||||
async def inner(
|
||||
self,
|
||||
data: dict,
|
||||
@@ -179,7 +180,7 @@ class XHS:
|
||||
logging(log, _("提取作品文件下载地址失败"), ERROR)
|
||||
await self.save_data(container)
|
||||
|
||||
@_data_cache
|
||||
@data_cache
|
||||
async def save_data(
|
||||
self,
|
||||
data: dict,
|
||||
@@ -480,7 +481,7 @@ class XHS:
|
||||
self.server = FastAPI(
|
||||
debug=self.VERSION_BETA,
|
||||
title="XHS-Downloader",
|
||||
version=f"{self.VERSION_MAJOR}.{self.VERSION_MINOR}",
|
||||
version=__VERSION__,
|
||||
)
|
||||
self.setup_routes()
|
||||
config = Config(
|
||||
|
||||
@@ -14,24 +14,24 @@ class Image:
|
||||
for i in images
|
||||
]
|
||||
match format_:
|
||||
case "png":
|
||||
case "png" | "webp" | "jpeg" | "heic" | "avif":
|
||||
return [
|
||||
Html.format_url(cls.__generate_png_link(i)) for i in token_list
|
||||
Html.format_url(cls.__generate_fixed_link(i, format_, )) for i in token_list
|
||||
], live_link
|
||||
case "webp":
|
||||
case "auto":
|
||||
return [
|
||||
Html.format_url(cls.__generate_webp_link(i)) for i in token_list
|
||||
Html.format_url(cls.__generate_auto_link(i)) for i in token_list
|
||||
], live_link
|
||||
case _:
|
||||
raise ValueError
|
||||
|
||||
@staticmethod
|
||||
def __generate_webp_link(token: str) -> str:
|
||||
def __generate_auto_link(token: str) -> str:
|
||||
return f"https://sns-img-bd.xhscdn.com/{token}"
|
||||
|
||||
@staticmethod
|
||||
def __generate_png_link(token: str) -> str:
|
||||
return f"https://ci.xiaohongshu.com/{token}?imageView2/format/png"
|
||||
def __generate_fixed_link(token: str, format_: str, ) -> str:
|
||||
return f"https://ci.xiaohongshu.com/{token}?imageView2/format/{format_}"
|
||||
|
||||
@staticmethod
|
||||
def __extract_image_token(url: str) -> str:
|
||||
|
||||
@@ -29,6 +29,7 @@ from .static import (
|
||||
FILE_SIGNATURES,
|
||||
FILE_SIGNATURES_LENGTH,
|
||||
MAX_WORKERS,
|
||||
__VERSION__,
|
||||
)
|
||||
from .tools import (
|
||||
retry,
|
||||
|
||||
@@ -138,8 +138,8 @@ class Manager:
|
||||
|
||||
@staticmethod
|
||||
def __check_image_format(image_format) -> str:
|
||||
if image_format in {"png", "PNG", "webp", "WEBP"}:
|
||||
return image_format.lower()
|
||||
if (i := image_format.lower()) in {"auto", "png", "webp", "jpeg", "heic", "avif", }:
|
||||
return i
|
||||
return "png"
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -3,7 +3,7 @@ from pathlib import Path
|
||||
VERSION_MAJOR = 2
|
||||
VERSION_MINOR = 5
|
||||
VERSION_BETA = True
|
||||
__version__ = f"{VERSION_MAJOR}.{VERSION_MINOR}.{'beta' if VERSION_BETA else 'stable'}"
|
||||
__VERSION__ = f"{VERSION_MAJOR}.{VERSION_MINOR}.{'beta' if VERSION_BETA else 'stable'}"
|
||||
ROOT = Path(__file__).resolve().parent.parent.parent
|
||||
PROJECT = f"XHS-Downloader V{VERSION_MAJOR}.{VERSION_MINOR} {
|
||||
'Beta' if VERSION_BETA else 'Stable'
|
||||
@@ -68,4 +68,4 @@ FILE_SIGNATURES_LENGTH = max(
|
||||
MAX_WORKERS: int = 4
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(__version__)
|
||||
print(__VERSION__)
|
||||
|
||||
Reference in New Issue
Block a user