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

Generated by cgit