Spaces:
Running
Running
import os | |
import re | |
import requests | |
import gradio as gr | |
def extract_fst_url(text): | |
url_pattern = r'(https?://[^\s"]+)' | |
match = re.search(url_pattern, text) | |
if match: | |
return match.group(1) | |
else: | |
return None | |
def infer(video_url): | |
video, parse_time, desc, avatar, author, sign = None, None, None, None, None, None | |
if not video_url: | |
desc = "The video sharing link is empty!" | |
return video, parse_time, desc, avatar, author, sign | |
video_url = extract_fst_url(video_url) | |
if not video_url: | |
desc = "Please enter a valid video sharing link!" | |
return video, parse_time, desc, avatar, author, sign | |
try: | |
response = requests.get( | |
os.getenv("api"), | |
params={"url": video_url}, | |
) | |
response_json = response.json() | |
retcode = response_json["code"] | |
if retcode == 200: | |
response_data = response_json["data"] | |
video = response_data["play_url"] | |
parse_time = response_data["parse_time"] | |
additional_data = response_data["additional_data"][0] | |
desc = additional_data["desc"] | |
avatar = additional_data["url"].split("?from=")[0] | |
author = additional_data["nickname"] | |
sign = additional_data["signature"] | |
else: | |
desc = f"Interface call failed, error code: HTTP {retcode}" | |
except Exception as e: | |
desc = f"Video parsing failed, error code: {e}" | |
return video, parse_time, desc, avatar, author, sign | |
if __name__ == "__main__": | |
gr.Interface( | |
fn=infer, | |
inputs=[ | |
gr.Textbox( | |
label="Please enter TikTok video sharing short link", | |
placeholder="https://v.douyin.com/*", | |
show_copy_button=True, | |
), | |
], | |
outputs=[ | |
gr.Video(label="Video download", show_download_button=True), | |
gr.Textbox(label="Parsing time", show_copy_button=True), | |
gr.Textbox(label="Video description", show_copy_button=True), | |
gr.Image(label="Author avatar", show_share_button=True), | |
gr.Textbox(label="Author nickname", show_copy_button=True), | |
gr.TextArea(label="Author signature", show_copy_button=True), | |
], | |
title="Parse TikTok video without watermark", | |
description="This site does not provide any video storage services, only to provide the most basic resolution services", | |
flagging_mode="never", | |
examples=[ | |
"https://v.douyin.com/iUsp2kWc", | |
"5.17 06/17 [email protected] OXM:/ MC——创世! 密码的 这咋玩?# 我的世界 # 我的世界极限生存 # 冰℃ https://v.douyin.com/i5MXfJac/ 复制此链接,打开Dou音搜索,直接观看视频!", | |
], | |
cache_examples=False, | |
).launch() | |