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.

51 lines
1.7 KiB

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