pytube: Getting a KeyError: 'title' when trying to download a playlist

im currently getting a key error when trying to download a playlist, anyone know a fix for this?

File "C:\Python34\lib\tkinter\__init__.py", line 1487, in __call__ return self.func(*args) File "D:/Pycharm/idk/playlist activator/youtubedownloaderguiNEW.py", line 38, in func pl.download_all('C:\\pythonmusic',prefix_number= True) File "C:\Users\nicton\PycharmProjects\abs\venv\lib\site-packages\pytube\contrib\playlist.py", line 172, in download_all dl_stream.download(download_path, filename_prefix=prefix) File "C:\Users\nicton\PycharmProjects\abs\venv\lib\site-packages\pytube\streams.py", line 206, in download filename = filename or self.default_filename File "C:\Users\nicton\PycharmProjects\abs\venv\lib\site-packages\pytube\streams.py", line 176, in default_filename title = self.player_config_args['title'] KeyError: 'title'

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 36 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Hopefully that pull request fixes the problem.

You have to edit the source files for pytube on your computer. You will then need to make the following changes below https://github.com/nficano/pytube/pull/435/files. The quickest way to find the files for Pytube, is to import pytube and check it’s file method!

@shostakun - Ok, try it now,

import os YouTube(link).streams.first().download(output_path=os.getcwd(), filename=“myvid”)

In order to fix the KeyError, you have to specify the filename in the download() functions parameters because pytube looks for a specified filename and if that is not set then it looks for the default title in the self.player_config_args['title'] dictionary entry.

In your script to download a video explicitly define the file name in this one liner Code Fix: YouTube(link).streams.first().download(output_path=path, filename=filename)

It worked for me when I specified the filename parameter of download function: YouTube(link).streams.first().download(output_path=path, filename=filename)

I executed “git pull origin pull/435/head”, compile && install then tried to download a file

YouTube(‘https://www.youtube.com/watch?v=602kWwpHmt0&list=RD602kWwpHmt0&start_radio=1’).streams.filter(progressive=True).first().download() and I got this forbidden error

File “/usr/lib/python2.7/urllib2.py”, line 556, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Forbidden

I faced the very same problem but i managed to solve it using two other fixes:

  1. Apply this fix to mixins.py
  2. Apply this fix to cipher.py

Hope it helps.

@Klakinoumi - If you use git from the command line, use this command:

git pull origin pull/435/head

If not, you may just have to edit the 2 files manually.

@TheGameIsAboutGlory there is also a change to streams.py, you can see it here: https://github.com/nficano/pytube/pull/435/files