pytube: [BUG][QUESTION] cannot download private video

Before creating an issue pytube 11.0.0 here

Describe the bug A clear and concise description of what the bug is.

I’m trying to download a private video which I can see as a logged in user.

I’m using the following command in Python3

YouTube(‘https://www.youtube.com/watch?v=RUFKT3N5ow8’, use_oauth=True).streams.first().download()

which yields

pytube.exceptions.VideoPrivate: RUFKT3N5ow8 is a private video

To Reproduce

from pytube import YouTube YouTube(‘https://www.youtube.com/watch?v=RUFKT3N5ow8’, use_oauth=True).streams.first().download()

Expected behavior I’m expecting some way to authenticate with Google and authorize the pytube client so I can download the video using my google account and pytube.

I was checking the code of innertube and I can see a place where the token file is supposed to be read if os.path.exists(_token_file):

and where self.fetch_bearer_token() call is made but I cannot figure out how to make it work for me.

I can see a place in def _call_api(self, endpoint, query, data):

where self.fetch_bearer_token() but I cannot see out of the code why fetch_bearer_token is not producing output it’s supposed to produce.

I’m happy to help extending the code to improve support if needed. Just need some guidance in the start.

Output Traceback (most recent call last): File “<stdin>”, line 1, in <module> File “/usr/local/lib/python3.9/site-packages/pytube/main.py”, line 284, in streams self.check_availability() File “/usr/local/lib/python3.9/site-packages/pytube/main.py”, line 217, in check_availability raise exceptions.VideoPrivate(video_id=self.video_id) pytube.exceptions.VideoPrivate: RUFKT3N5ow8 is a private video

System information Please provide the following information:

  • Python version (run python --version) $python3 --version Python 3.9.5

  • Pytube version (run print(pytube.__version__) in python) $ pytube --version pytube 11.0.0

  • Command used to install pytube pip3 install pytube

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 21 (1 by maintainers)

Most upvoted comments

I have managed to get this working but I had to uninstall pytube then install the branch with:

python -m pip install git+https://github.com/tfdahlin/pytube.git@fix/1097

then I had to apply a manual fix to cipher.py from:

https://github.com/pytube/pytube/issues/1243

then the following worked (had to interact with console output oauth the first time but it seems to cache):

test = pytube.YouTube(private_video_url, use_oauth=True)

test.streams.order_by(‘resolution’).desc().first().download(filename_prefix=“video_”)

but things do not seem to work from your 12.0 main branch can we get the private video fix and the fix to cipher.py from https://github.com/pytube/pytube/issues/1243 merged into the master branch so that I can use the latest version with these fixes pretty please

hi guys @tfdahlin great thanks for the fix. Will give it a try shortly.

In all sincerity, @89z was trying to help and asked me very good questions which helped us isolate the problem (in a sense that we got to a properly setup private test video which definitely didn’t work with pytube at the time of discussion).

I believe @89z could not solve the issue in the code, and recommended a solution which would actually solve my immediate problem of being unable to download a Private Video from CLI. When he mentioned his own solution there was also a clear remark that it’s not in Python.

@89z great thanks for the help! - I saw your mech repo when checking out your profile. Will give it a try as well. I’ve just been a fan of pytube for years though never used it API - just occasional CLI download. I feel sorry you’re leaving this repo because of sincerely trying to help me.

Try out the branch I just made, and let me know if it works for you: python3 -m pip install git@https://github.com/tfdahlin/pytube@fix/1097

It works for the private video I tested against, but would appreciate extra eyes. If it fixes your problem, I’ll merge it this weekend.

@sokol8 figured out the problem – before the OAuth implementation, I had some early checks to see if a video was unavailable that are no longer an accurate representation of our capabilities. I’ll fix that.