def test_parsing(self): self.build_config_file( "foo.conv", "[DEFAULT]\n" "name: Foo\n" "executable: ffmpeg\n" "\n" "[Target1]\n" "extension: mp4\n" "parameters: -i {input}\n" ) cm = conversions.ConverterManager() cm.load_converters(os.path.join(self.tempdir, "*.conv")) self.assertEqual(len(cm.get_converters()), 1) converter = cm.lookup_converter("target1") # this comes from the section name self.assertEqual(converter.name, "Target1") # this comes from the default self.assertEqual(converter.executable, "ffmpeg") # this comes from the section self.assertEqual(converter.extension, "mp4") # this is a special case self.assertEqual(converter.platforms, None)
def convert(args): cm = conversions.ConverterManager() cm.load_converters(resources.path('conversions/*.conv')) if len(args) < 2: print USAGE print "Available targets:" for section, converters in cm.get_converters(): print " %s" % section for mem in converters: print " %s - %s" % (mem.identifier, mem.name) return target = args[0] infiles = args[1:] try: converter_info = cm.lookup_converter(target) except KeyError: print "That target doesn't exist." return for mem in infiles: input_file = os.path.abspath(mem) if not os.path.exists(input_file): print "File %s does not exist. Skipping." % input_file continue final_path, temp_path = conversions.build_output_paths( FakeInfo(input_file), os.getcwd(), converter_info) media_info = conversions.get_media_info(input_file) params = conversions.build_parameters(mem, temp_path, converter_info, media_info) if converter_info.executable == "ffmpeg": cmd = utils.get_ffmpeg_executable_path() params = utils.customize_ffmpeg_parameters(params) else: cmd = utils.get_ffmpeg2theora_executable_path() params = utils.customize_ffmpeg2theora_parameters(params) params.insert(0, cmd) print "\nCONVERTING %s -> %s\n" % (mem, final_path) print "ffmpeg command line:" print " ".join(params) print "\n" retcall = subprocess.call(params) if retcall == 0: shutil.move(temp_path, final_path) print "Success! New file at %s." % final_path
def test_only_on(self): self.build_config_file( "foo2.conv", "[DEFAULT]\n" "name: Foo\n" "executable: ffmpeg\n" "\n" "[Target1]\n" "extension: mp4\n" "parameters: -i {input}\n" "only_on: %(platform)s\n" % {"platform": app.config.get(prefs.APP_PLATFORM)}) cm = conversions.ConverterManager() cm.load_converters(os.path.join(self.tempdir, "*.conv")) self.assertEqual(len(cm.get_converters()), 1) converter = cm.lookup_converter("target1") self.assertEqual(converter.platforms, app.config.get(prefs.APP_PLATFORM))
def test_empty(self): cm = conversions.ConverterManager() cm.load_converters(os.path.join(self.tempdir, "*.conv")) self.assertEquals(len(cm.get_converters()), 0) self.assertRaises(KeyError, cm.lookup_converter, "abc")