TCombu
TCombu

Reputation: 5

Getting detailed info from playlist using pytube

I'm trying to use pytube to get details about each video in a playlist. The API docs show how to download videos from the playlist here, but not how to get info from them.

Since each video is a YouTube object, and the docs say you can do something like yt_video.title, I thought I could do this:

from pytube import Playlist
    
playlist = Playlist('https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n')

for video in playlist.videos:

     print(video.title)

But it doesn't work for me. I get this error when running it:

Traceback (most recent call last):
  File "C:\Users\****\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 341, in title
    self._title = self.vid_info['videoDetails']['title']
KeyError: 'videoDetails'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\****\Desktop\dev\api\yt.py", line 15, in <module>
    print(video.title)
  File "C:\Users\****\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 346, in title
    raise exceptions.PytubeError(
pytube.exceptions.PytubeError: Exception while accessing title of https://youtube.com/watch?v=41qgdwd3zAg. Please file a bug report at https://github.com/pytube/pytube

I have to wonder what I'm doing wrong, or what the right way is to get detailed info about playlist videos.

Upvotes: 0

Views: 93

Answers (1)

0x01010
0x01010

Reputation: 350

PyTube is no longer the best option. You can check this post on gitub.

But you can use PyTubeFix instead of PyTube. Usage is same, but with less problems and it's good-maintained. I use it a lot and I didn't have any problems.

Install by

pip install pytubefix

And change importations:

# from pytube import Playlist
from pytubefix import Playlist

# OR

# import pytube
import pytubefix as pytube

Upvotes: 0

Related Questions