You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB

  1. from ..utils import PostProcessingError
  2. class PostProcessor(object):
  3. """Post Processor class.
  4. PostProcessor objects can be added to downloaders with their
  5. add_post_processor() method. When the downloader has finished a
  6. successful download, it will take its internal chain of PostProcessors
  7. and start calling the run() method on each one of them, first with
  8. an initial argument and then with the returned value of the previous
  9. PostProcessor.
  10. The chain will be stopped if one of them ever returns None or the end
  11. of the chain is reached.
  12. PostProcessor objects follow a "mutual registration" process similar
  13. to InfoExtractor objects.
  14. """
  15. _downloader = None
  16. def __init__(self, downloader=None):
  17. self._downloader = downloader
  18. def set_downloader(self, downloader):
  19. """Sets the downloader for this PP."""
  20. self._downloader = downloader
  21. def run(self, information):
  22. """Run the PostProcessor.
  23. The "information" argument is a dictionary like the ones
  24. composed by InfoExtractors. The only difference is that this
  25. one has an extra field called "filepath" that points to the
  26. downloaded file.
  27. This method returns a tuple, the first element of which describes
  28. whether the original file should be kept (i.e. not deleted - None for
  29. no preference), and the second of which is the updated information.
  30. In addition, this method may raise a PostProcessingError
  31. exception if post processing fails.
  32. """
  33. return None, information # by default, keep file and do nothing
  34. class AudioConversionError(PostProcessingError):
  35. pass