Pytube

https://github.com/pytube/pytube

 

GitHub - pytube/pytube: A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.

A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos. - GitHub - pytube/pytube: A lightweight, dependency-free Python library (and command-line ut...

github.com


How to use ?

from pytube import YouTube

url = 'https://youtu.be/2lAe1cqCOXo'

# 모든 정보 확인
yt = YouTube(url).streams
for k, v in yt.items():
	print(k, v)

# url 영상 다운
yt = YouTube(url)
yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download()Copy Icon

Error

1. raise RegexMatchError(caller="regex_search", pattern=pattern)

pytube.exceptions.RegexMatchError: regex_search: could not find match for (?:v=|\/)([0-9A-Za-z_-]{11}).*

https://github.com/pytube/pytube/pull/313#issuecomment-438175656

 

Fix of new signature deciphering by johnberroa · Pull Request #313 · pytube/pytube

#312 It seems a lot of people are getting this error because youtube changed its signature deciphering method (as pointed out by @anxdpanic). It's a hacky fix but it will get the program running:...

github.com

Solution

[python이 설치된 path]/[python 버전]/libs/site-packages/pytube/ciper.py 중 다음 line을 추가

r'\bc\s*&&\s*d\.set\([^,]+,.*?\((?P<sig>[a-zA-Z0-9$]+)\(\(0\s*,\s*window.decodeURIComponent' # addCopy Icon

욱근욱