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

KeyError: u'total_bytes' #10582

Closed
Elite opened this issue Sep 7, 2016 · 1 comment
Closed

KeyError: u'total_bytes' #10582

Elite opened this issue Sep 7, 2016 · 1 comment

Comments

@Elite
Copy link

@Elite Elite commented Sep 7, 2016

  • I've verified and I assure that I'm running youtube-dl 2016.09.04.1 (latest codebase)
  • At least skimmed through README and most notably FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • Question
  • Other

When using this python code:

from __future__ import unicode_literals
from youtube_dl import YoutubeDL

id = 'VxEgGUBaXw4'
audiofmt = '141/172/140/171/139'
videofmt = '137/248/299/303'
tmploc='/var/ytdl_tmp/'

def size_human(num):
    for x in ['bytes','KB','MB','GB','TB']:
        if num < 1024.0:
            return "%3.1f %s" % (num, x)
        num /= 1024.0

def progress_hook_video(pr):
    if pr['status']=='finished':
        pass
    else:
        prgstr = 'Getting Video ' + str(round(pr['downloaded_bytes'] / (pr['total_bytes'] / 100))) + '% (' + size_human(pr['downloaded_bytes']) + '/' + size_human(pr['total_bytes']) + ')'

ydl_options = {
    'outtmpl': tmploc + '%(id)s.video',
    'continuedl': True,
    'format': videofmt,
    'cache-dir':'/var/www/.cache/youtube-dl',
    'fixup':'warn',
    }

with YoutubeDL(ydl_options) as ydl:
    ydl.add_default_info_extractors()
    ydl.add_progress_hook(progress_hook_video)
    ydl.download([id])

I get this error:

python debug.py

[youtube] VxEgGUBaXw4: Downloading webpage
[youtube] VxEgGUBaXw4: Downloading video info webpage
[youtube] VxEgGUBaXw4: Extracting video information
[youtube] VxEgGUBaXw4: Downloading MPD manifest
[dashsegments] Total fragments: 317
[download] Destination: /var/ytdl_tmp/VxEgGUBaXw4.video
[download]   0.3% of ~221.03KiB at Unknown speed ETA Unknown ETATraceback (most recent call last):
  File "debug.py", line 32, in <module>
    ydl.download([id])
  File "/var/youtube-dl/youtube_dl/YoutubeDL.py", line 1775, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/var/youtube-dl/youtube_dl/YoutubeDL.py", line 693, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/var/youtube-dl/youtube_dl/YoutubeDL.py", line 739, in process_ie_result
    return self.process_video_result(ie_result, download=download)
  File "/var/youtube-dl/youtube_dl/YoutubeDL.py", line 1421, in process_video_result
    self.process_info(new_info)
  File "/var/youtube-dl/youtube_dl/YoutubeDL.py", line 1683, in process_info
    success = dl(filename, info_dict)
  File "/var/youtube-dl/youtube_dl/YoutubeDL.py", line 1625, in dl
    return fd.download(name, info)
  File "/var/youtube-dl/youtube_dl/downloader/common.py", line 350, in download
    return self.real_download(filename, info_dict)
  File "/var/youtube-dl/youtube_dl/downloader/dash.py", line 72, in real_download
    append_url_to_file(initialization_url, ctx['tmpfilename'], 'Init')
  File "/var/youtube-dl/youtube_dl/downloader/dash.py", line 47, in append_url_to_file
    success = ctx['dl'].download(target_filename, {'url': combine_url(base_url, target_url)})
  File "/var/youtube-dl/youtube_dl/downloader/common.py", line 341, in download
    'total_bytes': os.path.getsize(encodeFilename(filename)),
  File "/var/youtube-dl/youtube_dl/downloader/common.py", line 358, in _hook_progress
    ph(status)
  File "/var/youtube-dl/youtube_dl/downloader/fragment.py", line 114, in frag_progress_hook
    self._hook_progress(state)
  File "/var/youtube-dl/youtube_dl/downloader/common.py", line 358, in _hook_progress
    ph(status)
  File "debug.py", line 19, in progress_hook_video
    prgstr = 'Getting Video ' + str(round(pr['downloaded_bytes'] / (pr['total_bytes'] / 100))) + '% (' + size_human(pr['downloaded_bytes']) + '/' + size_human(pr['total_bytes']) + ')'
KeyError: u'total_bytes'

This does not errors with all videos but a few like VxEgGUBaXw4 in this example.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Sep 7, 2016

For fragment-based formats like DASH, there's no total_bytes. Use total_bytes_estimate instead.

@yan12125 yan12125 closed this Sep 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.