Spaces:
Running
Running
admin
commited on
Commit
·
97fe330
1
Parent(s):
2e5bead
add ignore
Browse files- .gitignore +3 -0
- app.py +24 -3
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
*__pycache__*
|
2 |
+
test.*
|
3 |
+
rename.sh
|
app.py
CHANGED
@@ -1,9 +1,29 @@
|
|
1 |
import os
|
2 |
import re
|
|
|
3 |
import requests
|
4 |
import gradio as gr
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def extract_fst_url(text):
|
8 |
url_pattern = r'(https?://[^\s"]+)'
|
9 |
match = re.search(url_pattern, text)
|
@@ -25,12 +45,13 @@ def infer(video_url):
|
|
25 |
return video, parse_time, desc, avatar, author, sign
|
26 |
|
27 |
try:
|
28 |
-
response = requests.get(
|
29 |
response_json = response.json()
|
30 |
retcode = response_json["code"]
|
31 |
if retcode == 200:
|
32 |
response_data = response_json["data"]
|
33 |
-
|
|
|
34 |
parse_time = response_data["parse_time"]
|
35 |
additional_data = response_data["additional_data"][0]
|
36 |
desc = additional_data["desc"]
|
@@ -58,7 +79,7 @@ if __name__ == "__main__":
|
|
58 |
),
|
59 |
],
|
60 |
outputs=[
|
61 |
-
gr.Video(label="Video download",
|
62 |
gr.Textbox(label="Parsing time", show_copy_button=True),
|
63 |
gr.Textbox(label="Video description", show_copy_button=True),
|
64 |
gr.Image(label="Author avatar", show_share_button=False),
|
|
|
1 |
import os
|
2 |
import re
|
3 |
+
import shutil
|
4 |
import requests
|
5 |
import gradio as gr
|
6 |
|
7 |
|
8 |
+
def download_file(url, video_id, cache_dir="./__pycache__"):
|
9 |
+
if os.path.exists(cache_dir):
|
10 |
+
shutil.rmtree(cache_dir)
|
11 |
+
|
12 |
+
os.makedirs(cache_dir)
|
13 |
+
local_file = f"{cache_dir}/{video_id}.mp4"
|
14 |
+
try:
|
15 |
+
response = requests.get(url, stream=True)
|
16 |
+
if response.status_code == 200:
|
17 |
+
with open(local_file, "wb") as file:
|
18 |
+
for chunk in response.iter_content(chunk_size=8192):
|
19 |
+
file.write(chunk)
|
20 |
+
|
21 |
+
except requests.exceptions.RequestException as e:
|
22 |
+
print(f"Failed to download: {e}")
|
23 |
+
|
24 |
+
return local_file
|
25 |
+
|
26 |
+
|
27 |
def extract_fst_url(text):
|
28 |
url_pattern = r'(https?://[^\s"]+)'
|
29 |
match = re.search(url_pattern, text)
|
|
|
45 |
return video, parse_time, desc, avatar, author, sign
|
46 |
|
47 |
try:
|
48 |
+
response = requests.get("https://api.xinyew.cn/api/douyinjx", params={"url": video_url})
|
49 |
response_json = response.json()
|
50 |
retcode = response_json["code"]
|
51 |
if retcode == 200:
|
52 |
response_data = response_json["data"]
|
53 |
+
video_id = response_data["play_url"].split("video_id=")[1].split("&")[0]
|
54 |
+
video = download_file(response_data["video_url"], video_id)
|
55 |
parse_time = response_data["parse_time"]
|
56 |
additional_data = response_data["additional_data"][0]
|
57 |
desc = additional_data["desc"]
|
|
|
79 |
),
|
80 |
],
|
81 |
outputs=[
|
82 |
+
gr.Video(label="Video download", show_download_button=True),
|
83 |
gr.Textbox(label="Parsing time", show_copy_button=True),
|
84 |
gr.Textbox(label="Video description", show_copy_button=True),
|
85 |
gr.Image(label="Author avatar", show_share_button=False),
|