Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
 def conversion_for_info(self, info):
     device_settings = self.device.database.get(u'settings', {})
     device_info = self.device.info
     try:
         media_info = conversions.get_media_info(info.video_path)
     except ValueError:
         logging.exception('error getting media info for %r',
                           info.video_path)
         return 'copy'
     
     requires_conversion = False
     def ensure_set(v):
         if isinstance(v, basestring):
             return set([v])
         else:
             return set(v)
     if 'container' in media_info:
         info_containers = ensure_set(media_info['container'])
         if not (device_info.container_types & info_containers):
             requires_conversion = True # container doesn't match
     else:
         requires_conversion = True
     if 'audio_codec' in media_info:
         info_audio_codecs = ensure_set(media_info['audio_codec'])
         if not (device_info.audio_types & info_audio_codecs):
             requires_conversion = True # audio codec doesn't match
     else:
         requires_conversion = True
     if info.file_type == 'video':
         if (device_settings.get(u'always_sync_videos') or
             'video_codec' not in media_info):
             requires_conversion = True
         else:
             info_video_codecs = ensure_set(media_info['video_codec'])
             if not (device_info.video_types & info_video_codecs):
                 requires_conversion = True # video codec doesn't match
     if not requires_conversion:
         return 'copy' # so easy!
     elif info.file_type == 'audio':
         return (device_settings.get(u'audio_conversion') or
                 device_info.audio_conversion)
     elif info.file_type == 'video':
         return (device_settings.get(u'video_conversion') or
                 device_info.video_conversion)