Created
September 16, 2019 18:04
-
-
Save tvdsluijs/466bab8dc7b5d0170bb31e98c4dfe5d5 to your computer and use it in GitHub Desktop.
For downloading one or multiple youtube video's
This file contains 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
""" | |
Author : Theo van der Sluijs | |
License: MIT | |
Version: 1.0 | |
V-Date: 16 sept 2019 | |
email: theo@vandersluijs.nl | |
installation: | |
create a folder called : youtube | |
install pytube: pip install pytube | |
run: python downtube.puy | |
just add one or multiple youtube id's | |
(multiple comma separated) | |
Have fun! | |
https://www.buymeacoffee.com/itheo | |
""" | |
from pytube import YouTube | |
import sys | |
import os | |
class DownTube: | |
def __init__(self, folder: str = None): | |
self.folder = folder | |
self.what_folder() | |
self.download() | |
def youtube_list(self, youtube_ids): | |
return youtube_ids.split(',') | |
def what_folder(self): | |
if self.folder is not None: | |
cp = os.getcwd() | |
folder = os.path.join(cp, self.folder) | |
os.makedirs(folder, exist_ok=True) | |
return True | |
while True: | |
self.folder = input("Where should I download : ") | |
if self.folder is not None and self.folder != "": | |
break | |
def download(self): | |
yes_now = ['y', 'n'] | |
while True: | |
you_tube = input("Give me the youtube id('s)): ") | |
if you_tube is not None and you_tube != "": | |
list = self.youtube_list(you_tube) | |
for l in list: | |
self.do_download(l) | |
more = "" | |
while more not in yes_now: | |
more = input("Download another one [y/n] ") | |
if more == 'n': | |
sys.exit() | |
print('all done') | |
def do_download(self, id: str = None): | |
try: | |
yt = YouTube(f"http://youtube.com/watch?v={id}") | |
yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(self.folder) | |
except Exception as e: | |
print(e) | |
if __name__ == '__main__': | |
dt = DownTube('youtube') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment