logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

common.py (2240B)


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