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

Bug in 'progress_hooks' - 'speed' value is None depending on download location #12802

Closed
kereilly opened this issue Apr 20, 2017 · 2 comments
Closed
Labels

Comments

@kereilly
Copy link

@kereilly kereilly commented Apr 20, 2017

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like that [x])
  • Use Preview tab to see how your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2017.04.17. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.

  • [x ] I've verified and I assure that I'm running youtube-dl 2017.04.17

Before submitting an issue make sure you have:

  • [ x] At least skimmed through README and most notably FAQ and BUGS sections
  • [x ] Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • [x ] 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

Description of your issue, suggested solution and other information

Explanation of your issue in arbitrary form goes here. Please make sure the description is worded well enough to be understood. Provide as much context and examples as possible.
If work on your issue requires account credentials please provide them or explain how one can obtain them.

I call youtube-dl from within my python script. I use progress_hooks to give the user feedback. the 'speed' key normally will provide the download speed, however depending on where i set 'outtmpl' to, where the file gets saved, the value of 'speed' is None. here are the options send to youtube-dl:

destination = directory_location + file_name + ".%(ext)s"

# options for youtube-dl
ydl_opts = {
    'logger': MyLogger(),
    'progress_hooks': [my_hook],
    'outtmpl': destination,
    'ignoreerrors': True,
}
try:
    # Lets download it now
    with YoutubeDL(ydl_opts, verbosity) as ydl:
        if verbosity >= 1:
            print ("Extracting information about the file to download")
        info = ydl.extract_info(url, download=False)
        download_target = ydl.prepare_filename(info)
        if verbosity >= 1:
            print ("Target download location: " + download_target)
        ydl_results = ydl.download([url])
        if verbosity >= 2:
            print ("\nThe output of ydl_results follows:")
            print (ydl_results)`


def my_hook(d):

# lets give the user some feedback
if d['status'] == 'downloading':
    # check and make sure 'speed' is not None. It can be sometimes
    if d['speed'] is not None:
        speed = "Download Speed: " + str(int(d['speed']/1024)) + " kb/s"
    else:
        speed = "Download Speed not available"
    # just in case do same with ETA
    if d['eta'] is not None:
        eta = "   ETA: " + str(d['eta'])
    else:
        eta = "ETA not available"
    text = "\r" + speed + eta
    sys.stdout.write(text)
    sys.stdout.flush()


# Logger for youtube-dl
class MyLogger(object):
    def debug(self, msg):
        pass

    def warning(self, msg):
        pass

    def error(self, msg):
        print(msg)

I can reproduce this behavior with 'speed' having a value of none when the 'outtmpl' is set to

'/Users/edit6/Desktop/RR299_Youtube_Test.%(ext)s'

however with the 'outtmpl' set to

'/Volumes/RR311-SANCTUARY_1/RR311_ARCHIVAL_FOOTAGE/RR299_Youtube_Test.%(ext)s'

'speed' will have its expected value. It didn't matter what url i was giving it although i only tried youtube links. Here was the url i was testing with in case it does matter:
https://www.youtube.com/watch?v=PXYeARRyDWk

I'm on Mac os X 10.11.6
Python: 2.7.10
youtube-dl: 2017.04.17

@kereilly
Copy link
Author

@kereilly kereilly commented Apr 20, 2017

of course now that I put

if d['speed'] is not None:

into my code this isn't an issue. Although initially, with the first example, the value of 'speed' is None, It does change and give the user the download speed. This bug is probably not really a problem if you write proper code, which initially i did not

@dstftw dstftw closed this Apr 20, 2017
@dstftw dstftw added the invalid label Apr 20, 2017
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.