From f7a1f2d8132967a62b0f6d5665c6d2dde2d42c09 Mon Sep 17 00:00:00 2001 From: Simon Sawicki Date: Thu, 20 Feb 2025 20:33:31 +0100 Subject: [core] Support emitting ConEmu progress codes (#10649) Authored by: Grub4K --- yt_dlp/utils/_utils.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'yt_dlp/utils/_utils.py') diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index c6a90a0dd..3e7a375ee 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -8,6 +8,7 @@ import contextlib import datetime as dt import email.header import email.utils +import enum import errno import functools import hashlib @@ -5677,3 +5678,32 @@ class _YDLLogger: def stderr(self, message): if self._ydl: self._ydl.to_stderr(message) + + +class _ProgressState(enum.Enum): + """ + Represents a state for a progress bar. + + See: https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC + """ + + HIDDEN = 0 + INDETERMINATE = 3 + VISIBLE = 1 + WARNING = 4 + ERROR = 2 + + @classmethod + def from_dict(cls, s, /): + if s['status'] == 'finished': + return cls.INDETERMINATE + + # Not currently used + if s['status'] == 'error': + return cls.ERROR + + return cls.INDETERMINATE if s.get('_percent') is None else cls.VISIBLE + + def get_ansi_escape(self, /, percent=None): + percent = 0 if percent is None else int(percent) + return f'\033]9;4;{self.value};{percent}\007' -- cgit v1.2.3