예제 #1
0
    def add(self, sound_file):
        # generate a temporary filename from source name and output suffix
        output_suffix = self.window.prefs.get_output_suffix()
        output_filename = sound_file.uri + "%s~SC~" % output_suffix

        if vfs_exists(output_filename):
            # always overwrite temporary files
            vfs_unlink(output_filename)

        path = urlparse(output_filename)[2]
        path = unquote_filename(path)

        c = Converter(
            sound_file,
            output_filename,
            self.window.prefs.get_string("output-mime-type"),
            self.window.prefs.get_int("delete-original"),
            self.window.prefs.get_int("output-resample"),
            self.window.prefs.get_int("resample-rate"),
            self.window.prefs.get_int("force-mono"),
        )
        c.set_vorbis_quality(self.window.prefs.get_float("vorbis-quality"))
        c.set_aac_quality(self.window.prefs.get_int("aac-quality"))
        c.set_opus_quality(self.window.prefs.get_int("opus-bitrate"))
        c.set_flac_compression(self.window.prefs.get_int("flac-compression"))
        c.set_wav_sample_width(self.window.prefs.get_int("wav-sample-width"))
        c.set_audio_profile(self.window.prefs.get_string("audio-profile"))

        quality = {"cbr": "mp3-cbr-quality", "abr": "mp3-abr-quality", "vbr": "mp3-vbr-quality"}
        mode = self.window.prefs.get_string("mp3-mode")
        c.set_mp3_mode(mode)
        c.set_mp3_quality(self.window.prefs.get_int(quality[mode]))
        c.init()
        c.add_listener("finished", self.on_task_finished)
        self.add_task(c)
예제 #2
0
    def on_task_finished(self, task):
        task.sound_file.progress = 1.0

        if task.error:
            debug("error in task, skipping rename:", task.output_filename)
            if vfs_exists(task.output_filename):
                vfs_unlink(task.output_filename)
            self.errors.append(task.error)
            self.error_count += 1
            return

        duration = task.get_duration()
        if duration:
            self.duration_processed += duration

        # rename temporary file
        newname = self.window.prefs.generate_filename(task.sound_file)
        log(beautify_uri(task.output_filename), "->", beautify_uri(newname))

        # safe mode. generate a filename until we find a free one
        p, e = os.path.splitext(newname)
        p = p.replace("%", "%%")
        p = p + " (%d)" + e
        i = 1
        while vfs_exists(newname):
            newname = p % i
            i += 1

        task.error = vfs_rename(task.output_filename, newname)
        if task.error:
            self.errors.append(task.error)
            self.error_count += 1
예제 #3
0
    def add(self, sound_file):
        # generate a temporary filename from source name and output suffix
        output_filename = self.window.prefs.generate_temp_filename(sound_file) + '~SC~'

        if vfs_exists(output_filename):
            # always overwrite temporary files
            vfs_unlink(output_filename)
        
        c = Converter(sound_file, output_filename,
                        self.window.prefs.get_string('output-mime-type'),
                        self.window.prefs.get_int('delete-original'),
                        self.window.prefs.get_int('output-resample'),
                        self.window.prefs.get_int('resample-rate'),
                        self.window.prefs.get_int('force-mono'),
                        )
        c.set_vorbis_quality(self.window.prefs.get_float('vorbis-quality'))
        c.set_aac_quality(self.window.prefs.get_int('aac-quality'))
        c.set_opus_quality(self.window.prefs.get_int('opus-bitrate'))
        c.set_flac_compression(self.window.prefs.get_int('flac-compression'))
        c.set_wav_sample_width(self.window.prefs.get_int('wav-sample-width'))
        c.set_audio_profile(self.window.prefs.get_string('audio-profile'))

        quality = {
            'cbr': 'mp3-cbr-quality',
            'abr': 'mp3-abr-quality',
            'vbr': 'mp3-vbr-quality'
        }
        mode = self.window.prefs.get_string('mp3-mode')
        c.set_mp3_mode(mode)
        c.set_mp3_quality(self.window.prefs.get_int(quality[mode]))
        c.init()
        c.add_listener('finished', self.on_task_finished)
        self.add_task(c)
예제 #4
0
 def restart(self):
     self.parsed = False
     self.duration = None
     self.finished()
     if vfs_exists(self.output_filename):
         vfs_unlink(self.output_filename)
     self.play()
예제 #5
0
    def on_task_finished(self, task):
        task.sound_file.progress = 1.0

        if task.error:
            debug('error in task, skipping rename:', task.output_filename)
            if vfs_exists(task.output_filename):
                vfs_unlink(task.output_filename)
            self.errors.append(task.error)
            self.error_count += 1
            return

        duration = task.get_duration()
        if duration:
            self.duration_processed += duration

        # rename temporary file
        newname = self.window.prefs.generate_filename(task.sound_file)
        log(beautify_uri(task.output_filename), '->', beautify_uri(newname))

        # safe mode. generate a filename until we find a free one
        p, e = os.path.splitext(newname)
        p = p.replace('%', '%%')
        p = p + ' (%d)' + e
        i = 1
        while vfs_exists(newname):
            newname = p % i
            i += 1

        task.error = vfs_rename(task.output_filename, newname)
        if task.error:
            self.errors.append(task.error)
            self.error_count += 1
예제 #6
0
 def restart(self):
     self.parsed = False
     self.duration = None
     self.finished()
     if vfs_exists(self.output_filename):
         vfs_unlink(self.output_filename)
     self.play()
예제 #7
0
    def add(self, sound_file):
        # generate a temporary filename from source name and output suffix
        output_filename = self.window.prefs.generate_temp_filename(sound_file)

        if vfs_exists(output_filename):
            # always overwrite temporary files
            vfs_unlink(output_filename)

        c = Converter(
            sound_file,
            output_filename,
            self.window.prefs.get_string('output-mime-type'),
            self.window.prefs.get_int('delete-original'),
            self.window.prefs.get_int('output-resample'),
            self.window.prefs.get_int('resample-rate'),
            self.window.prefs.get_int('force-mono'),
        )
        c.set_vorbis_quality(self.window.prefs.get_float('vorbis-quality'))
        c.set_aac_quality(self.window.prefs.get_int('aac-quality'))
        c.set_opus_quality(self.window.prefs.get_int('opus-bitrate'))
        c.set_flac_compression(self.window.prefs.get_int('flac-compression'))
        c.set_wav_sample_width(self.window.prefs.get_int('wav-sample-width'))
        c.set_audio_profile(self.window.prefs.get_string('audio-profile'))

        quality = {
            'cbr': 'mp3-cbr-quality',
            'abr': 'mp3-abr-quality',
            'vbr': 'mp3-vbr-quality'
        }
        mode = self.window.prefs.get_string('mp3-mode')
        c.set_mp3_mode(mode)
        c.set_mp3_quality(self.window.prefs.get_int(quality[mode]))
        c.init()
        c.add_listener('finished', self.on_task_finished)
        self.add_task(c)
예제 #8
0
    def init(self):
        self.encoders = {
            'audio/x-vorbis': self.add_oggvorbis_encoder,
            'audio/x-flac': self.add_flac_encoder,
            'audio/x-wav': self.add_wav_encoder,
            'audio/mpeg': self.add_mp3_encoder,
            'audio/x-m4a': self.add_aac_encoder,
            'gst-profile': self.add_audio_profile,
        }
        self.add_command('audiorate')
        self.add_command('audioresample')
        self.add_command('audioconvert')

        # audio resampling support
        if self.output_resample:
            self.add_command('audio/x-raw-int,rate=%d' % self.resample_rate)
            self.add_command('audioresample')
            self.add_command('audioconvert')

        if self.force_mono:
            self.add_command('audio/x-raw-int,channels=1')
            self.add_command('audioconvert')

        encoder = self.encoders[self.output_type]()
        if not encoder:
            # TODO: is this used ?
            # TODO: add proper error management when an encoder cannot be created
            dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
                        gtk.MESSAGE_ERROR,
                        gtk.BUTTONS_OK,
                        _("Cannot create a decoder for \'%s\' format.") % \
                        self.output_type)
            dialog.run()
            dialog.hide()
            return

        self.add_command(encoder)

        uri = gnomevfs.URI(self.output_filename)
        dirname = uri.parent
        if dirname and not gnomevfs.exists(dirname):
            log('Creating folder: \'%s\'' % dirname)
            if not vfs_makedirs(str(dirname)):
                # TODO add better error management
                dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
                            gtk.MESSAGE_ERROR,
                            gtk.BUTTONS_OK,
                            _("Cannot create \'%s\' folder.") % \
                            dirname)
                dialog.run()
                dialog.hide()
                return

        self.add_command('%s location="%s"' % (
            gstreamer_sink, encode_filename(self.output_filename)))
        if self.overwrite and vfs_exists(self.output_filename):
            log('overwriting \'%s\'' % self.output_filename)
            vfs_unlink(self.output_filename)
예제 #9
0
    def init(self):
        self.encoders = {
            'audio/x-vorbis': self.add_oggvorbis_encoder,
            'audio/x-flac': self.add_flac_encoder,
            'audio/x-wav': self.add_wav_encoder,
            'audio/mpeg': self.add_mp3_encoder,
            'audio/x-m4a': self.add_aac_encoder,
            'audio/ogg; codecs=opus': self.add_opus_encoder,
            'gst-profile': self.add_audio_profile,
        }
        self.add_command('audiorate')
        self.add_command('audioconvert')
        self.add_command('audioresample')

        # audio resampling support
        if self.output_resample:
            self.add_command('audio/x-raw-int,rate=%d' % self.resample_rate)
            self.add_command('audioconvert')
            self.add_command('audioresample')

        if self.force_mono:
            self.add_command('audio/x-raw-int,channels=1')
            self.add_command('audioconvert')

        encoder = self.encoders[self.output_type]()
        if not encoder:
            # TODO: is this used ?
            # TODO: add proper error management when an encoder cannot be created
            show_error(_('Error', "Cannot create a decoder for \'%s\' format.") % 
                        self.output_type)
            return

        self.add_command(encoder)

        uri = gnomevfs.URI(self.output_filename)
        dirname = uri.parent
        if dirname and not gnomevfs.exists(dirname):
            log('Creating folder: \'%s\'' % dirname)
            if not vfs_makedirs(str(dirname)):
                show_error('Error', _("Cannot create \'%s\' folder.") % dirname)
                return

        self.add_command('%s location="%s"' % (
            gstreamer_sink, encode_filename(self.output_filename)))
        if self.overwrite and vfs_exists(self.output_filename):
            log('overwriting \'%s\'' % beautify_uri(self.output_filename))
            vfs_unlink(self.output_filename)
예제 #10
0
    def finished(self):
        Pipeline.finished(self)

        # Copy file permissions
        try:
            info = gnomevfs.get_file_info(self.sound_file.uri,
                                        gnomevfs.FILE_INFO_FIELDS_PERMISSIONS)
            gnomevfs.set_file_info(self.output_filename, info,
                                            gnomevfs.SET_FILE_INFO_PERMISSIONS)
        except:
            log('Cannot set permission on \'%s\'' %
                        gnomevfs.format_uri_for_display(self.output_filename))

        if self.delete_original and self.processing and not self.error:
            log('deleting: \'%s\'' % self.sound_file.uri)
            try:
                vfs_unlink(self.sound_file.uri)
            except:
                log('Cannot remove \'%s\'' %
                        gnomevfs.format_uri_for_display(self.output_filename))
예제 #11
0
    def finished(self):
        Pipeline.finished(self)

        # Copy file permissions
        try:
            info = gnomevfs.get_file_info(
                self.sound_file.uri, gnomevfs.FILE_INFO_FIELDS_PERMISSIONS)
            gnomevfs.set_file_info(self.output_filename, info,
                                   gnomevfs.SET_FILE_INFO_PERMISSIONS)
        except:
            log('Cannot set permission on \'%s\'' %
                gnomevfs.format_uri_for_display(self.output_filename))

        if self.delete_original and self.processing and not self.error:
            log('deleting: \'%s\'' % self.sound_file.uri)
            try:
                vfs_unlink(self.sound_file.uri)
            except:
                log('Cannot remove \'%s\'' %
                    gnomevfs.format_uri_for_display(self.output_filename))
예제 #12
0
    def install_plugin_cb(self, result):
        if result in (gst.pbutils.INSTALL_PLUGINS_SUCCESS,
                      gst.pbutils.INSTALL_PLUGINS_PARTIAL_SUCCESS):
            gst.update_registry()
            self.parsed = False
            self.duration = None
            self.finished()
            vfs_unlink(self.output_filename)
            self.play()
            return
        self.done()
        if result == gst.pbutils.INSTALL_PLUGINS_USER_ABORT:
            dialog = gtk.MessageDialog(parent=None, flags=gtk.DIALOG_MODAL,
                type=gtk.MESSAGE_INFO,
                buttons=gtk.BUTTONS_OK,
                message_format='Plugin installation aborted.')
            dialog.run()
            dialog.hide()
            return

        show_error('Error', 'failed to install plugins: %s' % gobject.markup_escape_text(str(result)))
예제 #13
0
    def add(self, sound_file):
        output_filename = self.window.prefs.generate_filename(sound_file)
        path = urlparse(output_filename) [2]
        path = unquote_filename(path)

        exists = True
        try:
            gnomevfs.get_file_info(gnomevfs.URI((output_filename)))
        except gnomevfs.NotFoundError:
            exists = False
        except gnomevfs.AccessDeniedError:
            self.error_count += 1
            msg = _('Access denied: \'%s\'' % output_filename)
            log(msg)
            show_error(msg, '')
            raise ConverterQueueError()
            return
        except:
            self.error_count += 1
            msg = 'Invalid URI: \'%s\'' % output_filename
            log(msg)
            show_error(msg, '')
            raise ConverterQueueError()
            return

        # do not overwrite source file !!
        if output_filename == sound_file.uri:
            self.error_count += 1
            show_error(_('Cannot overwrite source file(s)!'), '')
            raise ConverterQueueCanceled()

        if exists:
            if self.overwrite_action is not None:
                result = self.overwrite_action
            else:
                dialog = self.window.existsdialog

                dpath = os.path.basename(path)
                dpath = gobject.markup_escape_text(dpath)

                msg = \
                _('The output file <i>%s</i>\n exists already.\n '\
                    'Do you want to skip the file, overwrite it or'\
                    ' cancel the conversion?\n') % dpath

                dialog.message.set_markup(msg)
                dialog.set_transient_for(self.window.widget)

                if self.overwrite_action is not None:
                    dialog.apply_to_all.set_active(True)
                else:
                    dialog.apply_to_all.set_active(False)

                result = dialog.run()
                dialog.hide()

                if dialog.apply_to_all.get_active():
                    if result == 1 or result == 0:
                        self.overwrite_action = result

            if result == 1:
                # overwrite
                try:
                    vfs_unlink(output_filename)
                except gnomevfs.NotFoundError:
                    pass
            elif result == 0:
                # skip file
                return
            else:
                # cancel operation
                raise ConverterQueueCanceled()

        c = Converter(sound_file, output_filename,
                        self.window.prefs.get_string('output-mime-type'),
                        self.window.prefs.get_int('delete-original'),
                        self.window.prefs.get_int('output-resample'),
                        self.window.prefs.get_int('resample-rate'),
                        self.window.prefs.get_int('force-mono'),
                        )
        c.set_vorbis_quality(self.window.prefs.get_float('vorbis-quality'))
        c.set_aac_quality(self.window.prefs.get_int('aac-quality'))
        c.set_flac_compression(self.window.prefs.get_int('flac-compression'))
        c.set_wav_sample_width(self.window.prefs.get_int('wav-sample-width'))
        c.set_audio_profile(self.window.prefs.get_string('audio-profile'))

        quality = {
            'cbr': 'mp3-cbr-quality',
            'abr': 'mp3-abr-quality',
            'vbr': 'mp3-vbr-quality'
        }
        mode = self.window.prefs.get_string('mp3-mode')
        c.set_mp3_mode(mode)
        c.set_mp3_quality(self.window.prefs.get_int(quality[mode]))
        c.init()
        c.add_listener('finished', self.on_task_finished)
        self.add_task(c)