优化项目代码

This commit is contained in:
yongquan 2024-01-08 22:00:14 +08:00
parent 6ccac1f9b6
commit 039f9f9785
6 changed files with 28 additions and 12 deletions

View File

@ -58,11 +58,11 @@
<li>运行 <code>main.py</code> 即可使用</li>
</ol>
<h1>🕹 用户脚本</h1>
<p>如果您的浏览器安装了 <a href="https://www.tampermonkey.net/">Tampermonkey</a> 浏览器扩展程序,可以添加 <a href="https://raw.githubusercontent.com/JoeanAmier/XHS-Downloader/master/static/XHS-Downloader.js">用户脚本</a>,无需下载即可体验!</p>
<p>使用 XHS-Downloader 用户脚本批量获取作品链接,搭配 XHS-Downloader 程序可以实现批量下载无水印作品文件!</p>
<p>如果您的浏览器安装了 <a href="https://www.tampermonkey.net/">Tampermonkey</a> 浏览器扩展程序,可以添加 <a href="https://raw.githubusercontent.com/JoeanAmier/XHS-Downloader/master/static/XHS-Downloader.js">用户脚本</a>,无需下载安装即可体验项目功能</p>
<p>提示:可以使用 XHS-Downloader 用户脚本批量提取网页上的作品链接,搭配 XHS-Downloader 程序即可实现批量下载无水印作品文件!</p>
<h2>脚本功能</h2>
<ul>
<li>下载无水印作品文件</li>
<li>下载小红书无水印作品文件</li>
<li>提取发现页面作品链接</li>
<li>提取账号发布作品链接</li>
<li>提取账号收藏作品链接</li>
@ -229,9 +229,6 @@ async with XHS(work_path=work_path,
<li>Email: yonglelolu@gmail.com</li>
</ul>
<p>
<b>XHS-Downloader 是我个人独立维护的一个开源项目,鉴于个人精力有限,请理解项目进展可能较为缓慢,我会尽力保持更新和维护,以确保项目的稳定性和功能的不断改进。</b>
</p>
<p>
<b>如果您通过 Email 联系我,我可能无法及时查看并回复信息,我会尽力在七天内回复您的邮件;如果有紧急事项或需要更快的回复,请通过其他方式与我联系,谢谢理解!</b>
</p>
<p><b>如果您对抖音 / TikTok 感兴趣,可以了解一下我的另一个开源项目 <a href="https://github.com/JoeanAmier/TikTokDownloader">TikTokDownloader</a></b></p>

View File

@ -35,3 +35,6 @@ class XHSDownloader(App):
async def action_settings(self):
await self.push_screen("setting")
async def action_back(self):
await self.push_screen("index")

View File

@ -15,9 +15,13 @@ class Setting(Screen):
"static/css/setting.tcss")
BINDINGS = [
Binding(key="q", action="quit", description="退出程序"),
Binding(key="b", action="back", description="返回首页"),
]
def compose(self) -> ComposeResult:
yield Header()
yield Label("我是设置页")
yield Label("我是设置页,敬请期待!")
yield Footer()
def on_mount(self) -> None:
self.title = "程序设置"

View File

@ -12,7 +12,11 @@ __all__ = ['Download']
class Download:
CONTENT_TYPE_MAP = {
"quicktime": "mov",
"image/png": "png",
"image/jpeg": "jpg",
"image/webp": "webp",
"application/octet-stream": "",
"video/quicktime": "mov",
}
def __init__(self, manager: Manager, ):
@ -50,7 +54,7 @@ class Download:
try:
async with self.session.get(url, proxy=self.proxy) as response:
suffix = self.__extract_type(
response.headers.get("Content-Type", "")) or format_
response.headers.get("Content-Type")) or format_
temp = self.temp.joinpath(name)
file = path.joinpath(name).with_suffix(f".{suffix}")
if self.manager.is_exists(file):
@ -87,5 +91,4 @@ class Download:
@classmethod
def __extract_type(cls, content: str) -> str:
return "" if content == "application/octet-stream" else cls.CONTENT_TYPE_MAP.get(
s := content.split("/")[-1], s)
return cls.CONTENT_TYPE_MAP.get(content, "")

View File

@ -24,6 +24,7 @@ from .static import (
from .tools import (
retry,
logging,
wait,
)
__all__ = [
@ -50,4 +51,5 @@ __all__ = [
"COOKIE",
"retry",
"logging",
"wait",
]

View File

@ -1,8 +1,11 @@
from asyncio import sleep
from random import randint
from rich.text import Text
from .static import INFO
__all__ = ["retry", "logging"]
__all__ = ["retry", "logging", "wait"]
def retry(function):
@ -23,3 +26,7 @@ def logging(log, text, style=INFO):
log.write(string)
else:
print(string)
async def wait():
await sleep(randint(15, 35) * 0.1)