def get_media_info(filepath): """Takes a file path and returns a dict of information about this media file that it extracted from ffmpeg -i. :param filepath: absolute path to the media file in question :returns: dict of media info possibly containing: height, width, container, audio_codec, video_codec """ ffmpeg_bin = utils.get_ffmpeg_executable_path() retcode, stdout, stderr = util.call_command(ffmpeg_bin, "-i", "%s" % filepath, return_everything=True) if stdout: output = stdout else: output = stderr # logging.info("get_media_info: %s %s", filepath, output) ast = parse_ffmpeg_output(output.splitlines()) return extract_info(ast)
def thread_function(): stdout = util.call_command(codegen_path, media_path, env=codegen_env) results = json.loads(stdout) # not sure why the code generator always returns a 1-element list, but # it does results = results[0] if 'error' in results: raise CodegenError(results['error']) # NOTE: both codegens return some metadata that we can use, but # mutagen can get the same data so let's just pay attention to the # code. return results['code']
def test_call_command(self): """ Currently only works on Linux and OSX """ # Command doesn't exist self.assertRaises(OSError, util.call_command, 'thiscommanddoesntexist') # Command exists but invalid option and returns error code self.assertRaises(OSError, util.call_command, 'ps', '-') # Valid command pid = int(os.getpid()) stdout = util.call_command('ps', '-p', str(pid), '-o', 'pid=') pid_read = int(stdout) self.assertEqual(pid, pid_read)
def test_call_command_success(self): pid = int(os.getpid()) stdout = util.call_command('ps', '-p', str(pid), '-o', 'pid=') pid_read = int(stdout) self.assertEqual(pid, pid_read)