コード例 #1
0
ファイル: concatenate_videos.py プロジェクト: TZocker/gpodder
    def _concatenate_videos(self, episodes):
        episodes = self._get_sorted_episode_list(episodes)

        # TODO: Show file list dialog for reordering

        out_filename = self._get_save_filename()
        if out_filename is None:
            return

        list_filename = os.path.join(os.path.dirname(out_filename),
                '.' + os.path.splitext(os.path.basename(out_filename))[0] + '.txt')

        with open(list_filename, 'w') as fp:
            fp.write('\n'.join("file '%s'\n" % episode.local_filename(create=False)
                for episode in episodes))

        indicator = ProgressIndicator(_('Concatenating video files'),
                _('Writing %(filename)s') % {
                    'filename': os.path.basename(out_filename)
                }, False, self.gpodder.get_dialog_parent())

        def convert():
            ffmpeg = util.Popen(['ffmpeg', '-f', 'concat', '-nostdin', '-y',
                                 '-i', list_filename, '-c', 'copy', out_filename],
                                close_fds=True)
            result = ffmpeg.wait()
            util.delete_file(list_filename)
            util.idle_add(lambda: indicator.on_finished())
            util.idle_add(lambda: self.gpodder.show_message(
                _('Videos successfully converted') if result == 0 else
                _('Error converting videos'),
                _('Concatenation result'), important=True))

        util.run_in_background(convert, True)
コード例 #2
0
ファイル: mygpodder.py プロジェクト: timabell/gpodder
    def on_button_list_uids_clicked(self, button):
        indicator = ProgressIndicator(_('Downloading device list'),
                _('Getting the list of devices from your account.'),
                False, self.main_window)

        def thread_proc():
            try:
                devices = self.mygpo_client.get_devices()
            except Exception, e:
                indicator.on_finished()
                def show_error(e):
                    if str(e):
                        message = str(e)
                    else:
                        message = e.__class__.__name__
                    self.show_message(message,
                            _('Error getting list'),
                            important=True)
                util.idle_add(show_error, e)
                return

            indicator.on_finished()

            def ui_callback(devices):
                model = DeviceList(devices)
                dialog = DeviceBrowser(model, self.main_window)
                result = dialog.get_selected()
                if result is not None:
                    uid, caption, device_type = result

                    # Update config and label with new UID
                    self.config.mygpo_device_uid = uid
                    self.label_uid_value.set_label(uid)

                    self.entry_caption.set_text(caption)
                    for index, data in enumerate(self.VALID_TYPES):
                        d_type, d_name = data
                        if device_type == d_type:
                            self.combo_type.set_active(index)
                            break
            util.idle_add(ui_callback, devices)
コード例 #3
0
ファイル: podcastdirectory.py プロジェクト: reacher/gpodder
    def obtain_podcasts_with(self, callback):
        if self.podcasts_progress_indicator is not None:
            self.podcasts_progress_indicator.on_finished()

        self.podcasts_progress_indicator = ProgressIndicator(
            _('Loading podcasts'),
            _('Please wait while the podcast list is downloaded'),
            parent=self.main_window)

        original_provider = self.current_provider

        self.en_query.set_sensitive(False)
        self.bt_search.set_sensitive(False)
        self.tag_cloud.set_sensitive(False)
        self.podcasts_model.clear()

        @util.run_in_background
        def download_data():
            try:
                podcasts = callback()
            except Exception as e:
                logger.warn('Got exception while loading podcasts: %s', e)
                podcasts = []

            @util.idle_add
            def update_ui():
                if self.podcasts_progress_indicator is not None:
                    self.podcasts_progress_indicator.on_finished()
                    self.podcasts_progress_indicator = None

                if original_provider == self.current_provider:
                    self.podcasts_model.load(podcasts or [])
                else:
                    logger.warn('Ignoring update from old thread')

                self.en_query.set_sensitive(True)
                self.bt_search.set_sensitive(True)
                self.tag_cloud.set_sensitive(True)
                if self.en_query.get_realized():
                    self.en_query.grab_focus()
コード例 #4
0
ファイル: podcastdirectory.py プロジェクト: skysign/gpodder
    def obtain_podcasts_with(self, callback):
        if self.podcasts_progress_indicator is not None:
            self.podcasts_progress_indicator.on_finished()

        self.podcasts_progress_indicator = ProgressIndicator(
            _("Loading podcasts"), _("Please wait while the podcast list is downloaded"), parent=self.main_window
        )

        original_provider = self.current_provider

        self.en_query.set_sensitive(False)
        self.bt_search.set_sensitive(False)
        self.tag_cloud.set_sensitive(False)
        self.podcasts_model.clear()

        @util.run_in_background
        def download_data():
            try:
                podcasts = callback()
            except Exception as e:
                logger.warn("Got exception while loading podcasts: %s", e)
                podcasts = []

            @util.idle_add
            def update_ui():
                if self.podcasts_progress_indicator is not None:
                    self.podcasts_progress_indicator.on_finished()
                    self.podcasts_progress_indicator = None

                if original_provider != self.current_provider:
                    logger.warn("Ignoring update from old thread")
                    return

                self.podcasts_model.load(podcasts or [])
                self.en_query.set_sensitive(True)
                self.bt_search.set_sensitive(True)
                self.tag_cloud.set_sensitive(True)
                self.en_query.grab_focus()
コード例 #5
0
ファイル: podcastdirectory.py プロジェクト: whakapapa/gpodder
class gPodderPodcastDirectory(BuilderWidget):
    def new(self):
        if hasattr(self, 'custom_title'):
            self.main_window.set_title(self.custom_title)

        if not hasattr(self, 'add_podcast_list'):
            self.add_podcast_list = None

        self.providers_model = DirectoryProvidersModel(directory.PROVIDERS)
        self.podcasts_model = DirectoryPodcastsModel(self.on_can_subscribe_changed)
        self.current_provider = None
        self.podcasts_progress_indicator = None

        self.setup_providers_treeview()
        self.setup_podcasts_treeview()
        self.setup_tag_cloud()

        selection = self.tv_providers.get_selection()
        selection.select_path((0,))
        self.on_tv_providers_row_activated(self.tv_providers, (0,), None)

        self.main_window.show()

    def download_opml_file(self, filename):
        self.providers_model.add_provider(directory.FixedOpmlFileProvider(filename))
        self.tv_providers.set_cursor(len(self.providers_model) - 1)

    def setup_podcasts_treeview(self):
        column = Gtk.TreeViewColumn('')
        cell = Gtk.CellRendererToggle()
        column.pack_start(cell, False)
        column.add_attribute(cell, 'active', DirectoryPodcastsModel.C_SELECTED)
        cell.connect('toggled', lambda cell, path: self.podcasts_model.toggle(path))
        self.tv_podcasts.append_column(column)

        column = Gtk.TreeViewColumn('')
        cell = Gtk.CellRendererText()
        cell.set_property('ellipsize', Pango.EllipsizeMode.END)
        column.pack_start(cell, True)
        column.add_attribute(cell, 'markup', DirectoryPodcastsModel.C_MARKUP)
        self.tv_podcasts.append_column(column)

        self.tv_podcasts.set_model(self.podcasts_model)
        self.podcasts_model.append((False, 'a', 'b', 'c'))

    def setup_providers_treeview(self):
        column = Gtk.TreeViewColumn('')
        cell = Gtk.CellRendererPixbuf()
        column.pack_start(cell, False)
        column.add_attribute(cell, 'pixbuf', DirectoryProvidersModel.C_ICON)
        cell = Gtk.CellRendererText()
        # cell.set_property('ellipsize', Pango.EllipsizeMode.END)
        column.pack_start(cell, True)
        column.add_attribute(cell, 'text', DirectoryProvidersModel.C_TEXT)
        column.add_attribute(cell, 'weight', DirectoryProvidersModel.C_WEIGHT)
        self.tv_providers.append_column(column)

        self.tv_providers.set_row_separator_func(self.providers_model.is_row_separator)

        self.tv_providers.set_model(self.providers_model)

    def setup_tag_cloud(self):
        self.tag_cloud = TagCloud()
        self.tag_cloud.set_size_request(-1, 130)
        self.tag_cloud.show_all()
        self.sw_tagcloud.add(self.tag_cloud)

        self.tag_cloud.connect('selected', self.on_tag_selected)

    def on_tag_selected(self, tag_cloud, tag):
        self.obtain_podcasts_with(lambda: self.current_provider.on_tag(tag))

    def on_tv_providers_row_activated(self, treeview, path, column):
        it = self.providers_model.get_iter(path)

        for row in self.providers_model:
            row[DirectoryProvidersModel.C_WEIGHT] = Pango.Weight.NORMAL

        if it:
            self.providers_model.set_value(it, DirectoryProvidersModel.C_WEIGHT, Pango.Weight.BOLD)
            provider = self.providers_model.get_value(it, DirectoryProvidersModel.C_PROVIDER)
            self.use_provider(provider)

    def use_provider(self, provider):
        self.podcasts_model.clear()
        self.current_provider = provider

        if provider.kind == directory.Provider.PROVIDER_SEARCH:
            self.lb_search.set_text(_('Search:'))
            self.bt_search.set_label(_('Search'))
        elif provider.kind == directory.Provider.PROVIDER_URL:
            self.lb_search.set_text(_('URL:'))
            self.bt_search.set_label(_('Download'))
        elif provider.kind == directory.Provider.PROVIDER_FILE:
            self.lb_search.set_text(_('Filename:'))
            self.bt_search.set_label(_('Open'))
        elif provider.kind == directory.Provider.PROVIDER_TAGCLOUD:
            self.tag_cloud.clear_tags()

            @util.run_in_background
            def load_tags():
                try:
                    tags = [(t.tag, t.weight) for t in provider.get_tags()]
                except Exception as e:
                    logger.warn('Got exception while loading tags: %s', e)
                    tags = []

                @util.idle_add
                def update_ui():
                    self.tag_cloud.set_tags(tags)
        elif provider.kind == directory.Provider.PROVIDER_STATIC:
            self.obtain_podcasts_with(provider.on_static)

        if provider.kind in (directory.Provider.PROVIDER_SEARCH,
                directory.Provider.PROVIDER_URL,
                directory.Provider.PROVIDER_FILE):
            self.en_query.set_text('')
            self.hb_text_entry.show()
            util.idle_add(self.en_query.grab_focus)
        else:
            self.hb_text_entry.hide()

        if provider.kind == directory.Provider.PROVIDER_TAGCLOUD:
            self.sw_tagcloud.show()
        else:
            self.sw_tagcloud.hide()

    def on_tv_providers_cursor_changed(self, treeview):
        path, column = treeview.get_cursor()
        if path is not None:
            self.on_tv_providers_row_activated(treeview, path, column)

    def obtain_podcasts_with(self, callback):
        if self.podcasts_progress_indicator is not None:
            self.podcasts_progress_indicator.on_finished()

        self.podcasts_progress_indicator = ProgressIndicator(_('Loading podcasts'),
                _('Please wait while the podcast list is downloaded'),
                parent=self.main_window)

        original_provider = self.current_provider

        self.en_query.set_sensitive(False)
        self.bt_search.set_sensitive(False)
        self.tag_cloud.set_sensitive(False)
        self.podcasts_model.clear()

        @util.run_in_background
        def download_data():
            try:
                podcasts = callback()
            except Exception as e:
                logger.warn('Got exception while loading podcasts: %s', e)
                podcasts = []

            @util.idle_add
            def update_ui():
                if self.podcasts_progress_indicator is not None:
                    self.podcasts_progress_indicator.on_finished()
                    self.podcasts_progress_indicator = None

                if original_provider == self.current_provider:
                    self.podcasts_model.load(podcasts or [])
                else:
                    logger.warn('Ignoring update from old thread')

                self.en_query.set_sensitive(True)
                self.bt_search.set_sensitive(True)
                self.tag_cloud.set_sensitive(True)
                if self.en_query.get_realized():
                    self.en_query.grab_focus()

    def on_bt_search_clicked(self, widget):
        if self.current_provider is None:
            return

        query = self.en_query.get_text()

        @self.obtain_podcasts_with
        def load_data():
            if self.current_provider.kind == directory.Provider.PROVIDER_SEARCH:
                return self.current_provider.on_search(query)
            elif self.current_provider.kind == directory.Provider.PROVIDER_URL:
                return self.current_provider.on_url(query)
            elif self.current_provider.kind == directory.Provider.PROVIDER_FILE:
                return self.current_provider.on_file(query)

    def on_can_subscribe_changed(self, can_subscribe):
        self.btnOK.set_sensitive(can_subscribe)

    def on_btnSelectAll_clicked(self, widget, *args):
        self.podcasts_model.set_selection_to(True)

    def on_btnSelectNone_clicked(self, widget, *args):
        self.podcasts_model.set_selection_to(False)

    def on_btnOK_clicked(self, widget, *args):
        urls = self.podcasts_model.get_selected_podcasts()

        self.main_window.destroy()

        # add channels that have been selected
        if self.add_podcast_list is not None:
            self.add_podcast_list(urls)

    def on_btnCancel_clicked(self, widget, *args):
        self.main_window.destroy()
コード例 #6
0
ファイル: podcastdirectory.py プロジェクト: skysign/gpodder
class gPodderPodcastDirectory(BuilderWidget):
    def new(self):
        if hasattr(self, "custom_title"):
            self.main_window.set_title(self.custom_title)

        if not hasattr(self, "add_podcast_list"):
            self.add_podcast_list = None

        self.providers_model = DirectoryProvidersModel(directory.PROVIDERS)
        self.podcasts_model = DirectoryPodcastsModel(self.on_can_subscribe_changed)
        self.current_provider = None
        self.podcasts_progress_indicator = None

        self.setup_providers_treeview()
        self.setup_podcasts_treeview()
        self.setup_tag_cloud()

        selection = self.tv_providers.get_selection()
        selection.select_path((0,))
        self.on_tv_providers_row_activated(self.tv_providers, (0,), None)

        self.main_window.show()

    def download_opml_file(self, filename):
        self.providers_model.add_provider(directory.FixedOpmlFileProvider(filename))
        self.tv_providers.set_cursor(len(self.providers_model) - 1)

    def setup_podcasts_treeview(self):
        column = gtk.TreeViewColumn("")
        cell = gtk.CellRendererToggle()
        column.pack_start(cell, False)
        column.add_attribute(cell, "active", DirectoryPodcastsModel.C_SELECTED)
        cell.connect("toggled", lambda cell, path: self.podcasts_model.toggle(path))
        self.tv_podcasts.append_column(column)

        column = gtk.TreeViewColumn("")
        cell = gtk.CellRendererText()
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
        column.pack_start(cell)
        column.add_attribute(cell, "markup", DirectoryPodcastsModel.C_MARKUP)
        self.tv_podcasts.append_column(column)

        self.tv_podcasts.set_model(self.podcasts_model)
        self.podcasts_model.append((False, "a", "b", "c"))

    def setup_providers_treeview(self):
        column = gtk.TreeViewColumn("")
        cell = gtk.CellRendererPixbuf()
        column.pack_start(cell, False)
        column.add_attribute(cell, "pixbuf", DirectoryProvidersModel.C_ICON)
        cell = gtk.CellRendererText()
        # cell.set_property('ellipsize', pango.ELLIPSIZE_END)
        column.pack_start(cell)
        column.add_attribute(cell, "text", DirectoryProvidersModel.C_TEXT)
        column.add_attribute(cell, "weight", DirectoryProvidersModel.C_WEIGHT)
        self.tv_providers.append_column(column)

        self.tv_providers.set_row_separator_func(self.providers_model.is_row_separator)

        self.tv_providers.set_model(self.providers_model)

    def setup_tag_cloud(self):
        self.tag_cloud = TagCloud()
        self.tag_cloud.set_size_request(-1, 130)
        self.tag_cloud.show_all()
        self.sw_tagcloud.add(self.tag_cloud)

        self.tag_cloud.connect("selected", self.on_tag_selected)

    def on_tag_selected(self, tag_cloud, tag):
        self.obtain_podcasts_with(lambda: self.current_provider.on_tag(tag))

    def on_tv_providers_row_activated(self, treeview, path, column):
        it = self.providers_model.get_iter(path)

        for row in self.providers_model:
            row[DirectoryProvidersModel.C_WEIGHT] = pango.WEIGHT_NORMAL

        if it:
            self.providers_model.set_value(it, DirectoryProvidersModel.C_WEIGHT, pango.WEIGHT_BOLD)
            provider = self.providers_model.get_value(it, DirectoryProvidersModel.C_PROVIDER)
            self.use_provider(provider)

    def use_provider(self, provider):
        self.podcasts_model.clear()
        self.current_provider = provider

        if provider.kind == directory.Provider.PROVIDER_SEARCH:
            self.lb_search.set_text("Search:")
            self.bt_search.set_label("Search")
        elif provider.kind == directory.Provider.PROVIDER_URL:
            self.lb_search.set_text("URL:")
            self.bt_search.set_label("Download")
        elif provider.kind == directory.Provider.PROVIDER_FILE:
            self.lb_search.set_text("Filename:")
            self.bt_search.set_label("Open")
        elif provider.kind == directory.Provider.PROVIDER_TAGCLOUD:
            self.tag_cloud.clear_tags()

            @util.run_in_background
            def load_tags():
                try:
                    tags = [(t.tag, t.weight) for t in provider.get_tags()]
                except Exception as e:
                    logger.warn("Got exception while loading tags: %s", e)
                    tags = []

                @util.idle_add
                def update_ui():
                    self.tag_cloud.set_tags(tags)

        elif provider.kind == directory.Provider.PROVIDER_STATIC:
            self.obtain_podcasts_with(provider.on_static)

        if provider.kind in (
            directory.Provider.PROVIDER_SEARCH,
            directory.Provider.PROVIDER_URL,
            directory.Provider.PROVIDER_FILE,
        ):
            self.en_query.set_text("")
            self.hb_text_entry.show()
            util.idle_add(self.en_query.grab_focus)
        else:
            self.hb_text_entry.hide()

        if provider.kind == directory.Provider.PROVIDER_TAGCLOUD:
            self.sw_tagcloud.show()
        else:
            self.sw_tagcloud.hide()

    def on_tv_providers_cursor_changed(self, treeview):
        path, column = treeview.get_cursor()
        self.on_tv_providers_row_activated(treeview, path, column)

    def obtain_podcasts_with(self, callback):
        if self.podcasts_progress_indicator is not None:
            self.podcasts_progress_indicator.on_finished()

        self.podcasts_progress_indicator = ProgressIndicator(
            _("Loading podcasts"), _("Please wait while the podcast list is downloaded"), parent=self.main_window
        )

        original_provider = self.current_provider

        self.en_query.set_sensitive(False)
        self.bt_search.set_sensitive(False)
        self.tag_cloud.set_sensitive(False)
        self.podcasts_model.clear()

        @util.run_in_background
        def download_data():
            try:
                podcasts = callback()
            except Exception as e:
                logger.warn("Got exception while loading podcasts: %s", e)
                podcasts = []

            @util.idle_add
            def update_ui():
                if self.podcasts_progress_indicator is not None:
                    self.podcasts_progress_indicator.on_finished()
                    self.podcasts_progress_indicator = None

                if original_provider != self.current_provider:
                    logger.warn("Ignoring update from old thread")
                    return

                self.podcasts_model.load(podcasts or [])
                self.en_query.set_sensitive(True)
                self.bt_search.set_sensitive(True)
                self.tag_cloud.set_sensitive(True)
                self.en_query.grab_focus()

    def on_bt_search_clicked(self, widget):
        if self.current_provider is None:
            return

        query = self.en_query.get_text()

        @self.obtain_podcasts_with
        def load_data():
            if self.current_provider.kind == directory.Provider.PROVIDER_SEARCH:
                return self.current_provider.on_search(query)
            elif self.current_provider.kind == directory.Provider.PROVIDER_URL:
                return self.current_provider.on_url(query)
            elif self.current_provider.kind == directory.Provider.PROVIDER_FILE:
                return self.current_provider.on_file(query)

    def on_can_subscribe_changed(self, can_subscribe):
        self.btnOK.set_sensitive(can_subscribe)

    def on_btnSelectAll_clicked(self, widget, *args):
        self.podcasts_model.set_selection_to(True)

    def on_btnSelectNone_clicked(self, widget, *args):
        self.podcasts_model.set_selection_to(False)

    def on_btnOK_clicked(self, widget, *args):
        urls = self.podcasts_model.get_selected_podcasts()

        self.main_window.destroy()

        # add channels that have been selected
        if self.add_podcast_list is not None:
            self.add_podcast_list(urls)

    def on_btnCancel_clicked(self, widget, *args):
        self.main_window.destroy()