JuanBindez / pytubefix

Python3 library for downloading YouTube Videos.
https://pytubefix.readthedocs.io
MIT License
722 stars 100 forks source link

YouTube music download stopped working after updating to pytubefix 8.4.1 #335

Closed deeffest closed 4 days ago

deeffest commented 5 days ago

:exclamation: DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE :exclamation:

lack of information will lead to closure of the issue


Describe the bug Downloading YouTube music is no longer possible as an error is thrown when attempting to download:

Traceback (most recent call last):
  File "D:\Program Files\Python\Lib\site-packages\pytubefix\__main__.py", line 693, in title
    self._title = self.vid_details['contents'][
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'videoMetadataRenderer'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "d:\Program Files\Projects\TESTS #1\test.py", line 14, in <module>
    stream = yt.streams.get_audio_only()
             ^^^^^^^^^^
  File "D:\Program Files\Python\Lib\site-packages\pytubefix\__main__.py", line 637, in streams
    return StreamQuery(self.fmt_streams)
                       ^^^^^^^^^^^^^^^^
  File "D:\Program Files\Python\Lib\site-packages\pytubefix\__main__.py", line 305, in fmt_streams
    self.stream_monostate.title = self.title
                                  ^^^^^^^^^^
  File "D:\Program Files\Python\Lib\site-packages\pytubefix\__main__.py", line 708, in title
    raise exceptions.PytubeFixError(
pytubefix.exceptions.PytubeFixError: Exception while accessing title of https://youtube.com/watch?v=lYBUbBu4W08. Please file a bug report at https://github.com/JuanBindez/pytubefix

However, downloading regular videos works fine, below is the code demonstrating this (the first URL is a regular video, the second URL is music from YT Music, but it's also available on YouTube):


code that was used that resulted in the bug

from pytubefix import YouTube

urls = [
    "https://youtube.com/watch?v=dQw4w9WgXcQ",
    "https://youtube.com/watch?v=lYBUbBu4W08"
]

for url in urls:
    print(f"Downloading {url}...")

    yt = YouTube(
        url,
        use_oauth=True,
        allow_oauth_cache=True
    )
    stream = yt.streams.get_audio_only()
    stream.download()

    print(f"Downloaded {yt.title} successfully")

Expected behavior I expect the successful download of both files in the code.


Screenshots https://github.com/user-attachments/assets/a1a389ed-e361-454d-bec1-7d9294adbc2b


Desktop (please complete the following information):


Additional context Any solutions or guesses?

JuanBindez commented 4 days ago

not being able to regain the title

JuanBindez commented 4 days ago

I did the test using your code, the first audio downloaded normally but the second failed, it is related to the 'next' endpoint, we will perhaps have to address another alternative :

https://github.com/JuanBindez/pytubefix/pull/331/commits/806e2ac2221dcdcee3e27523a76a34ff8370fc75#diff-352f0556c59f724ccc8b1124f14de5a10b9f116eec6f56b16ab536ce292c14adR686

felipeucelli commented 4 days ago

It looks like the JSON path for titles for YouTube music videos is a little different.

I sent a PR #338 that checks and searches for the title in this other path.