JuanBindez / pytubefix

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

70dcBUFysyo has age restrictions and cannot be accessed without confirmation. #185

Open jinhang87 opened 4 weeks ago

jinhang87 commented 4 weeks ago

Describe the bug Hello, I found that a small number of videos prompt this error. Please help take a look.

To Reproduce Steps to reproduce the behavior:

  1. test codes
    
    from pytubefix import YouTube
    from pytubefix import Channel

def test_YouTube(): url = 'https://www.youtube.com/watch?v=70dcBUFysyo' # has age restrictions and cannot be accessed without confirmation.

yt = YouTube(url, on_progress_callback=show_download_progress, use_oauth=True, allow_oauth_cache=True)

video_stream = yt.streams.get_highest_resolution()

output_path = r"./"
video_title_file = "test1.mp4"
video_stream.download(output_path=output_path, filename=video_title_file, max_retries=5)

def show_download_progress(stream, chunk, bytes_remaining): total_size = stream.filesize bytes_downloaded = total_size - bytes_remaining

progress = (bytes_downloaded / total_size) * 100
print(f"{progress:.2f}% ({bytes_downloaded / 1024 / 1024:.2f} MB / {total_size / 1024 / 1024:.2f} MB)", end='\r')

if name == 'main': test_YouTube()


3. See error

Traceback (most recent call last): File "D:\code\python\project\examples\pytube\test_pytubefix.py", line 74, in if name == 'main': File "D:\code\python\project\examples\pytube\test_pytubefix.py", line 15, in test_YouTube

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pytubefix__main__.py", line 563, in streams self.check_availability() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pytubefix__main.py", line 321, in check_availability self.age_check() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pytubefix\main__.py", line 417, in age_check raise exceptions.AgeCheckRequiredError(self.video_id) pytubefix.exceptions.AgeCheckRequiredError: 70dcBUFysyo has age restrictions and cannot be accessed without confirmation.



**Desktop (please complete the following information):**
 - OS: [Windows 11]
 - Python Version [3.10.11]
 - Pytubefix Version [6.11.0]
felipeucelli commented 4 weeks ago

Hi @jinhang87, could you do a test?

On line 395 of pytubefix's __main__ file, change the client to 'IOS' and tell us the result.

change this:

self.client = 'WEB'
innertube = InnerTube(
    client=self.client,
    use_oauth=self.use_oauth,
    allow_cache=self.allow_oauth_cache,
    token_file=self.token_file,
)

For that:

self.client = 'IOS'
innertube = InnerTube(
    client=self.client,
    use_oauth=self.use_oauth,
    allow_cache=self.allow_oauth_cache,
    token_file=self.token_file,
)
jinhang87 commented 3 weeks ago

Hello, I used this parameter here, and it's the same error image

Traceback (most recent call last):
  File "D:\code\python\project\examples\pytube\test_pytubefix_issue.py", line 22, in <module>
    test_YouTube()
  File "D:\code\python\project\examples\pytube\test_pytubefix_issue.py", line 8, in test_YouTube
    video_stream = yt.streams.get_highest_resolution()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pytubefix\__main__.py", line 564, in streams
    self.check_availability()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pytubefix\__main__.py", line 321, in check_availability
    self.age_check()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pytubefix\__main__.py", line 418, in age_check
    raise exceptions.AgeCheckRequiredError(self.video_id)
pytubefix.exceptions.AgeCheckRequiredError: 70dcBUFysyo has age restrictions and cannot be accessed without confirmation.
felipeucelli commented 3 weeks ago

I tested with several accounts and several videos, and they all worked for me.

Could you debug line 410 of __main__ and show us the result of playability_status.

jinhang87 commented 2 weeks ago

url = 'https://www.youtube.com/watch?v=z528yJglerI' # has age restrictions and cannot be accessed without confirmation.

playability_status: AGE_CHECK_REQUIRED

felipeucelli commented 2 weeks ago

I really didn't find anything wrong with the library, maybe this is a local problem. try deleting the __cache__ folder from pytubefix or try opening an age-restricted video on the official YouTube web, confirm your age and use the same account to log in with use_oauth. Or if you would prefer to investigate the issue, I would be happy to help.