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.

62 lines
1.9 KiB

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