Initial commit
This commit is contained in:
37
programs/download youtube.py
Normal file
37
programs/download youtube.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import pytube
|
||||
|
||||
def get_video(url):
|
||||
print('----------------')
|
||||
print(f'Getting video {url}')
|
||||
youtube = pytube.YouTube(url)
|
||||
return youtube
|
||||
|
||||
def download_video(youtube, require_audio=False, resolution=None, ext='webm'):
|
||||
print(f'Found video {youtube.title}. Searching for streams...')
|
||||
streams = youtube.streams.filter(file_extension=ext)
|
||||
|
||||
# Filter resolution
|
||||
if resolution:
|
||||
streams = streams.filter(res=resolution)
|
||||
|
||||
# Filter audio
|
||||
if require_audio:
|
||||
streams = [x for x in streams if x.includes_audio_track]
|
||||
|
||||
if streams:
|
||||
stream = max(streams, key=lambda x: x.filesize)
|
||||
print(f'Found stream {stream}. Attempting download...')
|
||||
stream.download()
|
||||
print('Download complete')
|
||||
else:
|
||||
print('Failed to find stream')
|
||||
|
||||
|
||||
urls = [
|
||||
'https://www.youtube.com/watch?v=aChm3M8hZvo',
|
||||
'https://www.youtube.com/watch?v=x74OJ8A855Q',
|
||||
'https://www.youtube.com/watch?v=oNj8-yO0bWs'
|
||||
]
|
||||
for url in urls:
|
||||
yt = get_video(url)
|
||||
download_video(yt)
|
||||
Reference in New Issue
Block a user