]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/postprocessor/metadataparser.py
[postprocessor,cleanup] Create `_download_json`
[yt-dlp.git] / yt_dlp / postprocessor / metadataparser.py
index 646659e759b009df7f3aef47b91a7c5f1e3934e1..5bc435da360b7f21ec92529c82666d960183d776 100644 (file)
@@ -1,5 +1,4 @@
 import re
-
 from enum import Enum
 
 from .common import PostProcessor
@@ -26,12 +25,17 @@ def validate_action(cls, action, *data):
         '''
         if not isinstance(action, cls.Actions):
             raise ValueError(f'{action!r} is not a valid action')
-        getattr(cls, action.value)(cls, *data)
+        getattr(cls, action.value)(cls, *data)  # So this can raise error to validate
 
     @staticmethod
     def field_to_template(tmpl):
         if re.match(r'[a-zA-Z_]+$', tmpl):
             return f'%({tmpl})s'
+
+        from ..YoutubeDL import YoutubeDL
+        err = YoutubeDL.validate_outtmpl(tmpl)
+        if err:
+            raise err
         return tmpl
 
     @staticmethod
@@ -66,7 +70,7 @@ def f(info):
             self.write_debug(f'Searching for {out_re.pattern!r} in {template!r}')
             match = out_re.search(data_to_parse)
             if match is None:
-                self.report_warning(f'Could not interpret {inp!r} as {out!r}')
+                self.to_screen(f'Could not interpret {inp!r} as {out!r}')
                 return
             for attribute, value in match.groupdict().items():
                 info[attribute] = value
@@ -80,7 +84,7 @@ def replacer(self, field, search, replace):
         def f(info):
             val = info.get(field)
             if val is None:
-                self.report_warning(f'Video does not have a {field}')
+                self.to_screen(f'Video does not have a {field}')
                 return
             elif not isinstance(val, str):
                 self.report_warning(f'Cannot replace in field {field} since it is a {type(val).__name__}')