Skip to content

Commit

Permalink
docs: 更新douyin代码片段 (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnserf-Seed committed Dec 1, 2024
1 parent 41114ce commit 4ef4327
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 87 deletions.
17 changes: 0 additions & 17 deletions docs/guide/apps/douyin/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,23 +669,6 @@ outline: deep

<<< @/snippets/douyin/webcast-signature.py#webcast-signature-snippet{4-8}

### 使用接口模型生成直播wss签名参数 🟢

类方法,用于使用不同接口数据模型生成直播wss签名参数。

| 参数 | 类型 | 说明 |
| :--- | :--- | :--- |
| user_agent | str | 用户代理 |
| base_endpoint | str | 端点 |
| params | dict | 请求参数 |

| 返回 | 类型 | 说明 |
| :--- | :--- | :--- |
| final_endpoint | str | 带wss签名参数的完整地址 |

<<< @/snippets/douyin/webcast-signature.py#webcast-signature-manager-snippet{10-14}


### 使用接口地址生成Xb参数 🟢

类方法,用于直接使用接口地址生成Xbogus参数,部分接口不校验。
Expand Down
1 change: 0 additions & 1 deletion docs/snippets/douyin/abogus.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ async def main():
# region model-2-endpoint-2-filter-snippet
# 使用用户信息模型生成请求链接,请求接口并使用自定义过滤器输出所需接口数据
import asyncio
from f2.apps.douyin.api import DouyinAPIEndpoints as dyendpoint
from f2.apps.douyin.crawler import DouyinCrawler
from f2.apps.douyin.model import UserProfile
from f2.apps.douyin.filter import UserProfileFilter
Expand Down
22 changes: 13 additions & 9 deletions docs/snippets/douyin/aweme-related.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@


async def main():
video = await DouyinHandler(kwargs).fetch_related_videos(
aweme_id="7294994585925848359"
)
print("=================_to_raw================")
print(video._to_raw())
# print("=================_to_dict================")
# print(video._to_dict())
# print("=================_to_list================")
# print(video._to_list())

async for related_list in DouyinHandler(kwargs).fetch_related_videos(
aweme_id="7294994585925848359",
filterGids="",
page_counts=20,
max_counts=20,
):
print("=================_to_raw================")
print(related_list._to_raw())
# print("=================_to_dict================")
# print(related_list._to_dict())
# print("=================_to_list================")
# print(related_list._to_list())


if __name__ == "__main__":
Expand Down
7 changes: 0 additions & 7 deletions docs/snippets/douyin/format-file-name.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ async def main():
format_file_name(kwargs.get("naming"), aweme_data._to_dict(), custom_fields)
+ "_video"
)
# 格式化后的自定义文件名,长度限制在100
print(
format_file_name(
kwargs.get("naming"), aweme_data._to_dict(), custom_fields, 100
)
+ "_video"
)


if __name__ == "__main__":
Expand Down
8 changes: 5 additions & 3 deletions docs/snippets/douyin/post-stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

async def main():
success_count, faild_count = 0, 0
aweme_id = "7436713470965468474"

for i in range(10000):
logger.info(f"第 {i+1} 次请求")
stats = await DouyinHandler(kwargs).fetch_post_stats(
aweme_id="7436713470965468474", aweme_type=68
aweme_id=aweme_id, aweme_type=68
)
if stats.status_code == 0:
success_count += 1
Expand All @@ -29,7 +29,9 @@ async def main():
faild_count += 1
logger.warning(stats.status_msg)

logger.info(f"播放量增加成功 {success_count} 次,失败 {faild_count} 次")
logger.info(
f"第 {i+1} 次请求,播放量增加成功 {success_count} 次,失败 {faild_count} 次"
)
# await asyncio.sleep(1)


Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/douyin/show-qrcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

if __name__ == "__main__":
show_qrcode("https://baidu.com/")
show_qrcode("https://baidu.com/", True)
# pip install pillow
# show_qrcode("https://baidu.com/", True)
16 changes: 8 additions & 8 deletions docs/snippets/douyin/user-collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@


async def main():
async for music_data_list in DouyinHandler(kwargs).fetch_user_music_collection():
async for music_list in DouyinHandler(kwargs).fetch_user_music_collection():
print("=================_to_raw================")
print(music_data_list._to_raw())
print(music_list._to_raw())
# print("=================_to_dict===============")
# print(music_data_list._to_dict())
# print(music_list._to_dict())
# print("=================_to_list===============")
# print(music_data_list._to_list())
# print(music_list._to_list())


if __name__ == "__main__":
Expand All @@ -46,13 +46,13 @@ async def main():


async def main():
async for aweme_data_list in DouyinHandler(kwargs).fetch_user_collection_videos():
async for collection_list in DouyinHandler(kwargs).fetch_user_collection_videos():
print("=================_to_raw================")
print(aweme_data_list._to_raw())
print(collection_list._to_raw())
# print("=================_to_dict===============")
# print(aweme_data_list._to_dict())
# print(collection_list._to_dict())
# print("=================_to_list===============")
# print(aweme_data_list._to_list())
# print(collection_list._to_list())


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions docs/snippets/douyin/user-collects.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ async def main():

async def main():
collects_id = "" # 收藏夹ID
async for aweme_data_list in DouyinHandler(kwargs).fetch_user_collects_videos(
async for collects_list in DouyinHandler(kwargs).fetch_user_collects_videos(
collects_id, 0, 10, 20
):
print("=================_to_raw================")
print(aweme_data_list._to_raw())
print(collects_list._to_raw())
# print("=================_to_dict===============")
# print(aweme_data_list._to_dict())
# print(collects_list._to_dict())
# print("=================_to_list===============")
# print(aweme_data_list._to_list())
# print(collects_list._to_list())


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/douyin/user-follow-live.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


async def main():
follow_live = await DouyinHandler(kwargs).fetch_following_live()
follow_live = await DouyinHandler(kwargs).fetch_user_following_lives()
print("=================_to_raw================")
print(follow_live._to_raw())
# print("=================_to_dict===============")
Expand Down
6 changes: 4 additions & 2 deletions docs/snippets/douyin/user-follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ async def main():
# min_time=0,
):
if follower.status_code != 0:
logger.error("错误代码:{0} 错误消息:{1}").format(
follower.status_code, follower.status_msg
logger.error(
"错误代码:{0} 错误消息:{1}".format(
follower.status_code, follower.status_msg
)
)
else:
logger.info(
Expand Down
6 changes: 4 additions & 2 deletions docs/snippets/douyin/user-following.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ async def main():
# min_time=0,
):
if following.status_code != 0:
logger.error("错误代码:{0} 错误消息:{1}").format(
following.status_code, following.status_msg
logger.error(
"错误代码:{0} 错误消息:{1}".format(
following.status_code, following.status_msg
)
)
else:
logger.info(
Expand Down
17 changes: 10 additions & 7 deletions docs/snippets/douyin/user-friend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@


async def main():
friend_video_list = await DouyinHandler(kwargs).fetch_friend_feed_videos()
print("=================_to_raw================")
print(friend_video_list._to_raw())
# print("=================_to_dict===============")
# print(friend_video_list._to_dict())
# print("=================_to_list===============")
# print(friend_video_list._to_list())

async for friend_list in DouyinHandler(kwargs).fetch_friend_feed_videos(
cursor=0, level=1, pull_type=0, max_counts=20
):
print("=================_to_raw================")
print(friend_list._to_raw())
# print("=================_to_dict===============")
# print(friend_list._to_dict())
# print("=================_to_list===============")
# print(friend_list._to_list())


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/douyin/user-like.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.douyin.com/",
},
"cookie": "YOUR_COOKIE_HERE",
"timeout": 10,
"proxies": {"http://": None, "https://": None},
"cookie": "YOUR_COOKIE_HERE",
}


Expand Down
24 changes: 0 additions & 24 deletions docs/snippets/douyin/webcast-signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,3 @@
print(signature)

# endregion webcast-signature-snippet


# region webcast-signature-manager-snippet
# fetch_live_danmaku

import asyncio
from f2.apps.douyin.api import DouyinAPIEndpoints as dyendpoint
from f2.apps.douyin.model import LiveWebcast
from f2.apps.douyin.utils import WebcastSignatureManager, ClientConfManager


async def main(params: LiveWebcast):
final_endpoint = WebcastSignatureManager.model_2_endpoint(
user_agent=ClientConfManager.user_agent(),
base_endpoint=dyendpoint.LIVE_IM_WSS,
params=params.model_dump(),
)
return final_endpoint


if __name__ == "__main__":
print(asyncio.run(main()))

# endregion webcast-signature-manager-snippet

0 comments on commit 4ef4327

Please sign in to comment.