def smi_to_srt(sub_path): def _detect(file_path): detector = UniversalDetector() fp = open(file_path, 'rb') for line in fp: line = line.replace(b'\r', b'') detector.feed(line) if detector.done: break fp.close() detector.close() return detector.result['encoding'] srt_path = fileutil.generate_temporary_file_path('.srt') tmp_sub_path = fileutil.generate_temporary_file_path('.smi') char_type = _detect(sub_path) context = open(sub_path, 'r', encoding=char_type, errors='ignore').read() open(tmp_sub_path, 'w', encoding='utf8').write(context) sub_path = tmp_sub_path cmd = ['/usr/local/bin/ffmpeg', '-y', '-i', sub_path, srt_path] processutil.call(cmd) return srt_path
def mux(mediafile, *args): mkv_path = fileutil.generate_temporary_file_path('.mkv') cmd = ['/usr/local/bin/mkvmerge', '-o', mkv_path, mediafile] cmd.extend(args) processutil.call(cmd) return mkv_path
def concat(mediafile, *args): mkv_path = fileutil.generate_temporary_file_path('.mkv') cmd = ['/usr/local/bin/mkvmerge', '-o', mkv_path, '--no-chapters', '--no-subtitles', mediafile] for arg in args: cmd.extend(['--no-chapters', '--no-subtitles', '+%s' % arg]) processutil.call(cmd) return mkv_path
def _get_medium_details(file_path, dictionary): template = _to_template(dictionary) command = ['/usr/local/bin/mediainfo', '--Inform=%s' % template, file_path] ret_code, details_raw, _ = processutil.call(command) return _parse_details(details_raw)
def get_mean_volume(src): ret, out, err = processutil.call(['/usr/local/bin/ffmpeg', '-i', src, '-af', 'volumedetect', '-f', 'null', '/dev/null']) vol_info = err vol_info = vol_info[vol_info.find('mean_volume:'):] vol_info = vol_info[:vol_info.find('\n')] return float(vol_info.split(' ')[1])
def call(parameters): command = parameters["command"] cwd = parameters.get('cwd', None) out, err = processutil.call(command, cwd=cwd) logutil.info('Output', out) logutil.info('Error', err)
def xml_root(self): if self._xml_root is None: cmd = ['/usr/local/bin/mediainfo', '--Output=XML', '-f', self._file_path] ret_code, out, err = processutil.call(cmd) self._xml_root = ElementTree.fromstring(out) return self._xml_root
def get_chapters(file_path): command = ['/usr/local/bin/MediaInfo', file_path] ret_code, out, err = processutil.call(command) chapter_info = out[out.find('Menu'):] return [chapter for chapter in chapter_info.splitlines(False)[1:] if chapter.strip() != '']
def execute(self): processutil.call(self.command) return self.command[-1]
def change_container(src, container): dst = fileutil.generate_temporary_file_path(container.extension) processutil.call(['/usr/local/bin/ffmpeg', '-y', '-i', src, '-map', '0', '-c', 'copy', dst]) return dst