mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-12-26 17:41:46 +00:00
Merge remote-tracking branch 'upstream/master' into wait-retries
This commit is contained in:
@@ -8,6 +8,7 @@ import contextlib
|
||||
import datetime as dt
|
||||
import email.header
|
||||
import email.utils
|
||||
import enum
|
||||
import errno
|
||||
import functools
|
||||
import hashlib
|
||||
@@ -51,6 +52,7 @@ from ..compat import (
|
||||
compat_HTMLParseError,
|
||||
)
|
||||
from ..dependencies import xattr
|
||||
from ..globals import IN_CLI
|
||||
|
||||
__name__ = __name__.rsplit('.', 1)[0] # noqa: A001: Pretend to be the parent module
|
||||
|
||||
@@ -1495,8 +1497,7 @@ def write_string(s, out=None, encoding=None):
|
||||
|
||||
# TODO: Use global logger
|
||||
def deprecation_warning(msg, *, printer=None, stacklevel=0, **kwargs):
|
||||
from .. import _IN_CLI
|
||||
if _IN_CLI:
|
||||
if IN_CLI.value:
|
||||
if msg in deprecation_warning._cache:
|
||||
return
|
||||
deprecation_warning._cache.add(msg)
|
||||
@@ -4899,10 +4900,6 @@ class Config:
|
||||
filename = None
|
||||
__initialized = False
|
||||
|
||||
# Internal only, do not use! Hack to enable --plugin-dirs
|
||||
# TODO(coletdjnz): remove when plugin globals system is implemented
|
||||
_plugin_dirs = None
|
||||
|
||||
def __init__(self, parser, label=None):
|
||||
self.parser, self.label = parser, label
|
||||
self._loaded_paths, self.configs = set(), []
|
||||
@@ -5640,6 +5637,24 @@ def filesize_from_tbr(tbr, duration):
|
||||
return int(duration * tbr * (1000 / 8))
|
||||
|
||||
|
||||
def _request_dump_filename(url, video_id, data=None, trim_length=None):
|
||||
if data is not None:
|
||||
data = hashlib.md5(data).hexdigest()
|
||||
basen = join_nonempty(video_id, data, url, delim='_')
|
||||
trim_length = trim_length or 240
|
||||
if len(basen) > trim_length:
|
||||
h = '___' + hashlib.md5(basen.encode()).hexdigest()
|
||||
basen = basen[:trim_length - len(h)] + h
|
||||
filename = sanitize_filename(f'{basen}.dump', restricted=True)
|
||||
# Working around MAX_PATH limitation on Windows (see
|
||||
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx)
|
||||
if os.name == 'nt':
|
||||
absfilepath = os.path.abspath(filename)
|
||||
if len(absfilepath) > 259:
|
||||
filename = fR'\\?\{absfilepath}'
|
||||
return filename
|
||||
|
||||
|
||||
# XXX: Temporary
|
||||
class _YDLLogger:
|
||||
def __init__(self, ydl=None):
|
||||
@@ -5668,3 +5683,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'
|
||||
|
||||
Reference in New Issue
Block a user