Skip to content

Commit

Permalink
📌新增生成ttwid #329
Browse files Browse the repository at this point in the history
目前版本请求必带参数
  • Loading branch information
Johnserf-Seed committed Feb 23, 2023
1 parent c940628 commit 1acf2e2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
13 changes: 12 additions & 1 deletion TikTokDownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def Find(string):
'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', string)
return url

def generate_ttwid() -> str:
"""生成请求必带的ttwid
param :None
return:ttwid
"""
url = '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}'
response = requests.request("POST", url, data=data)
# j = ttwid k = 1%7CfPx9ZM.....
for j, k in response.cookies.items():
return k

def main():
url = ""
Expand Down Expand Up @@ -108,7 +119,7 @@ def video_download(url, music, name):
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
'referer':'https://www.douyin.com/',
'Cookie': 'ttwid=1%7Ch5y5kqyWCBm-83nsJVded8JSFUBP6_6NqHUmPoZPbsk%7C1677073080%7Ca5a22c1959315d00a8d89cf1d088fb4de5720e45c262d53f389ec0f6373c8475;'
'Cookie': f'ttwid=ttwid={generate_ttwid()};'
}
r = requests.get(url=Find(url)[0])
key = re.findall('video/(\d+)?', str(r.url))[0]
Expand Down
14 changes: 13 additions & 1 deletion TikTokPic.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,24 @@ def generate_random_str(randomlength=16):
random_str += base_str[random.randint(0, length)]
return random_str

def generate_ttwid() -> str:
"""生成请求必带的ttwid
param :None
return:ttwid
"""
url = '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}'
response = requests.request("POST", url, data=data)
# j = ttwid k = 1%7CfPx9ZM.....
for j, k in response.cookies.items():
return k

# 下载图集
def pic_download(urlarg):
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
'referer':'https://www.douyin.com/',
'Cookie': 'ttwid=1%7Ch5y5kqyWCBm-83nsJVded8JSFUBP6_6NqHUmPoZPbsk%7C1677073080%7Ca5a22c1959315d00a8d89cf1d088fb4de5720e45c262d53f389ec0f6373c8475;'
'Cookie': f'ttwid=ttwid={generate_ttwid()};'
}
try:
r = requests.get(url=Find(urlarg)[0])
Expand Down
15 changes: 13 additions & 2 deletions Util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,23 @@ def generate_random_str(randomlength=16):
random_str += base_str[random.randint(0, length)]
return random_str

def generate_ttwid() -> str:
"""生成请求必带的ttwid
param :None
return:ttwid
"""
url = '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}'
response = requests.request("POST", url, data=data)
# j = ttwid k = 1%7CfPx9ZM.....
for j, k in response.cookies.items():
return k

headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
'referer':'https://www.douyin.com/',
# 获取用户数据失败就自行替换ttwid
'Cookie': f'msToken={generate_random_str(107)};ttwid=1%7ChVRQ5XD5O_yEYNm1icKvmSyggtCsR1x3BDbzVOkiPhs%7C1677072526%7C8029ae32b048ed3609bd99a653c4a7edc4ff7a15828cafb8bb6779e89bfef783;'
'Cookie': f'msToken={generate_random_str(107)};ttwid={generate_ttwid()};'
}


Expand Down Expand Up @@ -129,7 +140,7 @@ def reFind(strurl):
print("#" * 120)
print(
"""
TikTokTool V1.3.0.52
TikTokTool V1.3.0.53
使用说明:
1、本程序目前支持命令行调用和配置文件操作,GUI预览版本已经发布
2、命令行操作方法:1)将本程序路径添加到环境变量
Expand Down

0 comments on commit 1acf2e2

Please sign in to comment.