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
- Fix for KeyError: 'title' issue #434 — committed to SeikoChang/pytube by SeikoChang 5 years ago
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 thedownload()
functions parameters because pytube looks for a specified filename and if that is not set then it looks for the default title in theself.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 faced the very same problem but i managed to solve it using two other fixes:
mixins.py
cipher.py
Hope it helps.
@Klakinoumi - If you use git from the command line, use this command:
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