question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pytube length sometimes missing causes crash

See original GitHub issue

On certain urls trying to get the length of a youtube video crashes the program due to a key error in the object itself.

Ex: https://www.youtube.com/watch?v=4VR-6AS0-l4

Traceback (most recent call last):
    if end_time >= yt.length:
  File "/opt/python/run/venv/lib/python2.7/site-packages/pytube/__main__.py", line 286, in length
    return self.player_config_args['length_seconds']
KeyError: 'length_seconds'

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
MarcBressoncommented, Aug 28, 2019

hey i figured out what is happening ! Go to line 286 and change the only line with return ( self.player_config_args .get('player_response', {}) .get('videoDetails', {}) .get('lengthSeconds') ) It works really well for me 😉

1reaction
ricardodeazambujacommented, Sep 21, 2019

@marcounetB nailed it! However, if you don’t want to edit the source code… considering you have your object like current_video = YouTube(video_url), you just need to use:

current_video.player_config_args.get('player_response').get('videoDetails').get('lengthSeconds') or current_video.player_config_args['player_response']['videoDetails']['lengthSeconds']

Happy downloading 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pytube length sometimes missing causes crash · Issue #448
On certain urls trying to get the length of a youtube video crashes the program due to a key error in the object...
Read more >
pytube filesize() keyerror content-length - You.com - You.com
On certain urls trying to get the length of a youtube video crashes the program due to a key error in the object...
Read more >
Python YouTube downloader with pytube crashes when I ...
I am making a YouTube video downloader with Python. I made the design with PyQt and edited the code in IDLE. Here is...
Read more >
API — pytube 12.1.2 documentation
Parse a variable length sized list of codecs and returns a constant two element tuple, with the video codec as the first element...
Read more >
Associative Knowledge Graph Using Fuzzy Clustering and ...
consideration of the different length of each video content and generate ... For this reason, sometimes, it is ambiguous to find simi-.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found