JuanBindez / pytubefix

Python3 library for downloading YouTube Videos.
http://pytubefix.rtfd.io/
MIT License
674 stars 95 forks source link

Downloading some videos like Taylor Swift's will raise 403 Forbidden #148

Closed matthewcamilizer closed 3 months ago

matthewcamilizer commented 3 months ago

I don't know if downloading this video is Premium only? But it looks like premium videos cannot be downloaded through the package?

from pytubefix import YouTube from pytubefix.cli import on_progress

Cruel Summer official video

url = "https://youtu.be/ic8j13piAhQ"

yt = YouTube(url, on_progress_callback = on_progress)

ys = yt.streams.get_highest_resolution() ys.download()

File "d:\Games\MS\1.py", line 10, in ys.download() File "D:\Python 3.10\lib\site-packages\pytubefix\streams.py", line 325, in download bytes_remaining = self.filesize File "D:\Python 3.10\lib\site-packages\pytubefix\streams.py", line 171, in filesize self._filesize = request.filesize(self.url) File "D:\Python 3.10\lib\site-packages\pytubefix\request.py", line 204, in filesize return int(head(url)["content-length"]) File "D:\Python 3.10\lib\site-packages\pytubefix\request.py", line 268, in head response_headers = _execute_request(url, method="HEAD").info() File "D:\Python 3.10\lib\site-packages\pytubefix\request.py", line 35, in _execute_request
return urlopen(request, timeout=timeout) # nosec File "D:\Python 3.10\lib\urllib\request.py", line 216, in urlopen return opener.open(url, data, timeout) File "D:\Python 3.10\lib\urllib\request.py", line 525, in open response = meth(req, response) File "D:\Python 3.10\lib\urllib\request.py", line 634, in http_response response = self.parent.error( File "D:\Python 3.10\lib\urllib\request.py", line 563, in error return self._call_chain(args) File "D:\Python 3.10\lib\urllib\request.py", line 496, in _call_chain result = func(args) File "D:\Python 3.10\lib\urllib\request.py", line 643, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 403: Forbidden

JuanBindez commented 3 months ago

update to latest version and test

matthewcamilizer commented 3 months ago

update to latest version and test

Same issue. After I tried other videos which can be downloaded, I noticed their download URLs serve with different ways. These URLs allow users to access video file through it, while URLs of videos like Taylor Swift's do not allow users to access video file through it. Maybe Google added other authorizations to these videos.

You can use this snippet to output download URL

url = input("> ")

yt = YouTube(url, on_progress_callback = on_progress)

ys = yt.streams.get_highest_resolution() print(ys.url)

issue

JuanBindez commented 3 months ago

It worked perfectly for me here

>>> from pytubefix import YouTube
>>> from pytubefix.cli import on_progress
>>> 
>>> 
>>> url = 'https://youtu.be/ic8j13piAhQ'
>>> 
>>> yt = YouTube(url, on_progress_callback = on_progress)
>>> 
>>> ys = yt.streams.get_highest_resolution()
>>> print(ys.url)
https://rr5---sn-bg0s7n76.googlevideo.com/videoplayback?expire=1722470501&ei=BXyqZoenOcGcobIPnJXwCA&ip=2804%3A1458%3Aa8%3A0%3Ab6da%3Abbb1%3Ad735%3A77db&id=o-AK4vLEpdBLSVSgsVGJKv-564q5uJzfDAR0B6MKF771rF&itag=18&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&mh=LH&mm=31%2C26&mn=sn-bg0s7n76%2Csn-gpv7knee&ms=au%2Conr&mv=m&mvi=5&pl=32&gcr=br&vprv=1&svpuc=1&xtags=heaudio%3Dtrue&mime=video%2Fmp4&rqh=1&cnr=14&ratebypass=yes&dur=179.536&lmt=1706322589844493&mt=1722448397&fvip=3&c=ANDROID_TESTSUITE&txp=4530434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cgcr%2Cvprv%2Csvpuc%2Cxtags%2Cmime%2Crqh%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AJfQdSswRQIgUcftuIB6PykUgPB2AV2CkiWjtfiQ2Oi0t97yvUUcvc4CIQCbaOWsQCG3ViqwUvVWc-6uqL94UNwkKj1WZFo5TNM2qA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl&lsig=AGtxev0wRQIgV2RlnysHk_gGDrwHxc2MAIaglF1h_TdmnYJUL2Bbw9ECIQC9fuT9l2DRIcZjHLI0msXL1DX8UuolU8muZinp_TcqMA%3D%3D
>>> 

image

NannoSilver commented 3 months ago

It is working fine at my ending too, with pytubefix 6.8.1.

I tested with this code:

from pytubefix import YouTube

url = "https://www.youtube.com/watch?v=ic8j13piAhQ" # TS

yt = YouTube(url)

ys = yt.streams.get_highest_resolution()
print(ys.url)
NannoSilver commented 3 months ago

update to latest version and test

Same issue. After I tried other videos which can be downloaded, I noticed their download URLs serve with different ways. These URLs allow users to access video file through it, while URLs of videos like Taylor Swift's do not allow users to access video file through it. Maybe Google added other authorizations to these videos.

You can use this snippet to output download URL

url = input("> ")

yt = YouTube(url, on_progress_callback = on_progress)

ys = yt.streams.get_highest_resolution() print(ys.url)

issue

Try with a VPN to change your IP

matthewcamilizer commented 3 months ago

update to latest version and test

Same issue. After I tried other videos which can be downloaded, I noticed their download URLs serve with different ways. These URLs allow users to access video file through it, while URLs of videos like Taylor Swift's do not allow users to access video file through it. Maybe Google added other authorizations to these videos. You can use this snippet to output download URL url = input("> ") yt = YouTube(url, on_progress_callback = on_progress) ys = yt.streams.get_highest_resolution() print(ys.url) issue

Try with a VPN to change your IP

Thanks. I did it with a different IP. Maybe my original IP is not allowed for some URLs.