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

Update Download_Video.py

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