示例#1
0
文件: cover.py 项目: unkie/exaile
    def fetch_cover(self):
        """
        Searches for covers for the current track
        """
        db_strings = COVER_MANAGER.find_covers(self.track)

        if db_strings:
            for db_string in db_strings:
                if self.stopper.is_set():
                    return

                coverdata = COVER_MANAGER.get_cover_data(db_string)
                # Pre-render everything for faster display later
                pixbuf = pixbuf_from_data(coverdata)

                if pixbuf:
                    self.covers_model.append(
                        [
                            (db_string, coverdata),
                            pixbuf,
                            pixbuf.scale_simple(50, 50, GdkPixbuf.InterpType.BILINEAR),
                        ]
                    )

        self.emit('covers-fetched', db_strings)
示例#2
0
    def remove_cover(self):
        """
            Removes the cover of the currently selected album
        """
        paths = self.previews_box.get_selected_items()

        if paths:
            path = paths[0]
            album = self.model[path][0]
            track = self.album_tracks[album][0]
            COVER_MANAGER.remove_cover(track)
            self.model[path][1] = self.default_cover_pixbuf
示例#3
0
    def remove_cover(self):
        """
            Removes the cover of the currently selected album
        """
        paths = self.previews_box.get_selected_items()

        if paths:
            path = paths[0]
            album = self.model[path][0]
            track = self.album_tracks[album][0]
            COVER_MANAGER.remove_cover(track)
            self.model[path][1] = self.default_cover_pixbuf
示例#4
0
    def on_set_button_clicked(self, button):
        """
            Chooses the current cover and saves it to the database
        """
        paths = self.previews_box.get_selected_items()

        if paths:
            path = paths[0]
            coverdata = self.covers_model[path][0]

            COVER_MANAGER.set_cover(self.track, coverdata[0], coverdata[1])

            self.emit('cover-chosen', self.track, coverdata[1])
            self.window.destroy()
示例#5
0
    def on_set_button_clicked(self, button):
        """
            Chooses the current cover and saves it to the database
        """
        paths = self.previews_box.get_selected_items()

        if paths:
            path = paths[0]
            coverdata = self.covers_model[path][0]

            COVER_MANAGER.set_cover(self.track, coverdata[0], coverdata[1])

            self.emit('cover-chosen', self.track, coverdata[1])
            self.window.destroy()
示例#6
0
    def do_covers_fetched(self, db_strings):
        """
            Finishes the dialog setup after all covers have been fetched
        """
        if self.stopper.is_set():
            return

        self.cover_image_box.remove(self.loading_indicator)
        self.previews_box.set_model(self.covers_model)

        if db_strings:
            self.cover_image_box.pack_start(self.cover, True, True)
            self.cover.show()
            self.set_button.set_sensitive(True)

            # Show thumbnail bar if more than one cover was found
            if len(db_strings) > 1:
                self.previews_box.set_no_show_all(False)
                self.previews_box.show_all()

            # Try to select the current cover of the track, fallback to first
            track_db_string = COVER_MANAGER.get_db_string(self.track)
            position = db_strings.index(track_db_string) if track_db_string in db_strings else 0
            self.previews_box.select_path((position,))
        else:
            self.builder.get_object('info_box').hide()
            self.builder.get_object('actions_box').hide()
            self.message.show_warning(
                _('No covers found.'),
                _('None of the enabled sources has a cover for this track, try enabling more sources.')
            )
示例#7
0
    def do_covers_fetched(self, db_strings):
        """
            Finishes the dialog setup after all covers have been fetched
        """
        if self.stopper.is_set():
            return

        self.cover_image_box.remove(self.loading_indicator)
        self.previews_box.set_model(self.covers_model)

        if db_strings:
            self.cover_image_box.pack_start(self.cover, True, True, 0)
            self.cover.show()
            self.set_button.set_sensitive(True)

            # Show thumbnail bar if more than one cover was found
            if len(db_strings) > 1:
                self.previews_box.set_no_show_all(False)
                self.previews_box.show_all()

            # Try to select the current cover of the track, fallback to first
            track_db_string = COVER_MANAGER.get_db_string(self.track)
            position = db_strings.index(track_db_string) if track_db_string in db_strings else 0
            self.previews_box.select_path(Gtk.TreePath(position))
        else:
            self.builder.get_object('info_box').hide()
            self.builder.get_object('actions_box').hide()
            self.message.show_warning(
                _('No covers found.'),
                _('None of the enabled sources has a cover for this track, try enabling more sources.')
            )
示例#8
0
        def __get_cover():
            
            fetch = not settings.get_option('covers/automatic_fetching', True)
            cover_data = COVER_MANAGER.get_cover(track, set_only=fetch)

            if not cover_data:
                return

            glib.idle_add(self.on_cover_chosen, None, track, cover_data)
示例#9
0
        def __get_cover():
            
            fetch = not settings.get_option('covers/automatic_fetching', True)
            cover_data = COVER_MANAGER.get_cover(track, set_only=fetch)

            if not cover_data:
                return

            GLib.idle_add(self.on_cover_chosen, None, track, cover_data)
示例#10
0
    def on_track_tags_changed(self, e, track, tag):
        """
            Updates the displayed cover upon tag changes
        """
        if self.__track == track:
            cover_data = COVER_MANAGER.get_cover(track)

            if not cover_data:
                return

            glib.idle_add(self.on_cover_chosen, None, cover_data)
示例#11
0
文件: cover.py 项目: unkie/exaile
    def __init__(self, parent, collection):
        """
        Initializes the window
        """
        GObject.GObject.__init__(self)

        # List of identifiers of albums without covers
        self.outstanding = []
        # Map of album identifiers and their tracks
        self.album_tracks = {}

        self.outstanding_text = _('{outstanding} covers left to fetch')
        self.completed_text = _('All covers fetched')
        self.cover_size = (90, 90)
        self.default_cover_pixbuf = pixbuf_from_data(
            COVER_MANAGER.get_default_cover(), self.cover_size
        )

        builder = Gtk.Builder()
        builder.add_from_file(xdg.get_data_path('ui', 'covermanager.ui'))
        builder.connect_signals(self)

        self.window = builder.get_object('window')
        self.window.set_transient_for(parent)

        self.message = dialogs.MessageBar(
            parent=builder.get_object('content_area'), buttons=Gtk.ButtonsType.CLOSE
        )

        self.previews_box = builder.get_object('previews_box')
        self.model = builder.get_object('covers_model')
        # Map of album identifiers and model paths
        self.model_path_cache = {}
        self.menu = CoverMenu(self)
        self.menu.attach_to_widget(self.previews_box, lambda menu, widget: True)

        self.progress_bar = builder.get_object('progressbar')
        self.progress_bar.set_text(_('Collecting albums and covers...'))
        self.progress_bar.pulse_timeout = GLib.timeout_add(
            100, self.on_progress_pulse_timeout
        )
        self.close_button = builder.get_object('close_button')
        self.stop_button = builder.get_object('stop_button')
        self.stop_button.set_sensitive(False)
        self.fetch_button = builder.get_object('fetch_button')

        self.window.show_all()

        self.stopper = threading.Event()
        thread = threading.Thread(
            target=self.prefetch, name='CoverPrefetch', args=(collection,)
        )
        thread.daemon = True
        thread.start()
示例#12
0
文件: cover.py 项目: unkie/exaile
    def do_drag_data_received(self, context, x, y, selection, info, time):
        """
        Sets the cover based on the dragged data
        """
        if self.__track is not None:
            uri = selection.get_uris()[0]
            db_string = 'localfile:%s' % uri

            try:
                stream = Gio.File.new_for_uri(uri).read()
            except GLib.Error:
                return

            self.cover_data = stream.read()
            width = settings.get_option('gui/cover_width', 100)
            pixbuf = pixbuf_from_data(self.cover_data, (width, width))

            if pixbuf is not None:
                self.image.set_from_pixbuf(pixbuf)
                COVER_MANAGER.set_cover(self.__track, db_string, self.cover_data)
示例#13
0
    def on_track_tags_changed(self, e, track, tag):
        """
            Updates the displayed cover upon tag changes
        """
        if self.__track == track:
            cover_data = COVER_MANAGER.get_cover(track)

            if not cover_data:
                return

            GLib.idle_add(self.on_cover_chosen, None, cover_data)
示例#14
0
    def do_drag_data_received(self, context, x, y, selection, info, time):
        """
            Sets the cover based on the dragged data
        """
        if self.__track is not None:
            uri = selection.get_uris()[0]
            db_string = "localfile:%s" % uri

            try:
                stream = gio.File(uri).read()
            except gio.Error:
                return

            self.cover_data = stream.read()
            width = settings.get_option("gui/cover_width", 100)
            pixbuf = icons.MANAGER.pixbuf_from_data(self.cover_data, (width, width))

            if pixbuf is not None:
                self.image.set_from_pixbuf(pixbuf)
                COVER_MANAGER.set_cover(self.__track, db_string, self.cover_data)
示例#15
0
    def fetch_cover(self):
        """
            Searches for covers for the current track
        """
        db_strings = COVER_MANAGER.find_covers(self.track)

        if db_strings:
            for db_string in db_strings:
                if self.stopper.is_set():
                    return

                coverdata = COVER_MANAGER.get_cover_data(db_string)
                # Pre-render everything for faster display later
                pixbuf = icons.MANAGER.pixbuf_from_data(coverdata)

                if pixbuf:
                    self.covers_model.append(
                        [(db_string, coverdata), pixbuf, pixbuf.scale_simple(50, 50, gtk.gdk.INTERP_BILINEAR)]
                    )

        self.emit("covers-fetched", db_strings)
示例#16
0
    def set_blank(self):
        """
            Sets the default cover to display
        """

        self.drag_dest_unset()

        pixbuf = pixbuf_from_data(COVER_MANAGER.get_default_cover())
        self.image.set_from_pixbuf(pixbuf)
        self.set_drag_source_enabled(False)
        self.cover_data = None

        self.emit('cover-found', None)
示例#17
0
    def set_blank(self):
        """
            Sets the default cover to display
        """

        self.drag_dest_unset()

        pixbuf = icons.MANAGER.pixbuf_from_data(COVER_MANAGER.get_default_cover())
        self.image.set_from_pixbuf(pixbuf)
        self.set_drag_source_enabled(False)
        self.cover_data = None

        self.emit("cover-found", None)
 def _get_cover_url(self, track):
     trackid = track.get_tag_raw('__loc')
     if trackid not in self.cover_cache:
         cover_data = cover_manager.get_cover(track)
         if cover_data is not None:
             dir = os.path.expanduser('~/.cache/exaile')
             cover_temp = tempfile.NamedTemporaryFile(prefix='exaile-soundmenu', dir=dir, delete=False)
             cover_temp.write(cover_data)
             cover_temp.close()
             self.cover_cache[trackid] = "file://"+cover_temp.name
         else:
             return None
     return self.cover_cache[trackid]
示例#19
0
    def __init__(self, parent, collection):
        """
            Initializes the window
        """
        GObject.GObject.__init__(self)

        # List of identifiers of albums without covers
        self.outstanding = []
        # Map of album identifiers and their tracks
        self.album_tracks = {}

        self.outstanding_text = _('{outstanding} covers left to fetch')
        self.completed_text = _('All covers fetched')
        self.cover_size = (90, 90)
        self.default_cover_pixbuf = icons.MANAGER.pixbuf_from_data(
            COVER_MANAGER.get_default_cover(), self.cover_size)

        builder = Gtk.Builder()
        builder.add_from_file(xdg.get_data_path('ui', 'covermanager.ui'))
        builder.connect_signals(self)

        self.window = builder.get_object('window')
        self.window.set_transient_for(parent)

        self.message = dialogs.MessageBar(
            parent=builder.get_object('content_area'),
            buttons=Gtk.ButtonsType.CLOSE
        )

        self.previews_box = builder.get_object('previews_box')
        self.model = builder.get_object('covers_model')
        # Map of album identifiers and model paths
        self.model_path_cache = {}
        self.menu = CoverMenu(self)
        self.menu.attach_to_widget(self.previews_box, lambda menu, widget: True)

        self.progress_bar = builder.get_object('progressbar')
        self.progress_bar.set_text(_('Collecting albums and covers...'))
        self.progress_bar.pulse_timeout = \
            GLib.timeout_add(100, self.on_progress_pulse_timeout)
        self.close_button = builder.get_object('close_button')
        self.stop_button = builder.get_object('stop_button')
        self.stop_button.set_sensitive(False)
        self.fetch_button = builder.get_object('fetch_button')

        self.window.show_all()

        self.stopper = threading.Event()
        thread = threading.Thread(target=self.prefetch, name='CoverPrefetch', args=(collection,))
        thread.daemon = True
        thread.start()
 def _get_cover_url(self, track):
     trackid = track.get_tag_raw('__loc')
     trackhash = hashlib.sha1(trackid).hexdigest()
     if trackid not in self.cover_cache:
         cover_data = cover_manager.get_cover(track)
         if cover_data is not None:
             tempfile = os.path.join(xdg.get_cache_dir(), "cover-%s" % trackhash)
             try:
                 with open(tempfile, 'wb') as f:
                     f.write(cover_data)
             except BaseException as ex:
                 logger.error("Unable to export cover: %r" % ex)
                 return None
             self.cover_cache[trackid] = "file://%s" % tempfile
         else:
             return None
     return self.cover_cache[trackid]
示例#21
0
    def show_cover(self):
        """
            Shows the currently selected cover
        """
        paths = self.previews_box.get_selected_items()

        if paths:
            path = paths[0]
            album = self.model[path][0]
            track = self.album_tracks[album][0]  # Arbitrary track in album
            cover_data = COVER_MANAGER.get_cover(track, set_only=True)
            cover_pixbuf = icons.MANAGER.pixbuf_from_data(cover_data) if cover_data else None

            # Do not bother showing the dialog if there is no cover
            if cover_pixbuf:
                savedir = gio.File(track.get_loc_for_io()).get_parent()
                if savedir:
                    savedir = savedir.get_path()
                cover_window = CoverWindow(self.window, cover_pixbuf, album[1], savedir)
                cover_window.show_all()
示例#22
0
文件: cover.py 项目: unkie/exaile
    def show_cover(self):
        """
        Shows the currently selected cover
        """
        paths = self.previews_box.get_selected_items()

        if paths:
            path = paths[0]
            album = self.model[path][0]
            track = self.album_tracks[album][0]  # Arbitrary track in album
            cover_data = COVER_MANAGER.get_cover(track, set_only=True)
            cover_pixbuf = pixbuf_from_data(cover_data) if cover_data else None

            # Do not bother showing the dialog if there is no cover
            if cover_pixbuf:
                savedir = Gio.File.new_for_uri(track.get_loc_for_io()).get_parent()
                if savedir:
                    savedir = savedir.get_path()
                cover_window = CoverWindow(self.window, cover_pixbuf, album[1], savedir)
                cover_window.show_all()
示例#23
0
 def remove_cover(self):
     """
         Removes the cover for the current track from the database
     """
     COVER_MANAGER.remove_cover(self.__track)
     self.set_blank()
示例#24
0
 def remove_cover(self):
     """
         Removes the cover for the current track from the database
     """
     COVER_MANAGER.remove_cover(self.__track)
     self.set_blank()