mirror of
https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
synced 2025-04-22 12:05:13 +08:00
🧨 #3 Fix TikTok Parse
This commit is contained in:
parent
e52f234dcd
commit
6fa116b054
123
TikTok_EN.py
123
TikTok_EN.py
@ -2,7 +2,7 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
# @Author: https://github.com/Evil0ctal/
|
# @Author: https://github.com/Evil0ctal/
|
||||||
# @Time: 2021/11/06
|
# @Time: 2021/11/06
|
||||||
# @Update: 2022/01/01
|
# @Update: 2022/01/31
|
||||||
# @Function:
|
# @Function:
|
||||||
"""
|
"""
|
||||||
@Function:
|
@Function:
|
||||||
@ -55,6 +55,8 @@ def valid_check(kou_ling):
|
|||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return 'Please make sure that the input links are all valid Douyin/TikTok links!'
|
return 'Please make sure that the input links are all valid Douyin/TikTok links!'
|
||||||
|
elif kou_ling == 'wyn' or 'WYN':
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
return 'Douyin or TikTok share link is wrong!'
|
return 'Douyin or TikTok share link is wrong!'
|
||||||
|
|
||||||
@ -91,8 +93,8 @@ def loading(url_lists):
|
|||||||
set_scope('bar', position=3)
|
set_scope('bar', position=3)
|
||||||
with use_scope('bar'):
|
with use_scope('bar'):
|
||||||
put_processbar('bar')
|
put_processbar('bar')
|
||||||
for i in range(1, total_len):
|
for i in range(1, 4):
|
||||||
set_processbar('bar', i / (total_len - 1))
|
set_processbar('bar', i / 3)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
@ -161,14 +163,44 @@ def get_video_info(original_url):
|
|||||||
def get_video_info_tiktok(tiktok_url):
|
def get_video_info_tiktok(tiktok_url):
|
||||||
# Analyze TikTok video
|
# Analyze TikTok video
|
||||||
try:
|
try:
|
||||||
video_info = info_post(tiktok_url).video
|
tiktok_headers = {
|
||||||
# print(video_info)
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
||||||
|
"authority": "www.tiktok.com",
|
||||||
|
"Accept-Encoding": "gzip, deflate",
|
||||||
|
"Connection": "keep-alive",
|
||||||
|
"Host": "www.tiktok.com",
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/86.0.170 Chrome/80.0.3987.170 Safari/537.36",
|
||||||
|
}
|
||||||
|
html = requests.get(url=tiktok_url, headers=tiktok_headers)
|
||||||
|
res = re.search('<script id="sigi-persisted-data">(.*)</script><script', html.text).group(1)
|
||||||
|
resp = re.findall(r'^window\[\'SIGI_STATE\']=(.*)?;window', res)[0]
|
||||||
|
result = json.loads(resp)
|
||||||
|
author_id = result["ItemList"]["video"]["list"][0]
|
||||||
|
video_info = result["ItemModule"][author_id]
|
||||||
|
print("The author_id is: ", author_id)
|
||||||
|
print(video_info)
|
||||||
|
# The format is messy, please bear with it
|
||||||
return video_info
|
return video_info
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Exception capture
|
# Exception capture
|
||||||
error_do(e, 'get_video_info_tiktok')
|
error_do(e, 'get_video_info_tiktok')
|
||||||
|
|
||||||
|
|
||||||
|
@retry(stop_max_attempt_number=3)
|
||||||
|
def tiktok_nowm(tiktok_url):
|
||||||
|
# Use 3rd party API to get watermark-free video link (not guaranteed to be stable)
|
||||||
|
try:
|
||||||
|
api_url = "https://api.reiyuura.me/api/dl/tiktok?url="
|
||||||
|
no_water_mark = api_url + tiktok_url
|
||||||
|
res = requests.get(no_water_mark, headers=headers)
|
||||||
|
print(res)
|
||||||
|
result = json.loads(res.text)
|
||||||
|
nowm = result['result']['nowm']
|
||||||
|
return nowm
|
||||||
|
except Exception as e:
|
||||||
|
error_do(e, "tiktok_nwm")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api")
|
@app.route("/api")
|
||||||
def webapi():
|
def webapi():
|
||||||
# Create a Flask application to get POST parameters and return the results
|
# Create a Flask application to get POST parameters and return the results
|
||||||
@ -343,21 +375,24 @@ def put_tiktok_result(item):
|
|||||||
# Display TikTok results on the front end
|
# Display TikTok results on the front end
|
||||||
video_info = get_video_info_tiktok(item)
|
video_info = get_video_info_tiktok(item)
|
||||||
download_url = find_url(tikmate().get_media(item)[1].json)[0]
|
download_url = find_url(tikmate().get_media(item)[1].json)[0]
|
||||||
|
nowm = tiktok_nowm(item)
|
||||||
api_url = '/api?url=' + item
|
api_url = '/api?url=' + item
|
||||||
put_table([
|
put_table([
|
||||||
['type', 'content'],
|
['type', 'content'],
|
||||||
['Video direct link (with watermark): ', put_link('Click to open the video', video_info['video']['playAddr'], new_window=True)],
|
['video title: ', video_info['desc']],
|
||||||
['Video download (no watermark):', put_link('click to download', download_url, new_window=True)],
|
['Video direct link (with watermark): ', put_link('Click to open video', video_info['video']['playAddr'], new_window=True)],
|
||||||
['Video title: ', video_info['desc']],
|
['Video direct link (no watermark): ', put_link('Click to open video', nowm, new_window=True)],
|
||||||
['Author nickname: ', video_info['author']['nickname']],
|
['Video download (no watermark):', put_link('Click to download', download_url, new_window=True)],
|
||||||
['Author Douyin ID: ', video_info['author']['uniqueId']],
|
['audio(name-author):', video_info['music']['album'] + " - " + video_info['music']['authorName']],
|
||||||
['Author signature: ', video_info['author']['signature']],
|
['Music link:', put_link('Click to play', video_info['music']['playUrl'], new_window=True)],
|
||||||
|
['Author Nickname: ', video_info['author']],
|
||||||
|
['Author ID: ', video_info['authorId']],
|
||||||
['Number of fans: ', video_info['authorStats']['followerCount']],
|
['Number of fans: ', video_info['authorStats']['followerCount']],
|
||||||
['Follow others: ', video_info['authorStats']['followingCount']],
|
['Follow others amount: ', video_info['authorStats']['followingCount']],
|
||||||
['Total number of likes: ', video_info['authorStats']['heart']],
|
['Total likes get: ', video_info['authorStats']['heart']],
|
||||||
['Total video amount: ', video_info['authorStats']['videoCount']],
|
['Total videos: ', video_info['authorStats']['videoCount']],
|
||||||
['Original video link: ', put_link('Click to open the original video', item, new_window=True)],
|
['Original video link: ', put_link('Click to open the original video', item, new_window=True)],
|
||||||
['Current video API link: ', put_link('Click to browse API data', api_url, new_window=True)]
|
['Current Video API Link: ', put_link('Click to browse API data', api_url, new_window=True)]
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
@ -455,28 +490,42 @@ def main():
|
|||||||
placeholder=placeholder,
|
placeholder=placeholder,
|
||||||
position=0)
|
position=0)
|
||||||
if kou_ling:
|
if kou_ling:
|
||||||
url_lists = find_url(kou_ling)
|
if 'wyn' or 'WYN' in kou_ling:
|
||||||
# Analysis start time
|
with popup('For WYN💖'):
|
||||||
start = time.time()
|
put_text('常见朋友们发一些浪漫的文案。')
|
||||||
try:
|
put_text('我想,')
|
||||||
loading(url_lists)
|
put_text('浪慢的话我也会写,')
|
||||||
for url in url_lists:
|
put_text('但是让谁来听呢?')
|
||||||
if 'douyin.com' in url:
|
put_text('或者又能给谁看呢?')
|
||||||
put_result(url)
|
put_text('我想,')
|
||||||
else:
|
put_text('这大抵是安慰自己罢了...')
|
||||||
put_tiktok_result(url)
|
put_text('新年快乐🧨')
|
||||||
clear('bar')
|
put_text('2022/02/01')
|
||||||
# Analysis end time
|
put_text('-Evil0ctal')
|
||||||
end = time.time()
|
put_link('return to home page', '/')
|
||||||
put_html("<br><hr>")
|
else:
|
||||||
put_link('return to home page', '/')
|
url_lists = find_url(kou_ling)
|
||||||
put_text('Parsing is complete! time consuming: %.4fs' % (end - start))
|
# Analysis start time
|
||||||
except Exception as e:
|
start = time.time()
|
||||||
# 异常捕获
|
try:
|
||||||
clear('bar')
|
loading(url_lists)
|
||||||
error_do(e, 'main')
|
for url in url_lists:
|
||||||
end = time.time()
|
if 'douyin.com' in url:
|
||||||
put_text('Parsing is complete! time consuming: %.4fs' % (end - start))
|
put_result(url)
|
||||||
|
else:
|
||||||
|
put_tiktok_result(url)
|
||||||
|
clear('bar')
|
||||||
|
# Analysis end time
|
||||||
|
end = time.time()
|
||||||
|
put_html("<br><hr>")
|
||||||
|
put_link('return to home page', '/')
|
||||||
|
put_text('Parsing is complete! time consuming: %.4fs' % (end - start))
|
||||||
|
except Exception as e:
|
||||||
|
# exception catch
|
||||||
|
clear('bar')
|
||||||
|
error_do(e, 'main')
|
||||||
|
end = time.time()
|
||||||
|
put_text('Parsing is complete! time consuming: %.4fs' % (end - start))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user