Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
import yt_dlp
|
3 |
import os
|
4 |
-
import binascii
|
5 |
import json
|
6 |
|
7 |
-
def dl_user(inp):
|
8 |
-
out_json={}
|
9 |
-
os.system(f'yt-dlp "{inp}" --write-info-json --skip-download --cookies-from-browser chrome -o "{inp_out}"')
|
10 |
-
try:
|
11 |
-
with open(f"{inp_out}.info.json", "r") as f:
|
12 |
-
f_out = f.read()
|
13 |
-
print(f_out)
|
14 |
-
json_object = json.loads(f_out)
|
15 |
-
out_json = json.dumps(json_object, indent=4)
|
16 |
-
print (out_json)
|
17 |
-
except Exception as e:
|
18 |
-
print (e)
|
19 |
-
return out_json
|
20 |
def dl(inp):
|
21 |
out = None
|
22 |
out_file=[]
|
23 |
-
out_json={}
|
24 |
try:
|
25 |
inp_out=inp.replace("https://","")
|
26 |
inp_out=inp_out.replace("/","_").replace(".","_")
|
27 |
-
os.system(f'yt-dlp "{inp}" --write-description --skip-download -o "{inp_out}"')
|
28 |
-
os.system(f'yt-dlp "{inp}" --write-info-json --skip-download -o "{inp_out}"')
|
29 |
-
|
30 |
os.system(f'yt-dlp "{inp}" --trim-filenames 100 -o "{inp_out}.mp4"')
|
31 |
out = f"{inp_out}.mp4"
|
32 |
-
out_file.append(out)
|
33 |
-
out_file.append(f"{inp_out}.description")
|
34 |
-
out_file.append(f"{inp_out}.info.json")
|
35 |
-
out_json=f'{inp_out}.info.json'
|
36 |
try:
|
37 |
with open(f"{inp_out}.info.json", "r") as f:
|
38 |
-
|
39 |
f_out = f.read()
|
40 |
-
print(f_out)
|
41 |
-
#for line in f_out:
|
42 |
-
# print (line)
|
43 |
-
# json_line.append(line)
|
44 |
-
#dec_line = line.decode('utf-8', 'backslashreplace')
|
45 |
-
#out_line = binascii.hexlify(eval(dec_line))
|
46 |
-
#print (out_line)
|
47 |
json_object = json.loads(f_out)
|
48 |
out_json = json.dumps(json_object, indent=4)
|
49 |
-
print (out_json)
|
50 |
except Exception as e:
|
51 |
print (e)
|
52 |
except Exception as e:
|
53 |
print (e)
|
54 |
out = None
|
55 |
-
return out
|
56 |
-
|
57 |
|
58 |
with gr.Blocks() as app:
|
59 |
inp_url = gr.Textbox()
|
60 |
-
|
61 |
-
#btn=gr.Button("Search")
|
62 |
-
go_btn = gr.Button("Run")
|
63 |
-
|
64 |
with gr.Row():
|
65 |
with gr.Column():
|
66 |
outp_vid=gr.Video()
|
67 |
with gr.Column():
|
68 |
outp_files=gr.Files()
|
69 |
-
|
70 |
-
#btn.click(dl,inp_url,out_json)
|
71 |
-
go_btn.click(dl,inp_url,[outp_vid,outp_files,out_json])
|
72 |
|
73 |
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import yt_dlp
|
3 |
import os
|
|
|
4 |
import json
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def dl(inp):
|
7 |
out = None
|
8 |
out_file=[]
|
|
|
9 |
try:
|
10 |
inp_out=inp.replace("https://","")
|
11 |
inp_out=inp_out.replace("/","_").replace(".","_")
|
|
|
|
|
|
|
12 |
os.system(f'yt-dlp "{inp}" --trim-filenames 100 -o "{inp_out}.mp4"')
|
13 |
out = f"{inp_out}.mp4"
|
|
|
|
|
|
|
|
|
14 |
try:
|
15 |
with open(f"{inp_out}.info.json", "r") as f:
|
|
|
16 |
f_out = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
json_object = json.loads(f_out)
|
18 |
out_json = json.dumps(json_object, indent=4)
|
|
|
19 |
except Exception as e:
|
20 |
print (e)
|
21 |
except Exception as e:
|
22 |
print (e)
|
23 |
out = None
|
24 |
+
return out
|
|
|
25 |
|
26 |
with gr.Blocks() as app:
|
27 |
inp_url = gr.Textbox()
|
28 |
+
go_btn = gr.Button("Run")
|
|
|
|
|
|
|
29 |
with gr.Row():
|
30 |
with gr.Column():
|
31 |
outp_vid=gr.Video()
|
32 |
with gr.Column():
|
33 |
outp_files=gr.Files()
|
34 |
+
go_btn.click(dl,inp_url,outp_vid)
|
|
|
|
|
35 |
|
36 |
app.launch()
|