Skip to content

Commit

Permalink
feat: 发布 1.1 版本
Browse files Browse the repository at this point in the history
1. 减小 Docker 镜像体积
2. 修复检查新版本错误的问题
3. 优化运行状态提示
4. 简化数据请求头
5. 优化链接匹配正则表达式
6. 优化代码运行逻辑
7. 优化代码格式

Closes #3
Closes #5
Closes #7
Closes #10
  • Loading branch information
JoeanAmier committed Sep 1, 2024
1 parent 4e46144 commit d0ae463
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM python:3.12.4-slim

LABEL name="KS-Downloader" version="1.1 Beta" authors="JoeanAmier"
LABEL name="KS-Downloader" version="1.1" authors="JoeanAmier"

COPY source /source
COPY LICENSE /LICENSE
COPY main.py /main.py
COPY requirements.txt /requirements.txt

RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

CMD ["python", "main.py"]
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
</ul>
<p>⭐ KS-Downloader 开发计划及进度可前往 <a href="https://github.com/users/JoeanAmier/projects/6">Projects</a> 查阅</p>
<h1>📸 程序截图</h1>
<img src="docs/项目运行截图.png" alt="">
<img src="docs/项目运行截图1.png" alt="">
<hr>
<img src="docs/项目运行截图2.png" alt="">
<h1>🥣 使用方法</h1>
<h2>🖱 程序运行</h2>
<p>Mac OS、Windows 10 及以上用户可前往 <a href="https://github.com/JoeanAmier/KS-Downloader/releases/latest">Releases</a> 下载程序压缩包,解压后打开程序文件夹,双击运行 <code>main</code> 即可使用。</p>
Expand All @@ -53,14 +55,15 @@
<li><code>https://www.kuaishou.com/f/分享码</code></li>
<li><code>https://v.kuaishou.com/分享码</code></li>
<li><code>https://www.kuaishou.com/short-video/作品ID</code></li>
<li><code>https://kuaishou.cn/short-video/作品ID</code></li>
<br/>
<p><b>推荐使用分享链接;支持单次输入多个作品链接,链接之间使用空格分隔。</b></p>
</ul>
<h1>🪟 关于终端</h1>
<p>⭐ 推荐使用 <a href="https://learn.microsoft.com/zh-cn/windows/terminal/install">Windows 终端</a> (Windows 11 默认终端)运行程序以便获得最佳显示效果!</p>
<h1>⚙️ 配置文件</h1>
<p>项目根目录下的 <code>config.yaml</code> 文件,首次运行自动生成,可以自定义部分运行参数。</p>
<p><b>如果项目功能无法正常使用,请尝试手动复制 Cookie 并写入配置文件后重新运行项目!</b></p>
<p><b>如果项目功能无法正常使用,请尝试配置 Cookie 后再使用!</b></p>
<table>
<thead>
<tr>
Expand Down
28 changes: 16 additions & 12 deletions docs/Release_Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
3. 使用 HTTPX 替代 AIOHTTP
4. 新增自动删除空文件夹功能
5. 优化匹配链接的正则表达式
6. 优化下载进度条显示效果
7. 引入 aiofiles 库写入文件
8. 新增 name_format 参数
9. 更新 chunk 参数默认值
10. 新增文件断点续传功能
11. 优化配置文件字符转义
12. 新增 cookie 配置参数
13. 优化链接的请求方式
14. 优化运行状态提示
15. 优化配置文件编码
16. 修复其他已知 Bug
17. 其他细节优化
6. 修复检查新版本错误的问题
7. 优化下载进度条显示效果
8. 优化链接匹配正则表达式
9. 引入 aiofiles 库写入文件
10. 新增 name_format 参数
11. 修改 chunk 参数默认值
12. 新增文件断点续传功能
13. 优化配置文件字符转义
14. 适配更多作品链接格式
15. 新增 cookie 配置参数
16. 优化链接的请求方式
17. 优化运行状态提示
18. 优化配置文件编码
19. 优化运行错误提示
20. 修复其他已知 Bug
21. 其他细节优化

<p><strong>注意:Mac OS 平台可执行文件 <code>main</code> 可能需要从终端命令行启动;受设备限制,Mac OS 平台可执行文件尚未经过测试,无法保证可用性!</strong></p>
Binary file removed docs/项目运行截图.png
Binary file not shown.
Binary file added docs/项目运行截图1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/项目运行截图2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion source/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
VERSION_MINOR,
VERSION_BETA,
DISCLAIMER_TEXT,
REPOSITORY,
LICENCE,
)
from source.downloader import Downloader
from source.extract import APIExtractor
Expand Down Expand Up @@ -123,7 +125,10 @@ async def __update_version(self):
return
if target := await self.version.get_target_version():
state = self.version.compare_versions(
f"{self.VERSION_MAJOR}.{self.VERSION_MINOR}", target, self.VERSION_BETA)
f"{self.VERSION_MAJOR}.{self.VERSION_MINOR}",
target,
self.VERSION_BETA,
)
self.console.print(
self.version.STATUS_CODE[state],
style=INFO if state == 1 else WARNING)
Expand All @@ -133,10 +138,12 @@ async def __update_version(self):

async def __modify_update(self):
await self.__update_config("Update", 0 if self.config["Update"] else 1)
self.console.print("修改设置成功!", style=INFO, )

async def __modify_record(self):
await self.__update_config("Record", 0 if self.config["Record"] else 1)
self.database.record = self.config["Record"]
self.console.print("修改设置成功!", style=INFO, )

async def __update_config(self, key: str, value: int):
self.config[key] = value
Expand All @@ -152,6 +159,9 @@ def __welcome(self):
self.console.print("\n")
self.console.print(self.LINE, style=MASTER)
self.console.print()
self.console.print(f"项目地址:{REPOSITORY}", style=MASTER)
self.console.print(f"开源协议:{LICENCE}", style=MASTER)
self.console.print()

async def detail(self, detail: str):
app, urls = await self.examiner.run(detail)
Expand Down
1 change: 1 addition & 0 deletions source/custom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
RELEASES,
REPOSITORY,
DISCLAIMER_TEXT,
LICENCE,
)
2 changes: 1 addition & 1 deletion source/custom/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
VERSION_MAJOR = 1
VERSION_MINOR = 1
VERSION_BETA = True
VERSION_BETA = False
PROJECT_NAME = f"KS-Downloader V{VERSION_MAJOR}.{
VERSION_MINOR}{" Beta" if VERSION_BETA else ""}"

Expand Down
11 changes: 7 additions & 4 deletions source/downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ async def __download_file(self, url: str, path: "Path", progress: Progress, id_:
path = path.with_name(f"{path.name}.{suffix}")
position = self.__update_headers_range(headers, temp, )
try:
# print("stream", headers.get("Range")) # 调试代码
async with self.client.stream("GET", url, headers=headers, ) as response:
response.raise_for_status()
task_id = progress.add_task(
Expand All @@ -180,7 +181,7 @@ async def __download_file(self, url: str, path: "Path", progress: Progress, id_:
progress.update(task_id, advance=len(chunk))
except HTTPError as e:
await self.database.delete_download_data(id_)
raise HTTPError from e
raise HTTPError(repr(e)) from e
self.move(temp, path)
self.console.info(f"【{tip}{text} 下载完成")
await self.database.write_download_data(id_)
Expand Down Expand Up @@ -263,9 +264,11 @@ async def __head_file(
url: str,
headers: dict,
) -> [int, str]:
response = await self.client.head(url,
headers=headers,
)
# print("head", headers.get("Range")) # 调试代码
response = await self.client.head(
url,
headers=headers,
)
response.raise_for_status()
suffix = self.__extract_type(
response.headers.get("Content-Type"))
Expand Down
22 changes: 7 additions & 15 deletions source/link/examiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@


class Examiner:
V_SHORT_URL = compile(r"(https?://v\.kuaishou\.com/\S+)")
F_SHORT_URL = compile(r"(https?://www\.kuaishou\.com/f/\S+)")
PC_COMPLETE_URL = compile(r"(https?://www\.kuaishou\.com/short-video/\S+)")
DETAIL_URL = compile(r"(https?://\S+\.m\.chenzhongtech\.com/fw/photo/\S+)")
SHORT_URL = compile(r"(https?://\S*kuaishou\.(?:com|cn)/\S+)")
PC_COMPLETE_URL = compile(r"(https?://\S*kuaishou\.(?:com|cn)/short-video/\S+)")
REDIRECT_URL = compile(r"(https?://\S*chenzhongtech\.(?:com|cn)/fw/photo/\S+)")

def __init__(self, manager: "Manager"):
self.client = manager.client
Expand All @@ -24,13 +23,6 @@ def __init__(self, manager: "Manager"):
self.pc_data_headers = manager.pc_data_headers
self.console = manager.console
self.retry = manager.max_retry
self.app_url = (
self.V_SHORT_URL,
self.F_SHORT_URL,
)
self.pc_url = (
self.PC_COMPLETE_URL,
)

async def run(self, text: str, key="detail"):
app = True
Expand All @@ -49,7 +41,7 @@ async def run(self, text: str, key="detail"):
def __link_judgment(self, urls: str, app: bool, ) -> [bool, list]:
if app:
urls = [i.group() for i in chain(
self.DETAIL_URL.finditer(urls),
self.REDIRECT_URL.finditer(urls),
self.PC_COMPLETE_URL.finditer(urls),
)]
else:
Expand All @@ -59,9 +51,9 @@ def __link_judgment(self, urls: str, app: bool, ) -> [bool, list]:
async def __request_redirect(self, text: str, app=True, ) -> str:
match app:
case True:
urls = chain(*(i.finditer(text) for i in self.app_url))
urls = self.SHORT_URL.finditer(text)
case False:
urls = chain(*(i.finditer(text) for i in self.pc_url))
urls = self.PC_COMPLETE_URL.finditer(text)
case _:
raise TypeError
result = []
Expand All @@ -75,7 +67,7 @@ async def __request_url(self, url: str, ) -> str:
response = await self.client.head(
url,
headers=self.app_headers if (
"https://v.kuaishou.com/" in url) else self.pc_headers,
"v.kuaishou.com" in url) else self.pc_headers,
)
response.raise_for_status()
self.__update_cookie(response.cookies.items(), )
Expand Down
6 changes: 4 additions & 2 deletions source/tools/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ async def inner(self, *args, **kwargs):
try:
return await function(self, *args, **kwargs)
except HTTPError as e:
self.console.error(f"网络异常:{e}")
self.console.error(f"网络异常:{repr(e)}")
except JSONDecodeError as e:
self.console.error(f"响应内容异常:{e}")
self.console.error(f"响应内容异常:{repr(e)}")
except PermissionError as e:
self.console.error(f"权限异常:{repr(e)}")
return None

return inner
2 changes: 1 addition & 1 deletion source/tools/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def compare_versions(
return 4
if target_minor == current_minor:
return 3 if is_development else 1
return 2
return 2 if is_development else 1

@retry_request
@capture_error_request
Expand Down
14 changes: 6 additions & 8 deletions source/variable/internal.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
PC_USERAGENT = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 "
"Safari/537.36")
PC_USERAGENT = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 "
"Safari/537.36")
APP_USERAGENT = (
"Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) "
"Version/16.6 Mobile/15E148 Safari/604.1")
SEC_CH_UA = '"Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"'
PC_PAGE_HEADERS = {
'Accept': '*/*',
'Accept-Language': 'zh-CN,zh;q=0.9',
# 'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'keep-alive',
# 'Sec-Fetch-Dest': 'document',
# 'Sec-Fetch-Mode': 'navigate',
Expand All @@ -21,7 +19,7 @@
}
PC_DATA_HEADERS = {
'Accept': '*/*',
'Accept-Language': 'zh-CN,zh;q=0.9',
# 'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'keep-alive',
'Origin': 'https://www.kuaishou.com',
'Referer': 'https://www.kuaishou.com/',
Expand All @@ -35,7 +33,7 @@
}
APP_HEADERS = {
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.9",
# "Accept-Language": "zh-CN,zh;q=0.9",
"Accept-Encoding": "*/*",
"Host": "v.kuaishou.com",
# "Sec-Fetch-Dest": "document",
Expand All @@ -47,7 +45,7 @@
APP_DATA_HEADERS = {
"Accept": "*/*",
"Accept-Encoding": "*/*",
"Accept-Language": "en,ja;q=0.9,zh-CN;q=0.8,zh-HK;q=0.7,zh;q=0.6",
# "Accept-Language": "en,ja;q=0.9,zh-CN;q=0.8,zh-HK;q=0.7,zh;q=0.6",
"Content-Type": "application/json",
# "Origin": "https://v.m.chenzhongtech.com",
"Host": "m.gifshow.com",
Expand Down

0 comments on commit d0ae463

Please sign in to comment.