-
Notifications
You must be signed in to change notification settings - Fork 0
/
pytubeDownloader.py
25 lines (25 loc) · 1.39 KB
/
pytubeDownloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from pytube import YouTube
defaultLink = 'https://www.youtube.com/watch?v=o4TbVaIk40Q'
def DownloadVidAndAudio(link = defaultLink, outputFilename = None):
youtubeObject = YouTube(link)
if outputFilename is None:
outputFilename = 'VIDEO AND AUDIO ' + youtubeObject.streams[0].title
youtubeObject = youtubeObject.streams.get_highest_resolution()
youtubeObject.download(filename=outputFilename, output_path='Downloads')
print("Download is completed successfully")
def DownloadOnlyAudio(link = defaultLink, outputFilename = None):
youtubeObject = YouTube(link)
if outputFilename is None:
outputFilename = 'AUDIO ONLY ' + youtubeObject.streams[0].title
youtubeObject = youtubeObject.streams.filter(only_audio=True)
youtubeObject[0].download(filename = outputFilename, output_path='Downloads')
print("Download is completed successfully")
def DownloadOnlyVideo(link = defaultLink, outputFilename = None):
youtubeObject = YouTube(link)
if outputFilename is None:
outputFilename = 'VIDEO ONLY ' + youtubeObject.streams[0].title
elif outputFilename.split('.')[len(outputFilename.split('.'))-1] != 'mp4':
outputFilename = outputFilename.split('.')[0] + '.mp4'
youtubeObject = youtubeObject.streams.filter(only_video=True)
youtubeObject[0].download(filename=outputFilename, output_path='Downloads')
print("Download is completed successfully")