From 4c3f8c3fb68637d80acc58f908b1511f9160bdbc Mon Sep 17 00:00:00 2001 From: pukkandan Date: Fri, 4 Mar 2022 19:40:10 +0530 Subject: [PATCH] Handle negative duration from extractor Closes #2921 --- yt_dlp/YoutubeDL.py | 2 ++ yt_dlp/utils.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 10eebecf2..9672d0cd3 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -2392,6 +2392,8 @@ def sanitize_numeric_fields(info): sanitize_string_field(info_dict, 'id') sanitize_numeric_fields(info_dict) + if (info_dict.get('duration') or 0) <= 0 and info_dict.pop('duration', None): + self.report_warning('"duration" field is negative, there is an error in extractor') if 'playlist' not in info_dict: # It isn't part of a playlist diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 4134acfdc..ef2c6bb24 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -2257,7 +2257,7 @@ def unsmuggle_url(smug_url, default=None): def format_decimal_suffix(num, fmt='%d%s', *, factor=1000): """ Formats numbers with decimal sufixes like K, M, etc """ num, factor = float_or_none(num), float(factor) - if num is None: + if num is None or num < 0: return None exponent = 0 if num == 0 else int(math.log(num, factor)) suffix = ['', *'kMGTPEZY'][exponent]