Rehman1603 commited on
Commit
d3998fd
·
verified ·
1 Parent(s): 8d727e0

Update Download_Video.py

Browse files
Files changed (1) hide show
  1. Download_Video.py +18 -6
Download_Video.py CHANGED
@@ -1,8 +1,20 @@
1
- import pytube
 
2
 
3
- def download_video(url):
4
- yt=pytube.YouTube(url)
5
- video_files=yt.streams.first()
6
- video_path=video_files.download()
7
- return video_path
 
 
 
 
 
 
 
 
 
 
 
8
 
 
1
+ from yt_dlp import YoutubeDL
2
+ import os
3
 
4
+ def download_video(url, download_dir=None):
5
+ try:
6
+ # Set download options
7
+ ydl_opts = {
8
+ 'format': 'best', # Download the best quality available
9
+ 'outtmpl': os.path.join(download_dir, '%(title)s.%(ext)s') if download_dir else '%(title)s.%(ext)s', # Save file with title as name
10
+ 'quiet': True, # Suppress output (set to False for debugging)
11
+ }
12
+
13
+ with YoutubeDL(ydl_opts) as ydl:
14
+ info_dict = ydl.extract_info(url, download=True) # Extract video info and download
15
+ video_path = ydl.prepare_filename(info_dict) # Get the path of the downloaded file
16
+ return video_path
17
+
18
+ except Exception as e:
19
+ return f"An error occurred: {e}"
20