Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playlist returns empty list #89

Closed
Maelstrom6 opened this issue Jul 2, 2020 · 1 comment
Closed

Playlist returns empty list #89

Maelstrom6 opened this issue Jul 2, 2020 · 1 comment

Comments

@Maelstrom6
Copy link

I raised a question in StackOverflow but I think copying it here might get it answered a bit quicker.

It seems that sometime in the past 2 or 3 weeks, the Playlist class seems to have stopped working for me. I've tried the following code snippet adapted from the ReadMe:

from pytube import Playlist
playlist = Playlist("https://www.youtube.com/playlist?list=PLynhp4cZEpTbRs_PYISQ8v_uwO0_mDg_X")

print(len(playlist.video_urls))
for url in playlist.video_urls:
    print(url)

I've tried multiple public playlists but they all produced an empty list object. This code was working about 3 weeks ago. Also, I am running Python 3.7.6 and the latest version of PyTube3 (9.6.4).

Is there something that I'm doing wrong?

@Maelstrom6
Copy link
Author

I looked into the source a bit and it seemed that it would load the html and then perform a regex search for /watch/v=... URLs. The regex expression used was href=\"(/watch\?v=[\w-]*) but it couldn't find any matches since YouTube must have updated their html. They now send the watch URLs in a JSON object. So we should look for that instead.

About to send a pull request.

For now, here is something that works:

from pytube import Playlist
import re

playlist = Playlist("https://www.youtube.com/playlist?list=PLynhp4cZEpTbRs_PYISQ8v_uwO0_mDg_X")
playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)")

print(len(playlist.video_urls))
for url in playlist.video_urls:
    print(url)

Hope this is useful until the next patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant