Created
January 27, 2024 10:33
-
-
Save Grub4K/701d90c94a802cdc8367c41d18b0d502 to your computer and use it in GitHub Desktop.
Fixed update, configurable progress rate as a plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import time | |
from threading import Lock | |
from yt_dlp.downloader.common import FileDownloader | |
# Configure update delay here, in nanoseconds | |
UPDATE_DELAY_NS = 1_000_000_000 | |
_next_update = time.monotonic_ns() | |
_lock = Lock() | |
_old_report_progress = FileDownloader.report_progress | |
@functools.wraps(FileDownloader.report_progress) | |
def report_progress(self, s): | |
global _next_update | |
current_time = time.monotonic_ns() | |
with _lock: | |
if current_time < _next_update and s['status'] != 'finished': | |
return | |
_next_update = current_time + UPDATE_DELAY_NS | |
_old_report_progress(self, s) | |
FileDownloader.report_progress = report_progress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment