]> jfr.im git - yt-dlp.git/commitdiff
Add `only_once` param for `report_warning`
authorpukkandan <redacted>
Tue, 20 Jul 2021 20:05:35 +0000 (01:35 +0530)
committerpukkandan <redacted>
Tue, 20 Jul 2021 20:09:58 +0000 (01:39 +0530)
Related: https://github.com/yt-dlp/yt-dlp/pull/488#discussion_r667527297

yt_dlp/YoutubeDL.py

index 9da607b17cb3166e7c9906b22a1ad15b747f3c66..3dfab69b2dcf20843922ae1eff2bacbdd9979009 100644 (file)
@@ -450,7 +450,7 @@ class YoutubeDL(object):
     params = None
     _ies = []
     _pps = {'pre_process': [], 'before_dl': [], 'after_move': [], 'post_process': []}
-    __prepare_filename_warned = False
+    _reported_warnings = set()
     _first_webpage_request = True
     _download_retcode = None
     _num_downloads = None
@@ -465,7 +465,7 @@ def __init__(self, params=None, auto_init=True):
         self._ies = []
         self._ies_instances = {}
         self._pps = {'pre_process': [], 'before_dl': [], 'after_move': [], 'post_process': []}
-        self.__prepare_filename_warned = False
+        self._reported_warnings = set()
         self._first_webpage_request = True
         self._post_hooks = []
         self._progress_hooks = []
@@ -755,11 +755,15 @@ def to_screen(self, message, skip_eol=False):
         self.to_stdout(
             message, skip_eol, quiet=self.params.get('quiet', False))
 
-    def report_warning(self, message):
+    def report_warning(self, message, only_once=False):
         '''
         Print the message to stderr, it will be prefixed with 'WARNING:'
         If stderr is a tty file the 'WARNING:' will be colored
         '''
+        if only_once:
+            if message in self._reported_warnings:
+                return
+            self._reported_warnings.add(message)
         if self.params.get('logger') is not None:
             self.params['logger'].warning(message)
         else:
@@ -1017,13 +1021,13 @@ def prepare_filename(self, info_dict, dir_type='', warn=False):
 
         filename = self._prepare_filename(info_dict, dir_type or 'default')
 
-        if warn and not self.__prepare_filename_warned:
+        if warn:
             if not self.params.get('paths'):
                 pass
             elif filename == '-':
-                self.report_warning('--paths is ignored when an outputting to stdout')
+                self.report_warning('--paths is ignored when an outputting to stdout', only_once=True)
             elif os.path.isabs(filename):
-                self.report_warning('--paths is ignored since an absolute path is given in output template')
+                self.report_warning('--paths is ignored since an absolute path is given in output template', only_once=True)
             self.__prepare_filename_warned = True
         if filename == '-' or not filename:
             return filename