diff --git a/docs/snippets/QA.md b/docs/snippets/QA.md index b9b794a..32f37ea 100644 --- a/docs/snippets/QA.md +++ b/docs/snippets/QA.md @@ -1,4 +1,4 @@ -// #region response-is-null-snippet +# region response-is-null-snippet 只要是出现第 n 次响应内容为空均是`cookie`设置的问题。 你需要排查的是: @@ -7,25 +7,25 @@ 3. 使用`--auto-cookie`命令时,确保选择的浏览器中已登录正常账号,游客账号的`cookie`非常不稳定。 4. 如果你使用的是该app扫码登录的功能,可能会因为未知的设备环境风控造成网页端与app端账号下线。如果出现扫码登录的`cookie`失效,请使用`--auto-cookie`命令。 5. `0.0.1.2`之前的版本如果将`cookie`保存在自定义配置文件中,会有无法被正确识别的情况。 -// #endregion response-is-null-snippet +# endregion response-is-null-snippet -// #region api-rate-limit-snippet +# region api-rate-limit-snippet 如果出现`API Rate Limit Error`时只需等待一会后重试即可。 继续频繁出现该错误需在网页端中重新登录并获取`cookie`。 仍无效后请切换网络环境和账号。 https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81 https://datatracker.ietf.org/doc/html/rfc6585#section-7.2 -// #endregion api-rate-limit-snippet +# endregion api-rate-limit-snippet -// #region urlopen-errno-11001 +# region urlopen-errno-11001 该问题为本地网络连接问题,请检查你的网络连接是否正常。需要排查代理是否可以正常访问。 -// #endregion urlopen-errno-11001 +# endregion urlopen-errno-11001 -// #region f2-command-not-found +# region f2-command-not-found 在非Windows系统中,如果出现`f2: command not found`错误,说明你的系统环境变量中没有添加`f2`命令的路径。 运行`which f2`命令查看`f2`命令的路径,然后将该路径添加到环境变量中。 @@ -33,10 +33,10 @@ https://datatracker.ietf.org/doc/html/rfc6585#section-7.2 添加环境变量的方法: 1. 编辑`~/.bashrc`文件,添加`export PATH="$PATH:/home/YOUR_NAME/.local/bin"`。 2. 运行`source ~/.bashrc`命令使环境变量生效。 -// #endregion f2-command-not-found +# endregion f2-command-not-found -// #region no-matching-videos-found +# region no-matching-videos-found 如果出现`WARNING 没有找到符合条件的作品`,请检查你是否配置了`interval`参数,该参数是用来设置作品发布时间的筛选条件。 解决办法: @@ -48,10 +48,10 @@ https://datatracker.ietf.org/doc/html/rfc6585#section-7.2 可参考的issue: https://github.com/Johnserf-Seed/f2/issues/42 https://github.com/Johnserf-Seed/TikTokDownload/issues/660 -// #endregion no-matching-videos-found +# endregion no-matching-videos-found -// #region ssl-faild-01 +# region ssl-faild-01 出现`EOF occurred in violation of protocol (_ssl.c:992)`说明SSL握手失败。 解决办法: @@ -59,10 +59,10 @@ https://github.com/Johnserf-Seed/TikTokDownload/issues/660 2. 确保代理网络连接稳定。 这个问题可能涉及到多个方面,需要自己逐步排查和解决。 -// #endregion ssl-faild-01 +# endregion ssl-faild-01 -// #region ssl-faild-02 +# region ssl-faild-02 出现`_ssl.c:975: The handshake operation timed out`说明SSL握手超时。可能是网络连接不稳定或延迟过高导致。 解决办法: @@ -72,10 +72,10 @@ https://github.com/Johnserf-Seed/TikTokDownload/issues/660 4. 调整超时设置 这个问题可能涉及到多个方面,需要自己逐步排查和解决。 -// #endregion ssl-faild-02 +# endregion ssl-faild-02 -// #region tiktok-403-forbidden +# region tiktok-403-forbidden 当下载`tiktok`视频时出现`403 Forbidden`错误时,是由于`设备id`被封禁导致的。 `设备id`与生成的`cookie`是一一对应的,如果`设备id`被封禁,那么生成的`cookie`也会被封禁。 @@ -89,4 +89,4 @@ https://github.com/Johnserf-Seed/TikTokDownload/issues/660 代码片段: https://johnserf-seed.github.io/f2/guide/apps/tiktok/#%E7%94%9F%E6%88%90deviceid-%F0%9F%9F%A2 -// #endregion tiktok-403-forbidden \ No newline at end of file +# endregion tiktok-403-forbidden \ No newline at end of file diff --git a/docs/snippets/douyin/abogus.py b/docs/snippets/douyin/abogus.py index 03afbb2..044ba1a 100644 --- a/docs/snippets/douyin/abogus.py +++ b/docs/snippets/douyin/abogus.py @@ -1,4 +1,4 @@ -// #region str-2-endpoint-snippet +# region str-2-endpoint-snippet # 使用接口地址直接生成请求链接 import asyncio from f2.apps.douyin.utils import ABogusManager, ClientConfManager @@ -17,10 +17,10 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion str-2-endpoint-snippet +# endregion str-2-endpoint-snippet -// #region model-2-endpoint-snippet +# region model-2-endpoint-snippet # 使用用户信息模型生成请求链接 import asyncio from f2.apps.douyin.api import DouyinAPIEndpoints as dyendpoint @@ -33,12 +33,12 @@ async def gen_user_profile(params: UserProfile): ClientConfManager.user_agent(), base_endpoint=dyendpoint.USER_DETAIL, params=params.model_dump(), - request_type = "GET", + request_type="GET", ) async def main(): - sec_user_id="MS4wLjABAAAANXSltcLCzDGmdNFI2Q_QixVTr67NiYzjKOIP5s03CAE" + sec_user_id = "MS4wLjABAAAANXSltcLCzDGmdNFI2Q_QixVTr67NiYzjKOIP5s03CAE" params = UserProfile(sec_user_id=sec_user_id) return await gen_user_profile(params) @@ -46,10 +46,10 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion model-2-endpoint-snippet +# endregion model-2-endpoint-snippet -// #region model-2-endpoint-2-filter-snippet +# region model-2-endpoint-2-filter-snippet # 使用用户信息模型生成请求链接,请求接口并使用自定义过滤器输出所需接口数据 import asyncio from f2.apps.douyin.api import DouyinAPIEndpoints as dyendpoint @@ -70,14 +70,15 @@ async def main(): async def main(): async with DouyinCrawler(kwargs) as crawler: - sec_user_id="MS4wLjABAAAANXSltcLCzDGmdNFI2Q_QixVTr67NiYzjKOIP5s03CAE" + sec_user_id = "MS4wLjABAAAANXSltcLCzDGmdNFI2Q_QixVTr67NiYzjKOIP5s03CAE" params = UserProfile(sec_user_id=sec_user_id) response = await crawler.fetch_user_profile(params) user = UserProfileFilter(response) # return user # user为UserProfileFilter对象,需要调用_to_dict()方法转为字典格式 return user._to_dict() + if __name__ == "__main__": print(asyncio.run(main())) -// #endregion model-2-endpoint-2-filter-snippet \ No newline at end of file +# endregion model-2-endpoint-2-filter-snippet diff --git a/docs/snippets/douyin/aweme-id.py b/docs/snippets/douyin/aweme-id.py index 9734e47..50f56d0 100644 --- a/docs/snippets/douyin/aweme-id.py +++ b/docs/snippets/douyin/aweme-id.py @@ -1,4 +1,4 @@ -// #region single-aweme-id-snippet +# region single-aweme-id-snippet import asyncio from f2.apps.douyin.utils import AwemeIdFetcher @@ -13,10 +13,10 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion single-aweme-id-snippet +# endregion single-aweme-id-snippet -// #region multi-aweme-id-snippet +# region multi-aweme-id-snippet import asyncio from f2.apps.douyin.utils import AwemeIdFetcher from f2.utils.utils import extract_valid_urls @@ -41,4 +41,4 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion multi-aweme-id-snippet \ No newline at end of file +# endregion multi-aweme-id-snippet diff --git a/docs/snippets/douyin/mix-id.py b/docs/snippets/douyin/mix-id.py index 8fc88b4..af921ff 100644 --- a/docs/snippets/douyin/mix-id.py +++ b/docs/snippets/douyin/mix-id.py @@ -1,4 +1,4 @@ -// #region single-mix-id-snippet +# region single-mix-id-snippet import asyncio from f2.apps.douyin.utils import MixIdFetcher @@ -11,10 +11,10 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion single-mix-id-snippet +# endregion single-mix-id-snippet -// #region multi-mix-id-snippet +# region multi-mix-id-snippet import asyncio from f2.apps.douyin.utils import MixIdFetcher from f2.utils.utils import extract_valid_urls @@ -36,4 +36,4 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion multi-mix-id-snippet \ No newline at end of file +# endregion multi-mix-id-snippet diff --git a/docs/snippets/douyin/sec-user-id.py b/docs/snippets/douyin/sec-user-id.py index 36216dc..4e1d9af 100644 --- a/docs/snippets/douyin/sec-user-id.py +++ b/docs/snippets/douyin/sec-user-id.py @@ -1,23 +1,26 @@ -// #region single-user-id-snippet +# region single-user-id-snippet import asyncio from f2.apps.douyin.utils import SecUserIdFetcher + async def main(): raw_url = "https://www.douyin.com/user/MS4wLjABAAAANXSltcLCzDGmdNFI2Q_QixVTr67NiYzjKOIP5s03CAE?vid=7285950278132616463" # 对于单个URL return await SecUserIdFetcher.get_sec_user_id(raw_url) + if __name__ == "__main__": print(asyncio.run(main())) -// #endregion single-user-id-snippet +# endregion single-user-id-snippet -// #region multi-user-id-snippet +# region multi-user-id-snippet import asyncio from f2.apps.douyin.utils import SecUserIdFetcher from f2.utils.utils import extract_valid_urls + async def main(): raw_urls = [ "https://www.douyin.com/user/MS4wLjABAAAANXSltcLCzDGmdNFI2Q_QixVTr67NiYzjKOIP5s03CAE?vid=7285950278132616463", @@ -32,7 +35,8 @@ async def main(): # 对于URL列表 return await SecUserIdFetcher.get_all_sec_user_id(urls) + if __name__ == "__main__": print(asyncio.run(main())) -// #endregion multi-user-id-snippet \ No newline at end of file +# endregion multi-user-id-snippet diff --git a/docs/snippets/douyin/user-collection.py b/docs/snippets/douyin/user-collection.py index 2a135de..728ccd7 100644 --- a/docs/snippets/douyin/user-collection.py +++ b/docs/snippets/douyin/user-collection.py @@ -1,4 +1,4 @@ -// #region user-collection-music-snippet +# region user-collection-music-snippet import asyncio from f2.apps.douyin.handler import DouyinHandler @@ -27,10 +27,10 @@ async def main(): if __name__ == "__main__": asyncio.run(main()) -// #endregion user-collection-music-snippet +# endregion user-collection-music-snippet -// #region user-collection-video-snippet +# region user-collection-video-snippet import asyncio from f2.apps.douyin.handler import DouyinHandler @@ -58,4 +58,4 @@ async def main(): if __name__ == "__main__": asyncio.run(main()) -// #endregion user-collection-video-snippet \ No newline at end of file +# endregion user-collection-video-snippet diff --git a/docs/snippets/douyin/user-collects.py b/docs/snippets/douyin/user-collects.py index b73e5c7..f5d5949 100644 --- a/docs/snippets/douyin/user-collects.py +++ b/docs/snippets/douyin/user-collects.py @@ -1,4 +1,4 @@ -// #region user-collects-snippet +# region user-collects-snippet import asyncio from f2.apps.douyin.handler import DouyinHandler @@ -25,10 +25,10 @@ async def main(): if __name__ == "__main__": asyncio.run(main()) -// #endregion user-collects-snippet +# endregion user-collects-snippet -// #region user-collects-videos-snippet +# region user-collects-videos-snippet import asyncio from f2.apps.douyin.handler import DouyinHandler @@ -60,4 +60,4 @@ async def main(): if __name__ == "__main__": asyncio.run(main()) -// #endregion user-collects-videos-snippet \ No newline at end of file +# endregion user-collects-videos-snippet diff --git a/docs/snippets/douyin/user-folder.py b/docs/snippets/douyin/user-folder.py index a9271c8..162d4e4 100644 --- a/docs/snippets/douyin/user-folder.py +++ b/docs/snippets/douyin/user-folder.py @@ -1,4 +1,4 @@ -// #region create-user-folder +# region create-user-folder from f2.apps.douyin.utils import create_user_folder @@ -19,10 +19,10 @@ print(create_user_folder(kwargs, current_nickname)) # X:\......\Download\douyin\post\New Nickname -// #endregion create-user-folder +# endregion create-user-folder -// #region rename-user-folder +# region rename-user-folder import asyncio from f2.apps.douyin.db import AsyncUserDB from f2.apps.douyin.utils import rename_user_folder @@ -56,7 +56,8 @@ async def main(): print(new_user_path) # X:\......\Download\douyin\post\New Nickname + if __name__ == "__main__": asyncio.run(main()) -// #endregion rename-user-folder \ No newline at end of file +# endregion rename-user-folder diff --git a/docs/snippets/douyin/webcast-id.py b/docs/snippets/douyin/webcast-id.py index b161de4..0d0fa70 100644 --- a/docs/snippets/douyin/webcast-id.py +++ b/docs/snippets/douyin/webcast-id.py @@ -1,4 +1,4 @@ -// #region single-webcast-id-snippet +# region single-webcast-id-snippet import asyncio from f2.apps.douyin.utils import WebCastIdFetcher @@ -11,10 +11,10 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion single-webcast-id-snippet +# endregion single-webcast-id-snippet -// #region multi-webcast-id-snippet +# region multi-webcast-id-snippet import asyncio from f2.apps.douyin.utils import WebCastIdFetcher from f2.utils.utils import extract_valid_urls @@ -39,4 +39,4 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion multi-webcast-id-snippet \ No newline at end of file +# endregion multi-webcast-id-snippet diff --git a/docs/snippets/douyin/webcast-signature.py b/docs/snippets/douyin/webcast-signature.py index 2217408..ef327d6 100644 --- a/docs/snippets/douyin/webcast-signature.py +++ b/docs/snippets/douyin/webcast-signature.py @@ -1,4 +1,4 @@ -// #region webcast-signature-snippet +# region webcast-signature-snippet from f2.apps.douyin.algorithm.webcast_signature import DouyinWebcastSignature if __name__ == "__main__": @@ -9,10 +9,10 @@ ).get_signature(room_id, user_unique_id) print(signature) -// #endregion webcast-signature-snippet +# endregion webcast-signature-snippet -// #region webcast-signature-manager-snippet +# region webcast-signature-manager-snippet # fetch_live_danmaku import asyncio @@ -33,4 +33,4 @@ async def main(params: LiveWebcast): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion webcast-signature-manager-snippet +# endregion webcast-signature-manager-snippet diff --git a/docs/snippets/douyin/xbogus.py b/docs/snippets/douyin/xbogus.py index a4bcf9a..96113e0 100644 --- a/docs/snippets/douyin/xbogus.py +++ b/docs/snippets/douyin/xbogus.py @@ -1,4 +1,4 @@ -// #region str-2-endpoint-snippet +# region str-2-endpoint-snippet # 使用接口地址直接生成请求链接 import asyncio from f2.apps.douyin.utils import XBogusManager, ClientConfManager @@ -15,10 +15,10 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion str-2-endpoint-snippet +# endregion str-2-endpoint-snippet -// #region model-2-endpoint-snippet +# region model-2-endpoint-snippet # 使用用户信息模型生成请求链接 import asyncio from f2.apps.douyin.api import DouyinAPIEndpoints as dyendpoint @@ -35,7 +35,7 @@ async def gen_user_profile(params: UserProfile): async def main(): - sec_user_id="MS4wLjABAAAANXSltcLCzDGmdNFI2Q_QixVTr67NiYzjKOIP5s03CAE" + sec_user_id = "MS4wLjABAAAANXSltcLCzDGmdNFI2Q_QixVTr67NiYzjKOIP5s03CAE" params = UserProfile(sec_user_id=sec_user_id) return await gen_user_profile(params) @@ -43,10 +43,10 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion model-2-endpoint-snippet +# endregion model-2-endpoint-snippet -// #region model-2-endpoint-2-filter-snippet +# region model-2-endpoint-2-filter-snippet # 使用用户信息模型生成请求链接,请求接口并使用自定义过滤器输出所需接口数据 import asyncio from f2.apps.douyin.api import DouyinAPIEndpoints as dyendpoint @@ -68,14 +68,15 @@ async def main(): async def main(): async with DouyinCrawler(kwargs) as crawler: - sec_user_id="MS4wLjABAAAANXSltcLCzDGmdNFI2Q_QixVTr67NiYzjKOIP5s03CAE" + sec_user_id = "MS4wLjABAAAANXSltcLCzDGmdNFI2Q_QixVTr67NiYzjKOIP5s03CAE" params = UserProfile(sec_user_id=sec_user_id) response = await crawler.fetch_user_profile(params) user = UserProfileFilter(response) # return user # user为UserProfileFilter对象,需要调用_to_dict()方法转为字典格式 return user._to_dict() + if __name__ == "__main__": print(asyncio.run(main())) -// #endregion model-2-endpoint-2-filter-snippet \ No newline at end of file +# endregion model-2-endpoint-2-filter-snippet diff --git a/docs/snippets/set-debug.py b/docs/snippets/set-debug.py index 5a08cc2..1368f96 100644 --- a/docs/snippets/set-debug.py +++ b/docs/snippets/set-debug.py @@ -1,17 +1,18 @@ -// #region set-config-snippet +# region set-config-snippet import f2 f2.APP_CONFIG_FILE_PATH = "app.yaml" -// #endregion set-config-snippet +# endregion set-config-snippet -// #region set-debug-snippet +# region set-debug-snippet import asyncio from f2.apps.douyin.handler import DouyinHandler -from f2.log.logger import logger # [!code focus] -logger.setLevel("WARNING") # [!code focus] +from f2.log.logger import logger # [!code focus] + +logger.setLevel("WARNING") # [!code focus] kwargs = { "headers": { @@ -23,25 +24,27 @@ } if __name__ == "__main__": - asyncio.run(DouyinHandler(kwargs).fetch_user_post( - "MS4wLjABAAAA35iXl5qqCbLKY99pUvxkXzvpSXi8jgUbJ0zR4EuTpcHcS8PHaEb6G9yB6iKR0dNl" + asyncio.run( + DouyinHandler(kwargs).fetch_user_post( + "MS4wLjABAAAA35iXl5qqCbLKY99pUvxkXzvpSXi8jgUbJ0zR4EuTpcHcS8PHaEb6G9yB6iKR0dNl" ) ) -// #endregion set-debug-snippet +# endregion set-debug-snippet -// #region cli-debug-snippet -f2 -d WARNING -M post -u https://www.douyin.com/user/MS4wLjABAAAA35iXl5qqCbLKY99pUvxkXzvpSXi8jgUbJ0zR4EuTpcHcS8PHaEb6G9yB6iKR0dNl -// #endregion cli-debug-snippet +# region cli-debug-snippet +# f2 -d WARNING -M post -u https://www.douyin.com/user/MS4wLjABAAAA35iXl5qqCbLKY99pUvxkXzvpSXi8jgUbJ0zR4EuTpcHcS8PHaEb6G9yB6iKR0dNl +# endregion cli-debug-snippet -// #region log-2-console-snippet +# region log-2-console-snippet import asyncio from f2.apps.douyin.handler import DouyinHandler -from f2.log.logger import log_setup # [!code focus] -logger = log_setup(log_to_console=True) # [!code focus] +from f2.log.logger import log_setup # [!code focus] + +logger = log_setup(log_to_console=True) # [!code focus] kwargs = { "headers": { @@ -53,9 +56,10 @@ } if __name__ == "__main__": - asyncio.run(DouyinHandler(kwargs).fetch_user_post( - "MS4wLjABAAAA35iXl5qqCbLKY99pUvxkXzvpSXi8jgUbJ0zR4EuTpcHcS8PHaEb6G9yB6iKR0dNl" + asyncio.run( + DouyinHandler(kwargs).fetch_user_post( + "MS4wLjABAAAA35iXl5qqCbLKY99pUvxkXzvpSXi8jgUbJ0zR4EuTpcHcS8PHaEb6G9yB6iKR0dNl" ) ) -// #endregion log-2-console-snippet \ No newline at end of file +# endregion log-2-console-snippet diff --git a/docs/snippets/tiktok/aweme-id.py b/docs/snippets/tiktok/aweme-id.py index 94e1d83..060077b 100644 --- a/docs/snippets/tiktok/aweme-id.py +++ b/docs/snippets/tiktok/aweme-id.py @@ -1,4 +1,4 @@ -// #region single-aweme-id-snippet +# region single-aweme-id-snippet import asyncio from f2.apps.tiktok.utils import AwemeIdFetcher @@ -12,10 +12,10 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion single-aweme-id-snippet +# endregion single-aweme-id-snippet -// #region multi-aweme-id-snippet +# region multi-aweme-id-snippet import asyncio from f2.apps.tiktok.utils import AwemeIdFetcher from f2.utils.utils import extract_valid_urls @@ -38,4 +38,4 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion multi-aweme-id-snippet \ No newline at end of file +# endregion multi-aweme-id-snippet diff --git a/docs/snippets/tiktok/device-id.py b/docs/snippets/tiktok/device-id.py index e43690d..ff5c466 100644 --- a/docs/snippets/tiktok/device-id.py +++ b/docs/snippets/tiktok/device-id.py @@ -1,4 +1,4 @@ -// #region device-id-snippet +# region device-id-snippet import asyncio from f2.apps.tiktok.utils import DeviceIdManager @@ -13,10 +13,10 @@ async def main(): if __name__ == "__main__": asyncio.run(main()) -// #endregion device-id-snippet +# endregion device-id-snippet -// #region device-ids-snippet +# region device-ids-snippet import asyncio from f2.apps.tiktok.utils import DeviceIdManager @@ -31,4 +31,4 @@ async def main(): if __name__ == "__main__": asyncio.run(main()) -// #endregion device-ids-snippet \ No newline at end of file +# endregion device-ids-snippet diff --git a/docs/snippets/tiktok/sec-uid.py b/docs/snippets/tiktok/sec-uid.py index b9586c7..534014a 100644 --- a/docs/snippets/tiktok/sec-uid.py +++ b/docs/snippets/tiktok/sec-uid.py @@ -1,4 +1,4 @@ -// #region single-secuid-snippet +# region single-secuid-snippet import asyncio from f2.apps.tiktok.utils import SecUserIdFetcher @@ -12,10 +12,10 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion single-secuid-snippet +# endregion single-secuid-snippet -// #region multi-secuid-snippet +# region multi-secuid-snippet import asyncio from f2.apps.tiktok.utils import SecUserIdFetcher from f2.utils.utils import extract_valid_urls @@ -38,4 +38,4 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion multi-secuid-snippet \ No newline at end of file +# endregion multi-secuid-snippet diff --git a/docs/snippets/tiktok/token-manager.py b/docs/snippets/tiktok/token-manager.py index 8c5c849..7559101 100644 --- a/docs/snippets/tiktok/token-manager.py +++ b/docs/snippets/tiktok/token-manager.py @@ -1,39 +1,34 @@ -// #region mstoken-real-sinppest +# region mstoken-real-sinppest from f2.apps.tiktok.utils import TokenManager if __name__ == "__main__": print("tiktok real msToken:", TokenManager.gen_real_msToken()) -// #endregion mstoken-real-sinppest +# endregion mstoken-real-sinppest -// #region mstoken-false-sinppest +# region mstoken-false-sinppest from f2.apps.tiktok.utils import TokenManager if __name__ == "__main__": print("tiktok fake msToken:", TokenManager.gen_false_msToken()) -// #endregion mstoken-false-sinppest +# endregion mstoken-false-sinppest -// #region ttwid-sinppest +# region ttwid-sinppest from f2.apps.tiktok.utils import TokenManager if __name__ == "__main__": print("tiktok ttwid:", TokenManager.gen_ttwid()) -// #endregion ttwid-sinppest +# endregion ttwid-sinppest -// #region odin_tt-sinppest +# region odin_tt-sinppest from f2.apps.tiktok.utils import TokenManager if __name__ == "__main__": print("tiktok odin_tt:", TokenManager.gen_odin_tt()) -// #endregion odin_tt-sinppest - - - - - +# endregion odin_tt-sinppest diff --git a/docs/snippets/tiktok/unique-id.py b/docs/snippets/tiktok/unique-id.py index e859b59..28f36eb 100644 --- a/docs/snippets/tiktok/unique-id.py +++ b/docs/snippets/tiktok/unique-id.py @@ -1,4 +1,4 @@ -// #region single-unique-id-snippet +# region single-unique-id-snippet import asyncio from f2.apps.tiktok.utils import SecUserIdFetcher @@ -12,10 +12,10 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion single-unique-id-snippet +# endregion single-unique-id-snippet -// #region multi-unique-id-snippet +# region multi-unique-id-snippet import asyncio from f2.apps.tiktok.utils import SecUserIdFetcher from f2.utils.utils import extract_valid_urls @@ -38,4 +38,4 @@ async def main(): if __name__ == "__main__": print(asyncio.run(main())) -// #endregion multi-unique-id-snippet \ No newline at end of file +# endregion multi-unique-id-snippet diff --git a/docs/snippets/tiktok/user-folder.py b/docs/snippets/tiktok/user-folder.py index e4bc555..6168db5 100644 --- a/docs/snippets/tiktok/user-folder.py +++ b/docs/snippets/tiktok/user-folder.py @@ -1,4 +1,4 @@ -// #region create-user-folder +# region create-user-folder from f2.apps.tiktok.utils import create_user_folder @@ -19,10 +19,10 @@ print(create_user_folder(kwargs, current_nickname)) # X:\......\Download\tiktok\post\New Nickname -// #endregion create-user-folder +# endregion create-user-folder -// #region rename-user-folder +# region rename-user-folder import asyncio from f2.apps.tiktok.db import AsyncUserDB from f2.apps.tiktok.utils import rename_user_folder @@ -42,9 +42,13 @@ async def main(): - sec_user_id = "MS4wLjABAAAAQhcYf_TjRKUku-aF8oqngAfzrYksgGLRz8CKMciBFdfR54HQu3qGs-WoJ-KO7hO8" + sec_user_id = ( + "MS4wLjABAAAAQhcYf_TjRKUku-aF8oqngAfzrYksgGLRz8CKMciBFdfR54HQu3qGs-WoJ-KO7hO8" + ) async with AsyncUserDB("tiktok_users.db") as audb: - local_user_path = await TiktokHandler(kwargs).get_or_add_user_data(sec_user_id, audb) + local_user_path = await TiktokHandler(kwargs).get_or_add_user_data( + sec_user_id, audb + ) print(local_user_path) # X:\......\Download\tiktok\post\vantoan___ @@ -53,7 +57,8 @@ async def main(): print(new_user_path) # X:\......\Download\tiktok\post\New Nickname + if __name__ == "__main__": asyncio.run(main()) -// #endregion rename-user-folder \ No newline at end of file +# endregion rename-user-folder diff --git a/docs/snippets/tiktok/user-mix.py b/docs/snippets/tiktok/user-mix.py index 81a881b..e058a3f 100644 --- a/docs/snippets/tiktok/user-mix.py +++ b/docs/snippets/tiktok/user-mix.py @@ -1,4 +1,4 @@ -// #region playlist-sinppet +# region playlist-sinppet import asyncio from f2.apps.tiktok.handler import TiktokHandler from f2.apps.tiktok.utils import SecUserIdFetcher @@ -28,12 +28,13 @@ async def main(): # print("=================_to_list===============") # print(aweme_data_list._to_list()) + if __name__ == "__main__": asyncio.run(main()) -// #endregion playlist-sinppet +# endregion playlist-sinppet -// #region select-playlist-sinppet +# region select-playlist-sinppet import asyncio from f2.apps.tiktok.handler import TiktokHandler @@ -53,9 +54,11 @@ async def main(): secUid = await SecUserIdFetcher.get_secuid("https://www.tiktok.com/@vantoan___") playlist = await TiktokHandler(kwargs).fetch_play_list(secUid) - selected_index = await TiktokHandler(kwargs).select_playlist(playlist) # [!code focus] - if selected_index != 0: # [!code focus] - mixId = playlist.get("mixId", [])[selected_index - 1] # [!code focus] + selected_index = await TiktokHandler(kwargs).select_playlist( + playlist + ) # [!code focus] + if selected_index != 0: # [!code focus] + mixId = playlist.get("mixId", [])[selected_index - 1] # [!code focus] async for aweme_data_list in TiktokHandler(kwargs).fetch_user_mix_videos(mixId): print(aweme_data_list._to_raw()) @@ -64,7 +67,8 @@ async def main(): # print("=================_to_list===============") # print(aweme_data_list._to_list()) + if __name__ == "__main__": asyncio.run(main()) -// #endregion select-playlist-sinppet \ No newline at end of file +# endregion select-playlist-sinppet diff --git a/docs/snippets/tiktok/xbogus.py b/docs/snippets/tiktok/xbogus.py index 69b0669..f97dc62 100644 --- a/docs/snippets/tiktok/xbogus.py +++ b/docs/snippets/tiktok/xbogus.py @@ -1,4 +1,4 @@ -// #region str-2-endpoint-snippet +# region str-2-endpoint-snippet # 使用接口地址直接生成请求链接 import asyncio from f2.apps.tiktok.utils import XBogusManager @@ -8,36 +8,40 @@ async def main(): test_endpoint = "aid=1988&app_language=zh-Hans&app_name=tiktok_web&browser_platform=Win32&browser_version=5.0%20%28Windows%20NT%2010.0%3B%20Win64%3B%20x64%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F120.0.0.0%20Safari%2F537.36&channel=tiktok_web&cookie_enabled=true&count=16&coverFormat=2&device_id=7306060721837852167&device_platform=web_pc&itemID=7294298719665622305" return XBogusManager.str_2_endpoint(test_endpoint) + if __name__ == "__main__": print(asyncio.run(main())) -// #endregion str-2-endpoint-snippet +# endregion str-2-endpoint-snippet -// #region model-2-endpoint-snippet +# region model-2-endpoint-snippet # 使用用户信息模型生成请求链接 import asyncio from f2.apps.tiktok.api import TiktokAPIEndpoints as tkendpoint from f2.apps.tiktok.model import UserProfile from f2.apps.tiktok.utils import XBogusManager + async def gen_user_profile(params: UserProfile): - return XBogusManager.model_2_endpoint( - tkendpoint.USER_DETAIL, params.model_dump() - ) + return XBogusManager.model_2_endpoint(tkendpoint.USER_DETAIL, params.model_dump()) + async def main(): - secUid="MS4wLjABAAAAQhcYf_TjRKUku-aF8oqngAfzrYksgGLRz8CKMciBFdfR54HQu3qGs-WoJ-KO7hO8" + secUid = ( + "MS4wLjABAAAAQhcYf_TjRKUku-aF8oqngAfzrYksgGLRz8CKMciBFdfR54HQu3qGs-WoJ-KO7hO8" + ) params = UserProfile(secUid=secUid) return await gen_user_profile(params) + if __name__ == "__main__": print(asyncio.run(main())) -// #endregion model-2-endpoint-snippet +# endregion model-2-endpoint-snippet -// #region model-2-endpoint-2-filter-snippet +# region model-2-endpoint-2-filter-snippet # 使用用户信息模型生成请求链接,请求接口并使用自定义过滤器输出所需接口数据 import asyncio from f2.apps.tiktok.api import TiktokAPIEndpoints as tkendpoint @@ -58,14 +62,15 @@ async def main(): async def main(): async with TiktokCrawler(kwargs) as crawler: - secUid="MS4wLjABAAAAQhcYf_TjRKUku-aF8oqngAfzrYksgGLRz8CKMciBFdfR54HQu3qGs-WoJ-KO7hO8" + secUid = "MS4wLjABAAAAQhcYf_TjRKUku-aF8oqngAfzrYksgGLRz8CKMciBFdfR54HQu3qGs-WoJ-KO7hO8" params = UserProfile(secUid=secUid) response = await crawler.fetch_user_profile(params) user = UserProfileFilter(response) # return user # user为UserProfileFilter对象,需要调用_to_dict()方法转为字典格式 return user._to_dict() + if __name__ == "__main__": print(asyncio.run(main())) -// #endregion model-2-endpoint-2-filter-snippet \ No newline at end of file +# endregion model-2-endpoint-2-filter-snippet diff --git a/f2/apps/douyin/utils.py b/f2/apps/douyin/utils.py index c088bb8..f5d244c 100644 --- a/f2/apps/douyin/utils.py +++ b/f2/apps/douyin/utils.py @@ -730,7 +730,9 @@ async def get_sec_user_id(cls, url: str) -> str: host = parsed_url.hostname if host is None: - raise APINotFoundError("无法解析URL的主机部分。类名:{0}".format(cls.__name__)) + raise APINotFoundError( + "无法解析URL的主机部分。类名:{0}".format(cls.__name__) + ) if "v.douyin.com" in host: pattern = cls._REDIRECT_URL_PATTERN