randydev commited on
Commit
aebef05
1 Parent(s): f23a9bc

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -8
main.py CHANGED
@@ -195,15 +195,17 @@ async def youtube_api(payload: YouTubeBase):
195
  status="False",
196
  randydev={"error": url}
197
  )
 
198
  try:
 
199
  if payload.only_audio:
200
  with YoutubeDL(YoutubeDriver.song_options()) as ytdl:
201
  yt_data = ytdl.extract_info(url, download=True)
202
- yt_file = ytdl.prepare_filename(yt_data)
203
  ytdl.process_info(yt_data)
204
- time_second = time.time()
205
- with open(f"{yt_file}.mp3", "rb") as audio_file:
206
- encoded_string = base64.b64encode(audio_file.read())
207
  return SuccessResponse(
208
  status="True",
209
  randydev={
@@ -219,10 +221,10 @@ async def youtube_api(payload: YouTubeBase):
219
  else:
220
  with YoutubeDL(YoutubeDriver.video_options()) as ytdl:
221
  yt_data = ytdl.extract_info(url, download=True)
222
- yt_file = yt_data["id"]
223
- time_second = time.time()
224
- with open(f"{yt_file}.mp4", "rb") as video_file:
225
- encoded_string = base64.b64encode(video_file.read())
226
  return SuccessResponse(
227
  status="True",
228
  randydev={
 
195
  status="False",
196
  randydev={"error": url}
197
  )
198
+
199
  try:
200
+ time_second = time.time()
201
  if payload.only_audio:
202
  with YoutubeDL(YoutubeDriver.song_options()) as ytdl:
203
  yt_data = ytdl.extract_info(url, download=True)
204
+ yt_file = ytdl.prepare_filename(yt_data).replace('.webm', '.mp3')
205
  ytdl.process_info(yt_data)
206
+ with open(yt_file, "rb") as audio_file:
207
+ encoded_string = base64.b64encode(audio_file.read()).decode('utf-8')
208
+ os.remove(yt_file)
209
  return SuccessResponse(
210
  status="True",
211
  randydev={
 
221
  else:
222
  with YoutubeDL(YoutubeDriver.video_options()) as ytdl:
223
  yt_data = ytdl.extract_info(url, download=True)
224
+ yt_file = ytdl.prepare_filename(yt_data).replace('.webm', '.mp4')
225
+ with open(yt_file, "rb") as video_file:
226
+ encoded_string = base64.b64encode(video_file.read()).decode('utf-8')
227
+ os.remove(yt_file)
228
  return SuccessResponse(
229
  status="True",
230
  randydev={