Пример #1
0
    def fetch(self, name):
        '''
        Download and convert if needed.
        '''
        self.parse_button.set_sensitive(False)
        self.abort_download_button.set_sensitive(True)
        self.download_button.set_sensitive(False)
        self.clear_button.set_sensitive(False)
        self.formatframe.set_sensitive(False)
        encoding = locale.getdefaultlocale()[1]
        name = name.encode(encoding)
        try:
            saved_name = self.download(self.selected_format, name)
        except Exception:
            pass

        if self.abort_download:
            self.abort_download = False
            self.download_progressbar.set_fraction(1)
            self.download_progressbar.set_text(_('Aborted'))
        else:
            self.download_progressbar.set_text(_('Done'))
            self.abort_download_button.set_sensitive(False)

            # Conversion
            fmt = self.selected_format
            if self.fmt[fmt][1] != self.fmt[fmt][2]:
                self.download_progressbar.set_text(_('Converting to MP3, this '
                    'may take a while...'))

                # update GUI
                while gtk.events_pending():
                    gtk.main_iteration()

                try:
                    name = convert(fmt, saved_name, True)
                except Exception:
                    self.error_dialog(_('Some error occured during the '
                        'conversion, please try again.'))
                    self.download_progressbar.set_text(_('Failed'))
                else:
                    self.download_progressbar.set_text(_('Done'))

        self.parse_button.set_sensitive(True)
        self.abort_download_button.set_sensitive(False)
        self.download_button.set_sensitive(True)
        self.clear_button.set_sensitive(True)
        self.formatframe.set_sensitive(True)
Пример #2
0
    def fetch(self, fmt):
        '''
        Download and convert format if needed.
        '''
        if fmt not in self.fmt.keys():
            raise RuntimeError(_('Format not available for this video.'))

        print _('Downloading...')
        saved_name = self.download(fmt)

        # if downloaded extension != real extention, we need to convert
        if self.fmt[fmt][1] != self.fmt[fmt][2]:
            print _('Converting to %s, this may take a while...') % fmt
            saved_name = convert(fmt, saved_name)

        print _('Saved to `') + saved_name + '\'.'