mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-10-04 12:55:25 -04:00
[cleanup] Misc cleanup and refactor (#2173)
This commit is contained in:
@@ -69,8 +69,8 @@ class PostProcessor(metaclass=PostProcessorMetaClass):
|
||||
return name[6:] if name[:6].lower() == 'ffmpeg' else name
|
||||
|
||||
def to_screen(self, text, prefix=True, *args, **kwargs):
|
||||
tag = '[%s] ' % self.PP_NAME if prefix else ''
|
||||
if self._downloader:
|
||||
tag = '[%s] ' % self.PP_NAME if prefix else ''
|
||||
return self._downloader.to_screen(f'{tag}{text}', *args, **kwargs)
|
||||
|
||||
def report_warning(self, text, *args, **kwargs):
|
||||
|
@@ -1,29 +1,25 @@
|
||||
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__(self, 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(*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
|
||||
|
||||
@@ -99,6 +95,8 @@ class MetadataParserPP(PostProcessor):
|
||||
search_re = re.compile(search)
|
||||
return f
|
||||
|
||||
Actions = Namespace(INTERPRET=interpretter, REPLACE=replacer)
|
||||
|
||||
|
||||
class MetadataFromFieldPP(MetadataParserPP):
|
||||
@classmethod
|
||||
|
Reference in New Issue
Block a user