dependencies - Pytube will not use the function .streams.filter(()) - Stack Overflow

admin2025-04-16  1

so pulled this youtube audio file down loader off the internet and it was working great one day and then all of a sudden for some reason it does not like the function \line where the streaming of the video comes into place. I have looked everywhere and it seems as though pytube is the problem just not how to handle and any help would be much appreciated. thank you for all your time in advance.

Code:

    from pytubefix import YouTube
    import os

    # url input from user
    yt = YouTube(
         str(input("Enter the URL of the video you want to download: \n>> ")))

     #  extract only audio
     video = yt.streams.filter(only_audio=True).first()

    # check for destination to save file
    print("Enter the destination (leave blank for current directory)")
    destination = str(input(">> ")) or '.'

    # download the file
    out_file = video.download(output_path=destination)

    # save the file
    base, ext = os.path.splitext(out_file)
    new_file = base + '.mp3'
    os.rename(out_file, new_file)

    # result of success`your text`
    print(yt.title + " has been successfully downloaded.")
    ```


problem with line 10
Enter the URL of the video you want to download:
>> www.youtube/watch?v=Y21OR1OPC9A
Traceback (most recent call last):
  File "c:\Users\Hotpocket\Desktop\Mike's\projects\python\yoootubdownloader\yoootub.py", line 10, in <module>
    video = yt.streams.filter(only_audio=True).first()
            ^^^^^^^^^^
  File "C:\Users\Hotpocket\Desktop\Mike's\projects\python\yoootubdownloader\venv\Lib\site-packages\pytubefix\__main__.py", line 706, in streams
    self.check_availability()
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\Hotpocket\Desktop\Mike's\projects\python\yoootubdownloader\venv\Lib\site-packages\pytubefix\__main__.py", line 396, in check_availability
    raise exceptions.BotDetection(video_id=self.video_id)
pytubefix.exceptions.BotDetection: Y21OR1OPC9A This request was detected as a bot. Use `use_po_token=True` or switch to WEB client to view. See more details at 

I was expecting for the file to download into the folder that was specified, however error occurred. I have it set in an venv with all the necessary dependencies installed a list of all the pip install in the venv:

Package            Version
------------------ ----------
certifi            2024.12.14
charset-normalizer 3.4.1
pip                25.0
pytube             15.0.0
pytube3            9.6.4
pytubefix          8.12.0
requests           2.32.3
typing_extensions  4.12.2
urllib3            2.3.0 
转载请注明原文地址:http://www.anycun.com/QandA/1744759563a87218.html