aichina commited on
Commit
11a2742
1 Parent(s): d1d903e

you-get 支持

Browse files
Files changed (1) hide show
  1. app.py +29 -5
app.py CHANGED
@@ -3,9 +3,31 @@ import gradio as gr
3
  from pytube import YouTube
4
  import random
5
  import requests,json
 
6
 
7
 
 
 
 
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
 
11
  def create(prompt,openai_key):
@@ -66,11 +88,12 @@ def convert(res,openai_key):
66
 
67
  def get_audio(url):
68
 
69
- yt = YouTube(url)
70
- audio_file = f'{random.randint(10000,100000)}.mp4'
71
- print(f'{url} {audio_file} start get audio ...')
72
- yt.streams.filter(only_audio=True)[0].download(filename=audio_file)
73
- print('aodio over ..')
 
74
  return audio_file
75
 
76
  def get_transcript(url,openai_key):
@@ -89,6 +112,7 @@ def get_transcript(url,openai_key):
89
  }
90
  response = requests.post('https://api.gladia.io/audio/text/audio-transcription/', headers=headers, files=files)
91
  print(response.text)
 
92
  return convert(response,openai_key)
93
 
94
 
 
3
  from pytube import YouTube
4
  import random
5
  import requests,json
6
+ import subprocess
7
 
8
 
9
+ def del_down_file():
10
+ command = f'rm -rf *.mp4'
11
+ subprocess.call(command, shell=True)
12
 
13
+ def get_video(url):
14
+
15
+
16
+ # 下载视频
17
+ url = url
18
+ output_dir = '.'
19
+ command = f'you-get -o {output_dir} {url}'
20
+ subprocess.call(command, shell=True)
21
+
22
+ mp4_files = [] # 用于存储所有找到的 mp4 文件名
23
+
24
+ # 遍历指定目录中的所有文件
25
+ for filename in os.listdir('.'):
26
+ # 检查文件是否以 '.mp4' 结尾
27
+ if filename.endswith('.mp4'):
28
+ # 如果是,将文件名添加到 mp4_files 列表中
29
+ mp4_files.append(filename)
30
+ return mp4_files[0]
31
 
32
 
33
  def create(prompt,openai_key):
 
88
 
89
  def get_audio(url):
90
 
91
+ # yt = YouTube(url)
92
+ # audio_file = f'{random.randint(10000,100000)}.mp4'
93
+ # print(f'{url} {audio_file} start get audio ...')
94
+ # yt.streams.filter(only_audio=True)[0].download(filename=audio_file)
95
+ # print('aodio over ..')
96
+ audio_file = get_video(url)
97
  return audio_file
98
 
99
  def get_transcript(url,openai_key):
 
112
  }
113
  response = requests.post('https://api.gladia.io/audio/text/audio-transcription/', headers=headers, files=files)
114
  print(response.text)
115
+ del_down_file()
116
  return convert(response,openai_key)
117
 
118