Maximofn commited on
Commit
77d65f3
1 Parent(s): 8240f8e

Change to yt-dlp to download youtube videos

Browse files
Files changed (2) hide show
  1. download.py +4 -38
  2. requirements.txt +2 -1
download.py CHANGED
@@ -64,46 +64,12 @@ def download_twitch(url, type):
64
  os.system(f'rm {AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{args.format}')
65
 
66
  def download_youtube_video(url):
67
- yt = YouTube(url)
68
-
69
- # Get all video streams
70
- video_streams = yt.streams.filter(mime_type="video/mp4")
71
-
72
- # Get max resolution of video streams
73
- max_resolution = 0
74
- for stream in video_streams:
75
- if stream.audio_codec is not None:
76
- resolution = int(stream.resolution[:-1])
77
- if resolution > max_resolution:
78
- max_resolution = resolution
79
- max_resolution = f"{max_resolution}p"
80
-
81
- # Get stream with max resolution
82
- video_streams_max_resolution = video_streams.filter(resolution=max_resolution)
83
- for stream in video_streams_max_resolution:
84
- if stream.audio_codec is not None:
85
- video_stream = stream
86
-
87
- # Download video
88
- video_stream.download(filename=f'{VIDEO_FOLDER}/{DOWNLOAD_VIDEO_NAME}.{DOWNLOAD_VIDEO_FORMAT}')
89
 
90
  def download_youtube_audio(url):
91
- yt = YouTube(url)
92
-
93
- # Get all audio streams
94
- audio_streams = yt.streams.filter(mime_type="audio/mp4")
95
-
96
- # Get sorted list of audio bitrates
97
- abr_list = []
98
- for stream in audio_streams:
99
- abr_list.append(stream.abr)
100
- abr_list = sorted(set(abr_list))
101
-
102
- # Get stream with max audio bitrate
103
- audio_stream = audio_streams.filter(abr=abr_list[0]).first()
104
-
105
- # Download audio
106
- audio_stream.download(filename=f'{AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{DOWNLOAD_AUDIO_FORMAT}')
107
 
108
  def download_youtube(url, type):
109
  if type == DOWNLOAD_VIDEO:
 
64
  os.system(f'rm {AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{args.format}')
65
 
66
  def download_youtube_video(url):
67
+ command = f"yt-dlp -o '{VIDEO_FOLDER}/{DOWNLOAD_VIDEO_NAME}.{DOWNLOAD_VIDEO_FORMAT}' -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]' '{url}'"
68
+ os.system(command)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  def download_youtube_audio(url):
71
+ command = f"yt-dlp '{url}' -o '{AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{DOWNLOAD_AUDIO_FORMAT}' --extract-audio --audio-format mp3 --audio-quality 0"
72
+ os.system(command)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  def download_youtube(url, type):
75
  if type == DOWNLOAD_VIDEO:
requirements.txt CHANGED
@@ -2,7 +2,8 @@
2
  gradio
3
 
4
  # Download youtube and twitch videos
5
- pytube
 
6
  twitch-dl
7
 
8
  # # mossformer --> separate speech audios
 
2
  gradio
3
 
4
  # Download youtube and twitch videos
5
+ # pytube
6
+ yt-dlp
7
  twitch-dl
8
 
9
  # # mossformer --> separate speech audios