Skip to content

Instantly share code, notes, and snippets.

@Grub4K
Created January 27, 2024 10:33
Show Gist options
  • Save Grub4K/701d90c94a802cdc8367c41d18b0d502 to your computer and use it in GitHub Desktop.
Save Grub4K/701d90c94a802cdc8367c41d18b0d502 to your computer and use it in GitHub Desktop.
Fixed update, configurable progress rate as a plugin
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