基于Python增加抖音视频播放量的代码
一、思路
通过发送HTTP请求来实现这一功能。代码主要功能的简要介绍:
1. `get_ttwid`:这个函数用于获取`ttwid`,它是通过向字节跳动的接口发送POST请求,并从响应的cookie中提取`ttwid`值。
2. `get_web_id`:这个函数用于获取`web_id`,它是通过向某个API发送POST请求,并从响应中提取`web_id`。
3. `get_ms_token`:这个函数生成一个随机字符串,作为`ms_token`。
4. `get_ac_nonce`:这个函数用于获取`__ac_nonce`,它是通过向视频页面发送GET请求,并从响应的cookie中提取`__ac_nonce`。
5. `count_to_text` 和 `big_count_operation`:这两个函数用于执行一些位操作和字符编码,生成`ac_signature`的一部分。
6. `load_ac_signature`:这个函数用于生成`ac_signature`,它是通过一系列的位操作和编码操作,结合URL、时间戳、用户代理等信息生成的。
7. `get_trace_id`:这个函数生成一个UUID,用于追踪请求。
8. `do_add_view_count`:这个函数用于增加单个视频的播放次数。它通过构造一系列的请求参数和数据,向抖音的接口发送POST请求。
9. `add_view_count`:这个函数用于多次调用`do_add_view_count`函数,以增加指定次数的播放次数。
10. `parallel_add_view_count`:这个函数使用多线程来并行增加视频的播放次数,以提高效率。
11. 主函数部分:脚本首先要求用户输入抖音视频的链接和要增加的播放次数,然后调用`add_view_count`函数来执行增加播放次数的操作。
donate
如果该项目对您有帮助,欢迎微信打赏
三、源码
1、main.py
import json
import random
import sys
import time
import threading
from urllib.parse import urlparse, urlunparse
import requests
from fake_useragent import UserAgent
from CookieUtil import CookieUtil
def get_ttwid(user_agent):
headers = {
"User-Agent": user_agent,
"Content-Type": "application/json"
}
request_url = "https://ttwid.bytedance.com/ttwid/union/register/"
data = {
"aid": 2906,
"service": "douyin.com",
"unionHost": "https://ttwid.bytedance.com",
"needFid": "false",
"union": "true",
"fid": ""
}
data_str = json.dumps(data)
response = requests.post(request_url, data=data_str, headers=headers)
jsonObj = json.loads(response.text)
callback_url = jsonObj['redirect_url']
response = requests.get(callback_url, headers=headers)
status_code = response.status_code
if status_code == 200 and 'Set-Cookie' in response.headers:
cookie_dict = CookieUtil.cookies_from_headers(response.cookies)
if "ttwid" in co
作者:sh_moranliunian