Пример #1
0
    def run_ffmpeg_multiple_files(self, input_paths, out_path, opts):
        self.check_version()

        oldest_mtime = min(
            os.stat(encodeFilename(path)).st_mtime for path in input_paths)

        # opts += self._configuration_args() -- postprocessor_args

        files_cmd = []
        for path in input_paths:
            files_cmd.extend([
                encodeArgument('-i'),
                encodeFilename(self._ffmpeg_filename_argument(path), True)
            ])
        cmd = (
            [encodeFilename(self.executable, True),
             encodeArgument('-y')] + files_cmd +
            [encodeArgument(o) for o in opts] +
            [encodeFilename(self._ffmpeg_filename_argument(out_path), True)])

        # if self._downloader.params.get('verbose', False):
        self.logger.debug('[debug] ffmpeg command line: %s' % shell_quote(cmd))
        p = subprocess.Popen(cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             stdin=subprocess.PIPE)
        stdout, stderr = p.communicate()
        if p.returncode != 0:
            stderr = stderr.decode('utf-8', 'replace')
            msg = stderr.strip().split('\n')[-1]
            raise SaneFFmpegPostProcessorError(msg)
        self.try_utime(out_path, oldest_mtime, oldest_mtime)
Пример #2
0
 def get_audio_codec(self, path):
     if not self.probe_available:
         raise PostProcessingError(
             'ffprobe or avprobe not found. Please install one.')
     try:
         cmd = [
             encodeFilename(self.probe_executable, True),
             encodeArgument('-show_streams'),
             encodeFilename(self._ffmpeg_filename_argument(path), True)
         ]
         # if self._downloader.params.get('verbose', False):
         self.logger.debug('%s command line: %s' %
                           (self.basename, shell_quote(cmd)))
         handle = subprocess.Popen(cmd,
                                   stderr=compat_subprocess_get_DEVNULL(),
                                   stdout=subprocess.PIPE,
                                   stdin=subprocess.PIPE)
         output = handle.communicate()[0]
         if handle.wait() != 0:
             return None
     except (IOError, OSError):
         return None
     audio_codec = None
     for line in output.decode('ascii', 'ignore').split('\n'):
         if line.startswith('codec_name='):
             audio_codec = line.split('=')[1].strip()
         elif line.strip(
         ) == 'codec_type=audio' and audio_codec is not None:
             return audio_codec
     return None
Пример #3
0
    def run_ffmpeg_multiple_files(self,
                                  input_paths,
                                  out_path,
                                  opts,
                                  opts_before=[]):
        self.check_version()

        # sanitize file path
        out_path = pathvalidate.sanitize_filepath(out_path)

        oldest_mtime = min(
            os.stat(encodeFilename(path)).st_mtime for path in input_paths)

        opts += self._configuration_args()

        files_cmd = []
        for path in input_paths:
            files_cmd.extend([
                encodeArgument('-i'),
                encodeFilename(self._ffmpeg_filename_argument(path), True)
            ])
        cmd = [
            encodeFilename(self.executable, True),
            encodeArgument('-y'),
        ]  # without -y there is a error callen, if the file exists
        if self.basename == 'ffmpeg':
            cmd += [encodeArgument('-loglevel'), encodeArgument('repeat+info')]
        cmd += (
            [encodeArgument(o) for o in opts_before] + files_cmd +
            [encodeArgument(o) for o in opts] +
            [encodeFilename(self._ffmpeg_filename_argument(out_path), True)])

        if self._downloader.params.get('verbose', False):
            self._downloader.to_screen('[debug] ffmpeg command line: %s' %
                                       shell_quote(cmd))
        p = subprocess.Popen(cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             stdin=subprocess.PIPE,
                             universal_newlines=True)

        last_line = ''
        for line in p.stderr:
            # line = line.decode('utf-8', 'replace')
            if line.find('time=') > 0:
                print('\033[K' + line.replace('\n', '') + '\r', end='')
            last_line = line
        print('')

        std_out, std_err = p.communicate()
        if p.returncode != 0:
            msg = last_line.strip().split('\n')[-1]
            raise FFmpegPostProcessorError(msg)
        self.try_utime(out_path, oldest_mtime, oldest_mtime)
def build_completion(opt_parser):
    commands = []

    for group in opt_parser.option_groups:
        for option in group.option_list:
            long_option = option.get_opt_string().strip('-')
            help_msg = shell_quote([option.help])
            complete_cmd = ['complete', '--command', 'youtube-dl', '--long-option', long_option]
            if option._short_opts:
                complete_cmd += ['--short-option', option._short_opts[0].strip('-')]
            if option.help != optparse.SUPPRESS_HELP:
                complete_cmd += ['--description', option.help]
            complete_cmd.extend(EXTRA_ARGS.get(long_option, []))
            commands.append(shell_quote(complete_cmd))

    with open(FISH_COMPLETION_TEMPLATE) as f:
        template = f.read()
    filled_template = template.replace('{{commands}}', '\n'.join(commands))
    with open(FISH_COMPLETION_FILE, 'w') as f:
        f.write(filled_template)
Пример #5
0
def build_completion(opt_parser):
    commands = []

    for group in opt_parser.option_groups:
        for option in group.option_list:
            long_option = option.get_opt_string().strip('-')
            complete_cmd = ['complete', '--command', 'youtube-dl', '--long-option', long_option]
            if option._short_opts:
                complete_cmd += ['--short-option', option._short_opts[0].strip('-')]
            if option.help != optparse.SUPPRESS_HELP:
                complete_cmd += ['--description', option.help]
            complete_cmd.extend(EXTRA_ARGS.get(long_option, []))
            commands.append(shell_quote(complete_cmd))

    with open(FISH_COMPLETION_TEMPLATE) as f:
        template = f.read()
    filled_template = template.replace('{{commands}}', '\n'.join(commands))
    with open(FISH_COMPLETION_FILE, 'w') as f:
        f.write(filled_template)
Пример #6
0
 def test_shell_quote(self):
     args = ['ffmpeg', '-i', encodeFilename('ñ€ß\'.mp4')]
     self.assertEqual(shell_quote(args), """ffmpeg -i 'ñ€ß'"'"'.mp4'""")
Пример #7
0
 def test_shell_quote(self):
     args = ['ffmpeg', '-i', encodeFilename('ñ€ß\'.mp4')]
     self.assertEqual(shell_quote(args), """ffmpeg -i 'ñ€ß'"'"'.mp4'""")
Пример #8
0
 def test_shell_quote(self):
     args = ["ffmpeg", "-i", encodeFilename("ñ€ß'.mp4")]
     self.assertEqual(shell_quote(args), """ffmpeg -i 'ñ€ß'"'"'.mp4'""")