'Python library to dl youtube videos with highest resolution in colab

I want to be download videos in 1080p/720p etc fast in google colab. so I found the pytube but apparently it doesn't support 1080p vids.

from pytube import YouTube
link = "    https://www.youtube.com/watch?v=Dv91YPlFmQA       ".replace(' ','')

yt = YouTube(link)  

print(yt.streams.get_highest_resolution())

max quality here is 720p but the video has 1080p and btw the downloading speed was very high and can download 2GB videos in secs.

so I tried

youtube_dl_options = {
    "format": "mp4[height=1080]", # This will select the specific resolution typed here
    "outtmpl":'/content/drive/MyDrive/' +"%(title)s-%(id)s.%(ext)s",
    "restrictfilenames": True,
    "nooverwrites": True,
    "writedescription": True,
    "writeinfojson": True,
    "writeannotations": True,
    "writethumbnail": True,
    "writesubtitles": True,
    "writeautomaticsub": True
}
from __future__ import unicode_literals
import youtube_dl
link = "     https://www.youtube.com/watch?v=Dv91YPlFmQA     ".replace(' ','')
downloadLinks = [link]

with youtube_dl.YoutubeDL(youtube_dl_options) as ydl:
    ydl.download(downloadLinks)

it has 1080p but its downloading speed is super low like 70KB/s, so is there any other library to download youtube vids at a better speed with 1080p resolution.

so if u know a way that I can dl 1080p with pytube (ofc with audio) in colab, or anyway to make youtube-dl faster or any other way that can provide this functionalities please let me know.



Solution 1:[1]

The highest resolution for combined audio and video is 720p.

YouTube streaming data contains higher resolution videos, but they do not contain audio. These videos are DASH (Dynamic Adaptive Stream over HTTP), ie, individual stream of video only data, or audio only data.

You could use other library like ffmpeg to merge the audio and video streams to get higher resolution files. I have done it in my notebook, please have a look and see if the code is useful to you:

https://github.com/JNYH/pytube/blob/master/pytube_sample_code.ipynb

Bonus: I have also included OAuth log in (use_oauth=True, allow_oauth_cache=True) to access age-restricted videos and private videos (with given access).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Black Raven