🌠修复了有时无法获取作者抖音ID的BUG
This commit is contained in:
parent
302284f939
commit
7849e734f2
1 changed files with 37 additions and 16 deletions
53
main.py
53
main.py
|
|
@ -6,8 +6,7 @@
|
||||||
# @Function:
|
# @Function:
|
||||||
# 基于 PyWebIO、Requests、Flask,可实现在线批量解析抖音的无水印视频/图集。
|
# 基于 PyWebIO、Requests、Flask,可实现在线批量解析抖音的无水印视频/图集。
|
||||||
# 可用于下载作者禁止下载的视频,同时可搭配iOS的快捷指令APP配合本项目API实现应用内下载。
|
# 可用于下载作者禁止下载的视频,同时可搭配iOS的快捷指令APP配合本项目API实现应用内下载。
|
||||||
|
from pywebio import config
|
||||||
|
|
||||||
from pywebio.input import *
|
from pywebio.input import *
|
||||||
from pywebio.output import *
|
from pywebio.output import *
|
||||||
from pywebio.platform.flask import webio_view
|
from pywebio.platform.flask import webio_view
|
||||||
|
|
@ -20,6 +19,8 @@ import json
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
title = "抖音在线解析"
|
||||||
|
description = "在线批量解析抖音的无水印视频/图集。"
|
||||||
headers = {'user-agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36 Edg/87.0.664.66'}
|
headers = {'user-agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36 Edg/87.0.664.66'}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -38,22 +39,35 @@ def valid_check(kou_ling):
|
||||||
|
|
||||||
|
|
||||||
def error_msg():
|
def error_msg():
|
||||||
|
# 输出一个毫无用处的信息
|
||||||
put_text("无法解析输入内容,请检查输入内容及网络,如多次尝试仍失败,请移步GitHub提交issue。")
|
put_text("无法解析输入内容,请检查输入内容及网络,如多次尝试仍失败,请移步GitHub提交issue。")
|
||||||
put_link('Github: Evil0ctal', 'https://github.com/Evil0ctal/')
|
put_link('Github: Evil0ctal', 'https://github.com/Evil0ctal/')
|
||||||
|
|
||||||
|
|
||||||
def error_log(e):
|
def error_log(e):
|
||||||
|
# 将错误记录在logs.txt中
|
||||||
date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||||
with open('log.txt', 'a') as f:
|
with open('logs.txt', 'a') as f:
|
||||||
f.write(date + ": " + str(e) + '\n')
|
f.write(date + ": " + str(e) + '\n')
|
||||||
|
|
||||||
|
|
||||||
|
def loading():
|
||||||
|
# 写一个进度条装装样子吧 :)
|
||||||
|
set_scope('bar', position=0)
|
||||||
|
with use_scope('bar'):
|
||||||
|
put_processbar('bar')
|
||||||
|
for i in range(1, 10):
|
||||||
|
set_processbar('bar', i / 9)
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
@retry(stop_max_attempt_number=3)
|
@retry(stop_max_attempt_number=3)
|
||||||
def get_video_info(url):
|
def get_video_info(url):
|
||||||
# 利用官方接口解析链接信息
|
# 利用官方接口解析链接信息
|
||||||
try:
|
try:
|
||||||
clean_url = find_url(url)[0]
|
# 原视频链接
|
||||||
r = requests.get(url=clean_url)
|
original_url = find_url(url)[0]
|
||||||
|
r = requests.get(url=original_url)
|
||||||
key = re.findall('video/(\d+)?', str(r.url))[0]
|
key = re.findall('video/(\d+)?', str(r.url))[0]
|
||||||
api_url = f'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={key}'
|
api_url = f'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={key}'
|
||||||
js = json.loads(requests.get(url=api_url, headers=headers).text)
|
js = json.loads(requests.get(url=api_url, headers=headers).text)
|
||||||
|
|
@ -67,9 +81,10 @@ def get_video_info(url):
|
||||||
# 图集作者昵称
|
# 图集作者昵称
|
||||||
image_author = str(js['item_list'][0]['author']['nickname'])
|
image_author = str(js['item_list'][0]['author']['nickname'])
|
||||||
# 图集作者抖音号
|
# 图集作者抖音号
|
||||||
image_author_id = str(js['item_list'][0]['author']['short_id'])
|
image_author_id = str(js['item_list'][0]['author']['unique_id'])
|
||||||
# 原视频链接
|
if image_author_id == "":
|
||||||
original_url = clean_url
|
# 如果作者未修改过抖音号,应使用此值以避免无法获取其抖音ID
|
||||||
|
image_author_id = str(js['item_list'][0]['author']['short_id'])
|
||||||
# 去水印图集链接
|
# 去水印图集链接
|
||||||
images_url = []
|
images_url = []
|
||||||
for data in image_data:
|
for data in image_data:
|
||||||
|
|
@ -88,8 +103,9 @@ def get_video_info(url):
|
||||||
video_author = str(js['item_list'][0]['author']['nickname'])
|
video_author = str(js['item_list'][0]['author']['nickname'])
|
||||||
# 视频作者抖音号
|
# 视频作者抖音号
|
||||||
video_author_id = str(js['item_list'][0]['author']['unique_id'])
|
video_author_id = str(js['item_list'][0]['author']['unique_id'])
|
||||||
# 原视频链接
|
if video_author_id == "":
|
||||||
original_url = clean_url
|
# 如果作者未修改过抖音号,应使用此值以避免无法获取其抖音ID
|
||||||
|
video_author_id = str(js['item_list'][0]['author']['short_id'])
|
||||||
# 返回包含数据的列表
|
# 返回包含数据的列表
|
||||||
video_info = [video_url, video_music, video_title, video_author, video_author_id, original_url]
|
video_info = [video_url, video_music, video_title, video_author, video_author_id, original_url]
|
||||||
return video_info, 'video'
|
return video_info, 'video'
|
||||||
|
|
@ -100,6 +116,7 @@ def get_video_info(url):
|
||||||
|
|
||||||
@app.route("/api")
|
@app.route("/api")
|
||||||
def webapi():
|
def webapi():
|
||||||
|
# 创建一个Flask应用获取POST参数并返回结果
|
||||||
try:
|
try:
|
||||||
post_content = request.args.get("url")
|
post_content = request.args.get("url")
|
||||||
if post_content:
|
if post_content:
|
||||||
|
|
@ -116,10 +133,12 @@ def webapi():
|
||||||
video_author_id=response_data[4], original_url=response_data[5])
|
video_author_id=response_data[4], original_url=response_data[5])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 异常捕获
|
# 异常捕获
|
||||||
return jsonify(Result=False, Message=str(e), Data=None)
|
error_log(e)
|
||||||
|
return jsonify(Message="解析失败", Reason=str(e), Result=False)
|
||||||
|
|
||||||
|
|
||||||
def put_result(item):
|
def put_result(item):
|
||||||
|
# 根据解析格式向前端输出表格
|
||||||
video_info, type = get_video_info(item)
|
video_info, type = get_video_info(item)
|
||||||
if type == 'video':
|
if type == 'video':
|
||||||
put_table([
|
put_table([
|
||||||
|
|
@ -150,25 +169,27 @@ def put_result(item):
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@config(title=title, description=description)
|
||||||
def main():
|
def main():
|
||||||
placeholder = "如需批量解析请使用英文逗号进行分隔! \n格式: 1.02 GIi:/电动车真环保吗? https://v.douyin.com/RATN1fk/ 复制此链接,打开Dou音搜索,直接观看视频!"
|
placeholder = "如需批量解析请使用英文逗号进行分隔! \n格式: 1.02 GIi:/电动车真环保吗? https://v.douyin.com/RATN1fk/ 复制此链接,打开Dou音搜索,直接观看视频!"
|
||||||
kou_ling = textarea('请将抖音分享的口令粘贴于此', type=TEXT, validate=valid_check, required=True, placeholder=placeholder)
|
kou_ling = textarea('请将抖音的分享口令或网址粘贴于此', type=TEXT, validate=valid_check, required=True, placeholder=placeholder)
|
||||||
try:
|
try:
|
||||||
|
loading()
|
||||||
if ',' in kou_ling:
|
if ',' in kou_ling:
|
||||||
kou_ling = kou_ling.split(',')
|
kou_ling = kou_ling.split(',')
|
||||||
for item in kou_ling:
|
for item in kou_ling:
|
||||||
put_result(item)
|
put_result(item)
|
||||||
|
clear('bar')
|
||||||
else:
|
else:
|
||||||
put_result(kou_ling)
|
put_result(kou_ling)
|
||||||
|
clear('bar')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 异常捕获
|
# 异常捕获
|
||||||
|
clear('bar')
|
||||||
error_msg()
|
error_msg()
|
||||||
error_log(e)
|
error_log(e)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 访问URL http://127.0.0.1:80/tiktok
|
app.add_url_rule('/', 'webio_view', webio_view(main), methods=['GET', 'POST', 'OPTIONS'])
|
||||||
# 访问API http://127.0.0.1:80/api?url=[抖音分享口令]
|
|
||||||
app.add_url_rule('/tiktok', 'webio_view', webio_view(main), methods=['GET', 'POST', 'OPTIONS'])
|
|
||||||
app.run(host='0.0.0.0', port=80)
|
app.run(host='0.0.0.0', port=80)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue