Skip to content

Commit

Permalink
更新项目代码
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeanAmier committed Mar 9, 2024
1 parent 7ebfdff commit e56b34a
Show file tree
Hide file tree
Showing 24 changed files with 513 additions and 47 deletions.
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<li>阅读 TikTokDownloader 的免责声明,根据提示输入内容</li>
<li>将 Cookie 信息写入配置文件
<ol><b>手动复制粘贴(推荐)</b>
<li>参考 <a href="https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E6%95%99%E7%A8%8B.md">Cookie 提取教程</a>,复制所需 Cookie 至剪贴板</li>
<li>参考 <a href="https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E8%8E%B7%E5%8F%96%E6%95%99%E7%A8%8B.md">Cookie 提取教程</a>,复制所需 Cookie 至剪贴板</li>
<li>选择 <code>复制粘贴写入 Cookie</code> 选项,按照提示将 Cookie 写入配置文件</li>
</ol>
<ol><b>从浏览器获取(推荐)</b>
Expand All @@ -132,7 +132,7 @@

## 关于 Cookie

[点击查看 Cookie 获取教程](https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E6%95%99%E7%A8%8B.md)
[点击查看 Cookie 获取教程](https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E8%8E%B7%E5%8F%96%E6%95%99%E7%A8%8B.md)

| 程序功能 | 是否需要登录 |
|:--------:|:------:|
Expand Down Expand Up @@ -205,16 +205,10 @@
# ✉️ 联系作者\(Contact\)

<ul>
<li>QQ: 2437596031(联系请说明来意)</li>
<li>QQ Group: <a href="https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/QQ%E7%BE%A4%E8%81%8A%E4%BA%8C%E7%BB%B4%E7%A0%81.png">点击扫码加入群聊</a></li>
<li>Email: yonglelolu@gmail.com</li>
<li>微信: Downloader_Tools</li>
<li>微信公众号: Downloader Tools</li>
<li>QQ 群聊(使用交流): <a href="https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/QQ%E7%BE%A4%E8%81%8A%E4%BA%8C%E7%BB%B4%E7%A0%81.png">扫码加入群聊</a></li>
</ul>
<p>
<b>如果您在使用 TikTokDownloader 的时候遇到问题,请先阅读<a href="https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md">《提问的智慧》</a>,然后加入 QQ 群聊寻求帮助!</b>
</p>
<p>
<b>如果您通过 Email 联系我,我可能无法及时查看并回复信息,我会尽力在七天内回复您的邮件;如果有紧急事项或需要更快的回复,请通过其他方式与我联系,谢谢理解!</b>
</p>
<p><b>如果您对小红书感兴趣,可以了解一下我的另一个开源项目 <a href="https://github.com/JoeanAmier/XHS-Downloader">XHS-Downloader</a></b></p>

# ♥️ 支持项目\(Support\)
Expand Down
Binary file removed docs/Cookie教程1.png
Binary file not shown.
Binary file removed docs/Cookie教程2.png
Binary file not shown.
23 changes: 10 additions & 13 deletions docs/Cookie教程.md → docs/Cookie获取教程.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cookie 提取教程
# Cookie 获取教程

本教程仅演示部分能够提取 `Cookie` 的方法,仍有其他方法能够提取 `Cookie`;本教程使用的浏览器为 `Microsoft Edge`
本教程仅演示部分能够获取所需 `Cookie` 的方法,仍有其他方法能够获取所需 `Cookie`;本教程使用的浏览器为 `Microsoft Edge`
,部分浏览器的开发人员工具可能不支持中文语言。

**方法一\(推荐\)**
Expand All @@ -10,18 +10,15 @@
3.`F12` 打开开发人员工具
4. 选择 `网络` 选项卡
5. 勾选 `保留日志`
6.`筛选器` 输入框输入 `?device`
6.`筛选器` 输入框输入 `cookie-name:odin_tt`
7. 点击 `抖音网页版` 左侧选项卡中 `直播``首页``推荐``关注` 等任意一个模块
8. 在开发人员工具窗口选择任意一个数据包
9. 依次查找 `标头` -> `请求标头` -> `Cookie`
10. 检查 `Cookie` 是否包含 `passport_csrf_token``odin_tt` 字段
11. 如果未包含所需字段,尝试刷新网页或者再次点击其他选项卡
12. 全选并复制 `Cookie` 的值
13. 运行 `main.py` ,写入 `Cookie`
8. 在开发人员工具窗口选择任意一个数据包\(如果无数据包,重复步骤7\)
9. 全选并复制 `Cookie` 的值
10. 运行 `main.py` ,根据提示写入 `Cookie`

**截图示例:**

<img src="Cookie教程1.png" alt="开发人员工具">
<img src="Cookie获取教程1.png" alt="开发人员工具">

**方法二\(不适用\)**

Expand All @@ -31,10 +28,10 @@
4. 选择 `控制台` 选项卡
5. 输入 `document.cookie` 后回车确认
6. 检查 `Cookie` 是否包含 `passport_csrf_token``odin_tt` 字段
7. 如果未包含所需字段,尝试刷新网页或者再次点击左侧选项卡更新页面,回到第 5 步
7. 如果未包含所需字段,尝试刷新网页或者再次点击左侧选项卡更新页面,回到步骤5
8. 全选并复制 `Cookie` 的值
9. 运行 `main.py`写入 `Cookie`
9. 运行 `main.py`根据提示写入 `Cookie`

**截图示例:**

<img src="Cookie教程2.png" alt="开发人员工具">
<img src="Cookie获取教程2.png" alt="开发人员工具">
Binary file added docs/Cookie获取教程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/Cookie获取教程2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions docs/TikTokDownloader文档.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<li>阅读 TikTokDownloader 的免责声明,根据提示输入内容</li>
<li>将 Cookie 信息写入配置文件
<ol><b>手动复制粘贴(推荐)</b>
<li>参考 <a href="https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E6%95%99%E7%A8%8B.md">Cookie 提取教程</a>,复制所需 Cookie 至剪贴板</li>
<li>参考 <a href="https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E8%8E%B7%E5%8F%96%E6%95%99%E7%A8%8B.md">Cookie 提取教程</a>,复制所需 Cookie 至剪贴板</li>
<li>选择 <code>复制粘贴写入 Cookie</code> 选项,按照提示将 Cookie 写入配置文件</li>
</ol>
<ol><b>从浏览器获取(推荐)</b>
Expand All @@ -49,7 +49,7 @@
<li>输入抖音或 TikTok 作品链接即可下载作品文件</li>
</ol>
<h1>获取 Cookie</h1>
<p><a href="https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E6%95%99%E7%A8%8B.md">点击查看 Cookie 获取教程</a>,无效 / 过期的 Cookie 会导致程序获取数据失败或者无法下载高分辨率的视频文件;目前尚无判断 Cookie 无效 / 过期的方法,<a href="https://github.com/JoeanAmier/TikTokDownloader#%E5%85%B3%E4%BA%8E-cookie">更多 Cookie 说明</a>!</p>
<p><a href="https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E8%8E%B7%E5%8F%96%E6%95%99%E7%A8%8B.md">点击查看 Cookie 获取教程</a>,无效 / 过期的 Cookie 会导致程序获取数据失败或者无法下载高分辨率的视频文件;目前尚无判断 Cookie 无效 / 过期的方法,<a href="https://github.com/JoeanAmier/TikTokDownloader#%E5%85%B3%E4%BA%8E-cookie">更多 Cookie 说明</a>!</p>
<h1>入门说明</h1>
<h2>关于终端</h2>
<p>⭐ 推荐使用 <a href="https://learn.microsoft.com/zh-cn/windows/terminal/install">Windows 终端</a>(Windows 11 自带默认终端)运行程序以便获得最佳彩色交互显示效果!</p>
Expand Down Expand Up @@ -556,7 +556,7 @@ https://www.douyin.com/note/123456789
</ul>
<h1>功能介绍</h1>
<h2>复制粘贴写入 Cookie</h2>
<p>参考 <a href="https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E6%95%99%E7%A8%8B.md">Cookie 提取教程</a>,手动从浏览器复制所需 Cookie 至剪贴板,按照程序提示输入 Cookie 后回车确认,程序会自动处理 Cookie 并写入配置文件。</p>
<p>参考 <a href="https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E8%8E%B7%E5%8F%96%E6%95%99%E7%A8%8B.md">Cookie 提取教程</a>,手动从浏览器复制所需 Cookie 至剪贴板,按照程序提示输入 Cookie 后回车确认,程序会自动处理 Cookie 并写入配置文件。</p>
<p><b>推荐使用该方法获取 Cookie</b>,如果粘贴 Cookie 至终端后无响应,可能是 Cookie 文本长度超出终端最大文本长度限制,请考虑更换终端或者其他写入方式。</p>
<h2>从浏览器获取 Cookie</h2>
<p>自动读取本地浏览器的 Cookie 数据,并提取所需 Cookie 写入配置文件,需要完全关闭对应浏览器才能读取 Cookie 数据。</p>
Expand Down Expand Up @@ -1068,7 +1068,7 @@ print(response.json())
<p>记录文件路径: <code>./cache/IDRecorder.txt</code></p>
<p><strong>不建议在程序运行过程中访问记录文件!</strong></p>
<h2>删除指定下载记录</h2>
<p>输入作品 ID 或者作品完整链接(多个作品之间使用空格分隔),删除作品下载记录中对应的数据,如果输入 <code>all</code>,代表清空作品下载记录数据!</p>
<p>输入作品 ID 或者作品完整链接(多个作品之间使用空格分隔,支持混合输入),删除作品下载记录中对应的数据,如果输入 <code>all</code>,代表清空作品下载记录数据!</p>
<p>作品下载记录数据将在程序结束运行后保存至文件!</p>
<h2>启用/禁用运行日志记录</h2>
<p>是否将程序运行日志记录保存到文件,默认关闭,日志文件保存路径:<code>./Log</code></p>
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
requests>=2.31.0
openpyxl>=3.1.2
Flask>=3.0.2
qrcode>=7.4.2
emoji>=2.10.1
rich>=13.7.1
lxml>=5.1.0
browser-cookie3>=0.19.1
aiosqlite>=0.20.0
aiohttp>=3.9.3
9 changes: 4 additions & 5 deletions src/application/TikTokDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ def change_config(self, file: Path):

def write_cookie(self):
self.console.print(
"Cookie 获取教程:https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E6%95"
"%99%E7%A8%8B.md")
"Cookie 获取教程:https://github.com/JoeanAmier/TikTokDownloader/blob/master/docs/Cookie%E8%8E%B7%E5%8F%96%E6"
"%95%99%E7%A8%8B.md")
self.cookie.run()
self.check_settings()
self.parameter.update_cookie()
Expand Down Expand Up @@ -336,9 +336,8 @@ def run(self):
self.main_menu(safe_pop(self.default_mode))
self.close()

@staticmethod
def delete_temp():
rmtree(PROJECT_ROOT.joinpath("./cache/temp").resolve())
def delete_temp(self):
rmtree(self.parameter.temp.resolve())

def periodic_update_cookie(self):
while not self.event.is_set():
Expand Down
4 changes: 4 additions & 0 deletions src/application/main_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def __works_inquire(self, record):
if not any(ids):
self.logger.warning(f"{url} 提取作品 ID 失败")
continue
self.console.print(f"共提取到 {len(ids)} 个作品,开始处理!")
self.input_links_acquisition(tiktok, ids, record)

def __works_txt(self, record):
Expand All @@ -494,6 +495,7 @@ def __works_txt(self, record):
if not any(ids):
self.logger.warning("从文本文档提取作品 ID 失败")
return
self.console.print(f"共提取到 {len(ids)} 个作品,开始处理!")
self.input_links_acquisition(tiktok, ids, record)

def input_links_acquisition(
Expand Down Expand Up @@ -620,6 +622,7 @@ def __comment_inquire(self, root, params, logger):
elif tiktok:
self.console.print("目前项目暂不支持采集 TikTok 作品评论数据!", style=WARNING)
continue
self.console.print(f"共提取到 {len(ids)} 个作品,开始处理!")
self.__comment_handle(ids, root, params, logger)

def __comment_txt(self, root, params, logger):
Expand All @@ -632,6 +635,7 @@ def __comment_txt(self, root, params, logger):
elif tiktok:
self.console.print("目前项目暂不支持采集 TikTok 作品评论数据!", style=WARNING)
return
self.console.print(f"共提取到 {len(ids)} 个作品,开始处理!")
self.__comment_handle(ids, root, params, logger)

def __comment_handle(self, ids: list, root, params, logger):
Expand Down
3 changes: 2 additions & 1 deletion src/config/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def __init__(
self.settings = settings
self.cookie_object = cookie_object
self.main_path = main_path # 项目根路径
self.temp = main_path.joinpath("./cache/temp") # 缓存路径
self.cache = main_path.joinpath("cache") # 缓存路径
self.temp = self.cache.joinpath("temp") # 临时文件路径
self.headers = {
"User-Agent": USERAGENT,
}
Expand Down
2 changes: 2 additions & 0 deletions src/custom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
RETRY,
DISCLAIMER_TEXT,
BLANK_PREVIEW,
TIMEOUT,
)
from .static import (
MAX_WORKERS,
Expand Down Expand Up @@ -72,4 +73,5 @@
"X_BOGUS_CODE",
"DISCLAIMER_TEXT",
"BLANK_PREVIEW",
"TIMEOUT",
]
6 changes: 4 additions & 2 deletions src/custom/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
"X_BOGUS_CODE",
"DISCLAIMER_TEXT",
"BLANK_PREVIEW",
"TIMEOUT",
]

PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
VERSION_MAJOR = 5
VERSION_MINOR = 3
VERSION_BETA = False
VERSION_MINOR = 4
VERSION_BETA = True

REPOSITORY = "https://github.com/JoeanAmier/TikTokDownloader"
LICENCE = "GNU General Public License v3.0"
Expand All @@ -43,6 +44,7 @@
)

RETRY = 5
TIMEOUT = 10

USERAGENT = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 "
Expand Down
41 changes: 39 additions & 2 deletions src/encrypt/ttWid.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
from asyncio import run
from contextlib import suppress
from typing import TYPE_CHECKING

from rich.console import Console

from src.custom import ERROR
from src.tools import request_post

if TYPE_CHECKING:
from src.module import ColorfulConsole
__all__ = ["TtWid", "TtWidTikTok"]


class TtWid:
pass
NAME = "ttwid"
API = "https://ttwid.bytedance.com/ttwid/union/register/"
DATA = (
'{"region":"cn","aid":1768,"needFid":false,"service":"www.ixigua.com","migrate_info":'
'{"ticket":"","source":"node"},"cbUrlProtocol":"https","union":true}')

@classmethod
async def get_tt_wid(cls, console: "ColorfulConsole", ) -> dict | None:
if response := await request_post(console, cls.API, cls.DATA):
return cls.extract(console, response, cls.NAME)
console.print(f"获取 {cls.NAME} 参数失败!", style=ERROR)

@staticmethod
def extract(console: "ColorfulConsole", headers, key: str) -> dict | None:
if c := headers.get("Set-Cookie"):
with suppress(IndexError):
kv = c.split("; ")[0].split("=", 1)
return {kv[0]: kv[1]}
console.print(f"获取 {key} 参数失败!", style=ERROR)

class TtWidTikTok:

class TtWidTikTok(TtWid):
pass


async def debug():
print(await TtWid.get_tt_wid(Console()))


if __name__ == "__main__":
run(debug())
Loading

0 comments on commit e56b34a

Please sign in to comment.