]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/postprocessor/metadataparser.py
[dependencies] Create module with all dependency imports
[yt-dlp.git] / yt_dlp / postprocessor / metadataparser.py
index 5bc435da360b7f21ec92529c82666d960183d776..51b927b9116a103c07e16721c473474652b19702 100644 (file)
@@ -1,31 +1,27 @@
 import re
-from enum import Enum
 
 from .common import PostProcessor
+from ..utils import Namespace
 
 
 class MetadataParserPP(PostProcessor):
-    class Actions(Enum):
-        INTERPRET = 'interpretter'
-        REPLACE = 'replacer'
-
     def __init__(self, downloader, actions):
-        PostProcessor.__init__(self, downloader)
+        super().__init__(downloader)
         self._actions = []
         for f in actions:
-            action = f[0]
-            assert isinstance(action, self.Actions)
-            self._actions.append(getattr(self, action.value)(*f[1:]))
+            action, *args = f
+            assert action in self.Actions
+            self._actions.append(action(self, *args))
 
     @classmethod
     def validate_action(cls, action, *data):
-        ''' Each action can be:
+        """Each action can be:
                 (Actions.INTERPRET, from, to) OR
                 (Actions.REPLACE, field, search, replace)
-        '''
-        if not isinstance(action, cls.Actions):
+        """
+        if action not in cls.Actions:
             raise ValueError(f'{action!r} is not a valid action')
-        getattr(cls, action.value)(cls, *data)  # So this can raise error to validate
+        action(cls, *data)  # So this can raise error to validate
 
     @staticmethod
     def field_to_template(tmpl):
@@ -99,6 +95,8 @@ def f(info):
         search_re = re.compile(search)
         return f
 
+    Actions = Namespace(INTERPRET=interpretter, REPLACE=replacer)
+
 
 class MetadataFromFieldPP(MetadataParserPP):
     @classmethod