PierreHanna commited on
Commit
f95be78
β€’
1 Parent(s): 3b04551

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -7,21 +7,22 @@ import pickle
7
  import gradio as gr
8
  import numpy as np
9
  import faiss
10
- from pytube import YouTube
11
 
12
  embed_html1 = '<iframe width="560" height="315" src="https://www.youtube.com/embed/'
13
  embed_html2 = '" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
14
 
 
 
 
 
 
 
15
 
16
  def download_audio(id_video):
17
- video = YouTube(id_video,use_oauth=True, allow_oauth_cache=True)
18
  id = id_video.split("?v=")[-1][:11]
19
- print("ID youtube ", id)
20
- audio_streams = video.streams.filter(only_audio=True)
21
- audio_stream = audio_streams[0]
22
- audio_file = audio_stream.download()
23
- audio_parts = audio_file.split('/')[-1]
24
- audio_title = '.'.join(audio_parts.split('.')[:-1])
25
  embed_html_all = embed_html1 + id +embed_html2
26
  return audio_file, audio_file, embed_html_all
27
 
 
7
  import gradio as gr
8
  import numpy as np
9
  import faiss
10
+ import yt_dlp
11
 
12
  embed_html1 = '<iframe width="560" height="315" src="https://www.youtube.com/embed/'
13
  embed_html2 = '" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
14
 
15
+ def download_audio_(link):
16
+ with yt_dlp.YoutubeDL({'extract_audio': True, 'format': 'bestaudio', 'outtmpl': '%(title)s.mp3'}) as video:
17
+ info_dict = video.extract_info(link, download = True)
18
+ video_title = info_dict['title']
19
+ video.download(link)
20
+ return video_title
21
 
22
  def download_audio(id_video):
 
23
  id = id_video.split("?v=")[-1][:11]
24
+ audio_file = download_audio_(id_video)
25
+ audio_file = audio_file+'.mp3'
 
 
 
 
26
  embed_html_all = embed_html1 + id +embed_html2
27
  return audio_file, audio_file, embed_html_all
28