nickmuchi commited on
Commit
d4d965b
1 Parent(s): c0bba9c

Update functions.py

Browse files
Files changed (1) hide show
  1. functions.py +32 -20
functions.py CHANGED
@@ -96,31 +96,43 @@ def load_prompt():
96
 
97
  ###################### Functions #######################################################################################
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  @st.cache_data
100
  def get_yt_audio(url):
101
- temp_audio_file = os.path.join('output', 'audio')
102
-
103
- ydl_opts = {
104
- 'format': 'bestaudio/best',
105
- 'postprocessors': [{
106
- 'key': 'FFmpegExtractAudio',
107
- 'preferredcodec': 'mp3',
108
- 'preferredquality': '192',
109
- }],
110
- 'outtmpl': temp_audio_file,
111
- 'quiet': True,
112
- }
113
 
114
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
115
-
116
- info = ydl.extract_info(url, download=False)
117
- title = info.get('title', None)
118
- ydl.download([url])
119
 
120
- #with open(temp_audio_file+'.mp3', 'rb') as file:
121
- audio_file = os.path.join('output', 'audio.mp3')
 
122
 
123
- return audio_file, title
124
 
125
 
126
  @st.cache_resource
 
96
 
97
  ###################### Functions #######################################################################################
98
 
99
+ # @st.cache_data
100
+ # def get_yt_audio(url):
101
+ # temp_audio_file = os.path.join('output', 'audio')
102
+
103
+ # ydl_opts = {
104
+ # 'format': 'bestaudio/best',
105
+ # 'postprocessors': [{
106
+ # 'key': 'FFmpegExtractAudio',
107
+ # 'preferredcodec': 'mp3',
108
+ # 'preferredquality': '192',
109
+ # }],
110
+ # 'outtmpl': temp_audio_file,
111
+ # 'quiet': True,
112
+ # }
113
+
114
+ # with yt_dlp.YoutubeDL(ydl_opts) as ydl:
115
+
116
+ # info = ydl.extract_info(url, download=False)
117
+ # title = info.get('title', None)
118
+ # ydl.download([url])
119
+
120
+ # #with open(temp_audio_file+'.mp3', 'rb') as file:
121
+ # audio_file = os.path.join('output', 'audio.mp3')
122
+
123
+ # return audio_file, title
124
+
125
+
126
  @st.cache_data
127
  def get_yt_audio(url):
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
+ yt = YouTube(url)
 
 
 
 
130
 
131
+ # Get the first available audio stream and download it
132
+ audio_stream = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download()
133
+ title = audio_stream.split('\\')[-1].split('.')[0]
134
 
135
+ return audio_stream, title
136
 
137
 
138
  @st.cache_resource