logo

youtube-dl

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

execafterdownload.py (877B)


  1. from __future__ import unicode_literals
  2. import subprocess
  3. from .common import PostProcessor
  4. from ..compat import compat_shlex_quote
  5. from ..utils import (
  6. encodeArgument,
  7. PostProcessingError,
  8. )
  9. class ExecAfterDownloadPP(PostProcessor):
  10. def __init__(self, downloader, exec_cmd):
  11. super(ExecAfterDownloadPP, self).__init__(downloader)
  12. self.exec_cmd = exec_cmd
  13. def run(self, information):
  14. cmd = self.exec_cmd
  15. if '{}' not in cmd:
  16. cmd += ' {}'
  17. cmd = cmd.replace('{}', compat_shlex_quote(information['filepath']))
  18. self._downloader.to_screen('[exec] Executing command: %s' % cmd)
  19. retCode = subprocess.call(encodeArgument(cmd), shell=True)
  20. if retCode != 0:
  21. raise PostProcessingError(
  22. 'Command returned error code %d' % retCode)
  23. return [], information