Spaces:
Sleeping
Sleeping
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
Browse files
app.py
CHANGED
|
@@ -658,13 +658,22 @@ def download_youtube_video(youtube_id, output_path=OUTPUT_PATH):
|
|
| 658 |
# Create the output directory if it doesn't exist
|
| 659 |
if not os.path.exists(output_path):
|
| 660 |
os.makedirs(output_path)
|
| 661 |
-
|
| 662 |
# Download the video
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 666 |
|
| 667 |
-
|
| 668 |
|
| 669 |
def screenshot_youtube_video(youtube_id, snapshot_sec):
|
| 670 |
video_path = f'{OUTPUT_PATH}/{youtube_id}.mp4'
|
|
|
|
| 658 |
# Create the output directory if it doesn't exist
|
| 659 |
if not os.path.exists(output_path):
|
| 660 |
os.makedirs(output_path)
|
| 661 |
+
|
| 662 |
# Download the video
|
| 663 |
+
try:
|
| 664 |
+
yt = YouTube(youtube_url)
|
| 665 |
+
video_stream = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
|
| 666 |
+
video_stream.download(output_path=output_path, filename=youtube_id+".mp4")
|
| 667 |
+
print(f"[Pytube] Video downloaded successfully: {output_path}/{youtube_id}.mp4")
|
| 668 |
+
except Exception as e:
|
| 669 |
+
ydl_opts = {
|
| 670 |
+
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', # This ensures the best quality combining video and audio
|
| 671 |
+
'outtmpl': os.path.join(output_path, f'{youtube_id}.mp4'), # Output filename template
|
| 672 |
+
}
|
| 673 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 674 |
+
ydl.download([youtube_url])
|
| 675 |
|
| 676 |
+
print(f"[yt_dlp] Video downloaded successfully: {output_path}/{youtube_id}.mp4")
|
| 677 |
|
| 678 |
def screenshot_youtube_video(youtube_id, snapshot_sec):
|
| 679 |
video_path = f'{OUTPUT_PATH}/{youtube_id}.mp4'
|