ytD/downloader.py

34 lines
983 B
Python

from pytube import YouTube
import os
path = os.path.abspath(os.getcwd())
def DownloadMP3(url, destination):
yt = YouTube(url)
newpath = path + "/Downloads/Audio"
if len(destination)==0:
check = os.path.exists(newpath)
if not check:
os.makedirs(newpath)
destination = newpath
vid = yt.streams.filter(only_audio=True).first()
out_file = vid.download(output_path=destination)
n = os.path.splitext(out_file)
filename = n[0] + '.mp3'
os.rename(out_file, filename)
def DownloadMP4(url, quality, destination):
yt = YouTube(url)
newpath = path + "/Downloads/Video"
if len(destination)==0:
check = os.path.exists(newpath)
if not check:
os.makedirs(newpath)
destination = newpath
if quality == "MaxQ":
vid = yt.streams.get_highest_resolution()
else:
vid = yt.streams.filter(res=quality).first()
out_file = vid.download(output_path=destination)