diff options
author | Simon Sawicki <contact@grub4k.xyz> | 2025-02-20 20:33:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-20 20:33:31 +0100 |
commit | f7a1f2d8132967a62b0f6d5665c6d2dde2d42c09 (patch) | |
tree | 14cd5ae857c108acd0acf035860f2684e7e1144d /yt_dlp/utils/_utils.py | |
parent | 9deed13d7cce6d3647379e50589c92de89227509 (diff) |
[core] Support emitting ConEmu progress codes (#10649)
Authored by: Grub4K
Diffstat (limited to 'yt_dlp/utils/_utils.py')
-rw-r--r-- | yt_dlp/utils/_utils.py | 30 |
1 files changed, 30 insertions, 0 deletions
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' |