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

Add download speed to the last line of the youtube-dl output #31122

Open
3 tasks done
sndcrde opened this issue Jul 28, 2022 · 4 comments
Open
3 tasks done

Add download speed to the last line of the youtube-dl output #31122

sndcrde opened this issue Jul 28, 2022 · 4 comments
Labels

Comments

@sndcrde
Copy link

sndcrde commented Jul 28, 2022

Checklist

  • I'm reporting a feature request
  • I've verified that I'm running youtube-dl version 2021.12.17
  • I've searched the bugtracker for similar feature requests including closed ones

Description

Please calculate and add the download speed to the last line of the youtube-dl output. Currently it shows something like the following:

[download] 100% of x.xxMiB in yy:yy

I'd like it to be replaced with something like:

[download] 100% of x.xxMiB in yy:yy at zzzKiB/s

Thanks

This is the version I currently get and use:

$ wget https://yt-dl.org/downloads/latest/youtube-dl

...

$ ./youtube-dl --version
2021.12.17

@dirkf
Copy link
Contributor

dirkf commented Jul 29, 2022

You could do the division yourself?

Or

--- old/youtube_dl/downloader/common.py
+++ new/youtube_dl/downloader/common.py
@@ -257,6 +257,13 @@ class FileDownloader(object):
                 if s.get('elapsed') is not None:
                     s['_elapsed_str'] = self.format_seconds(s['elapsed'])
                     msg_template += ' in %(_elapsed_str)s'
+                if s.get('speed') is None:
+                    if s.get('total_bytes') is not None and s.get('elapsed'):
+                        s['speed'] = self.calc_speed(0, s['elapsed'], s['total_bytes'])
+                if s.get('speed') is not None:
+                    s['_speed_str'] = self.format_speed(s['speed'])
+                    msg_template += ' at %(_speed_str)s'
+
                 self._report_progress_status(
                     msg_template % s, is_last_line=True)

@sndcrde
Copy link
Author

sndcrde commented Jul 29, 2022

You could do the division yourself?

You mean manually? I could but it's a useful bit of information for me so I'd prefer to have it done in the script itself. Lots of other programs show download speed when downloading stuff so youtube-dl might as well.

Does your code snippet mean that the issue has been fixed and the fix will be available in the next release or do you just show how it could be done in theory? Thanks

@dirkf
Copy link
Contributor

dirkf commented Jul 29, 2022

The code works for me. As it's a small change I don't mind merging it unless other users come along with a big thumbs-down. yt-dl shows the rate while downloading but not in the final summary: so I've just adapted the code from the former case to the latter.

Meanwhile you might like to test it, if you have Python (say, Python 3.7 or later, unless there's a reason to have an older version) installed.

If you also have git installed, you could clone a local copy of this repo, make the new youtube-dl directory current, and apply the patch to (or just paste in the green code without the leading +) youtube_dl/downloader/common.py: then run it using python3 -m youtube_dl ....

Otherwise, you could follow the instructions here (also) to get a yt-dl version with quite a few fixes (including downloads from YT), in a form that would make it easy to test the patch.

To modify this installed version: run youtube-dl -v xxx to get a back-trace that shows the youtube_dl directory of the installed version (let's say, /usr/lib/python3/dist-packages/youtube_dl), then, as super-user, modify the file as before and run youtube-dl --version to ensure the change is in the compiled byte code file.

@sndcrde
Copy link
Author

sndcrde commented Jul 29, 2022

The code works for me. As it's a small change I don't mind merging it unless other users come along with a big thumbs-down.

I hope there are no objections. It's a small change, useful for some but those who don't need it can easily ignore it. Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants