Last active
May 23, 2020 11:54
-
-
Save kartikay-bagla/c529b944a376fb5822ef146bb99a0126 to your computer and use it in GitHub Desktop.
Downloads all videos in a YouTube playlist as audio files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pytube import YouTube, Playlist | |
import progressbar | |
pl = Playlist(url= "") # Enter YouTube playlist link here. | |
pl.populate_video_urls() | |
print("[INFO] Number of Links: {}".format(len(pl.video_urls))) | |
widgets = ["[INFO] Downloading Video: ", progressbar.Percentage(), " ", progressbar.Bar(), " ", progressbar.ETA()] | |
def progress_Check(stream = None, chunk = None, file_handle = None, remaining = None): | |
#Gets the percentage of the file that has been downloaded. | |
current_value = file_size - remaining | |
pbar.update(current_value) | |
for i, url in enumerate(pl.video_urls[:]): | |
flag = 0 | |
counter = 0 | |
while flag is 0: | |
try: | |
yt = YouTube(url= url, on_progress_callback=progress_Check) | |
print(i, yt.title) | |
type_vid = yt.streams.filter(only_audio= True, mime_type= "audio/mp4").first() | |
file_size = type_vid.filesize | |
pbar = progressbar.ProgressBar(maxval= file_size, widgets= widgets) | |
pbar = pbar.start() | |
type_vid.download() | |
flag= 1 | |
pbar.finish() | |
except ConnectionResetError: | |
counter += 1 | |
print("[INFO] Error Counter: {}".format(counter), end= " ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment