Esempio n. 1
0
    def _splice_callback(self, src, result, data):
        tmp_file, iostream = data

        iostream.close_async(GLib.PRIORITY_LOW, None,
                             self._close_iostream_callback, None)

        try:
            src.splice_finish(result)
        except GLib.Error as error:
            self._log.warning("Error: {}, {}".format(error.domain,
                                                     error.message))
            self._coreobject.props.thumbnail = "generic"
            return

        if isinstance(self._coreobject, CoreArtist):
            success, cache_file = MediaArt.get_file(
                self._coreobject.props.artist, None, "artist")
        elif isinstance(self._coreobject, CoreAlbum):
            success, cache_file = MediaArt.get_file(
                self._coreobject.props.artist, self._coreobject.props.title,
                "album")
        elif isinstance(self._coreobject, CoreSong):
            success, cache_file = MediaArt.get_file(
                self._coreobject.props.artist, self._coreobject.props.album,
                "album")
        else:
            success = False

        if not success:
            self._coreobject.props.thumbnail = "generic"
            return

        try:
            # FIXME: I/O blocking
            MediaArt.file_to_jpeg(tmp_file.get_path(), cache_file.get_path())
        except GLib.Error as error:
            self._log.warning("Error: {}, {}".format(error.domain,
                                                     error.message))
            self._coreobject.props.thumbnail = "generic"
            return

        self._coreobject.props.media.set_thumbnail(cache_file.get_uri())
        self._coreobject.props.thumbnail = cache_file.get_uri()

        tmp_file.delete_async(GLib.PRIORITY_LOW, None, self._delete_callback,
                              None)
Esempio n. 2
0
    def _in_cache(self):
        success, thumb_file = MediaArt.get_file(self._artist, None, "artist")
        if (not success or not thumb_file.query_exists()):
            return False

        self._coreartist.props.cached_thumbnail_uri = thumb_file.get_path()

        return True
Esempio n. 3
0
    def _in_cache(self):
        success, thumb_file = MediaArt.get_file(self._artist, None, "artist")
        if (not success or not thumb_file.query_exists()):
            self._coreartist.props.thumbnail = "loading"
            return False

        self._coreartist.props.thumbnail = thumb_file.get_uri()

        return True
    def _lookup_local(self, item, callback, itr, art_size):
        """Checks if there is already a local art file, if not calls
        the remote lookup function"""
        album = utils.get_album_title(item)
        artist = utils.get_artist_name(item)

        def stream_open(thumb_file, result, arguments):
            try:
                stream = thumb_file.read_finish(result)
            except Exception as err:
                logger.warn("Error: %s, %s", err.__class__, err)
                do_callback(None)
                return

            GdkPixbuf.Pixbuf.new_from_stream_async(stream, None, pixbuf_loaded,
                                                   None)

        def pixbuf_loaded(stream, result, data):
            try:
                pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(result)
            except Exception as err:
                logger.warn("Error: %s, %s", err.__class__, err)
                do_callback(None)
                return

            do_callback(pixbuf)
            return

        def do_callback(pixbuf):
            if not pixbuf:
                surface = DefaultIcon(self._scale).get(DefaultIcon.Type.music,
                                                       art_size)
            else:
                surface = _make_icon_frame(pixbuf, art_size, self._scale)

                # Sets the thumbnail location for MPRIS to use.
                item.set_thumbnail(
                    GLib.filename_to_uri(thumb_file.get_path(), None))

            GLib.idle_add(callback, surface, itr)
            return

        success, thumb_file = MediaArt.get_file(artist, album, "album")

        if (success and thumb_file.query_exists()):
            thumb_file.read_async(GLib.PRIORITY_LOW, None, stream_open, None)
            return

        stripped_album = MediaArt.strip_invalid_entities(album)
        if (artist in self.blacklist
                and stripped_album in self.blacklist[artist]):
            do_callback(None)
            return

        self._lookup_remote(item, callback, itr, art_size)
Esempio n. 5
0
    def _set_grilo_thumbnail_path(self):
        # TODO: This sets the thumbnail path for the Grilo Media object
        # to be used by MPRIS. However, calling this by default for
        # every cache hit is unnecessary.
        album = utils.get_album_title(self._media)
        artist = utils.get_artist_name(self._media)

        success, thumb_file = MediaArt.get_file(artist, album, "album")
        if success:
            self._media.set_thumbnail(
                GLib.filename_to_uri(thumb_file.get_path(), None))
Esempio n. 6
0
    def _set_grilo_thumbnail_path(self):
        # TODO: This sets the thumbnail path for the Grilo Media object
        # to be used by MPRIS. However, calling this by default for
        # every cache hit is unnecessary.
        album = utils.get_album_title(self._media)
        artist = utils.get_artist_name(self._media)

        success, thumb_file = MediaArt.get_file(artist, album, "album")
        if success:
            self._media.set_thumbnail(
                GLib.filename_to_uri(thumb_file.get_path(), None))
Esempio n. 7
0
def lookup_art_file_from_cache(media):
    """Lookup MediaArt cache art of an album or song.

    :param Grl.Media media: song or album
    :returns: a cache file
    :rtype: Gio.File
    """
    album = utils.get_album_title(media)
    artist = utils.get_artist_name(media)

    success, thumb_file = MediaArt.get_file(artist, album, "album")
    if (not success or not thumb_file.query_exists()):
        return None

    return thumb_file
Esempio n. 8
0
    def query(self, media):
        """Start the cache query

        :param Grl.Media media: The media object to search art for
        """
        album = utils.get_album_title(media)
        artist = utils.get_artist_name(media)

        success, thumb_file = MediaArt.get_file(artist, album, "album")

        if (success and thumb_file.query_exists()):
            thumb_file.read_async(GLib.PRIORITY_LOW, None, self._open_stream,
                                  None)
            return

        self.emit('miss')
Esempio n. 9
0
    def query(self, media):
        """Start the cache query

        :param Grl.Media media: The media object to search art for
        """
        album = utils.get_album_title(media)
        artist = utils.get_artist_name(media)

        success, thumb_file = MediaArt.get_file(artist, album, "album")

        if (success
                and thumb_file.query_exists()):
            thumb_file.read_async(
                GLib.PRIORITY_LOW, None, self._open_stream, None)
            return

        self.emit('miss')
Esempio n. 10
0
def lookup_art_file_from_cache(coresong):
    """Lookup MediaArt cache art of an album or song.

    :param CoreSong coresong: song or album
    :returns: a cache file
    :rtype: Gio.File
    """
    try:
        album = coresong.props.album
    except AttributeError:
        album = coresong.props.title
    artist = coresong.props.artist

    success, thumb_file = MediaArt.get_file(artist, album, "album")
    if (not success or not thumb_file.query_exists()):
        return None

    return thumb_file
Esempio n. 11
0
    def lookup(self, item, width, height, callback, itr, artist, album, first=True):
        if artist in self.blacklist and album in self.blacklist[artist]:
            self.finish(item, None, None, callback, itr, width, height)
            return

        try:
            [success, thumb_file] = MediaArt.get_file(artist, album, "album")

            if success == False:
                self.finish(item, None, None, callback, itr, width, height)
                return

            if not thumb_file.query_exists():
                if first:
                    self.cached_thumb_not_found(item, width, height, thumb_file.get_path(), callback, itr, artist, album)
                else:
                    self.finish(item, None, None, callback, itr, width, height)
                return

            stream = thumb_file.read_async(GLib.PRIORITY_LOW, None, self.stream_open,
                                           [item, width, height, thumb_file, callback, itr, artist, album])
        except Exception as e:
            logger.warn("Error: %s, %s", e.__class__, e)
Esempio n. 12
0
    def lookup(self, item, width, height, callback, itr, artist, album, first=True):
        if artist in self.blacklist and album in self.blacklist[artist]:
            self.finish(item, None, None, callback, itr, width, height)
            return

        try:
            [success, thumb_file] = MediaArt.get_file(artist, album, "album")

            if success == False:
                self.finish(item, None, None, callback, itr, width, height)
                return

            if not thumb_file.query_exists():
                if first:
                    self.cached_thumb_not_found(item, width, height, thumb_file.get_path(), callback, itr, artist, album)
                else:
                    self.finish(item, None, None, callback, itr, width, height)
                return

            stream = thumb_file.read_async(GLib.PRIORITY_LOW, None, self.stream_open,
                                           [item, width, height, thumb_file, callback, itr, artist, album])
        except Exception as e:
            logger.warn("Error: %s, %s", e.__class__, e)
Esempio n. 13
0
    def _lookup_local(self, item, callback, itr, art_size):
        """Checks if there is already a local art file, if not calls
        the remote lookup function"""
        album = utils.get_album_title(item)
        artist = utils.get_artist_name(item)

        def stream_open(thumb_file, result, arguments):
            try:
                stream = thumb_file.read_finish(result)
            except Exception as err:
                logger.warn("Error: %s, %s", err.__class__, err)
                do_callback(None)
                return

            GdkPixbuf.Pixbuf.new_from_stream_async(stream,
                                                   None,
                                                   pixbuf_loaded,
                                                   None)

        def pixbuf_loaded(stream, result, data):
            try:
                pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(result)
            except Exception as err:
                logger.warn("Error: %s, %s", err.__class__, err)
                do_callback(None)
                return

            do_callback(pixbuf)
            return

        def do_callback(pixbuf):
            if not pixbuf:
                surface = DefaultIcon(self._scale).get(DefaultIcon.Type.music,
                                                       art_size)
            else:
                surface = _make_icon_frame(pixbuf, art_size, self._scale)

                # Sets the thumbnail location for MPRIS to use.
                item.set_thumbnail(GLib.filename_to_uri(thumb_file.get_path(),
                                                        None))

            GLib.idle_add(callback, surface, itr)
            return

        success, thumb_file = MediaArt.get_file(artist, album, "album")

        if (success
                and thumb_file.query_exists()):
            thumb_file.read_async(GLib.PRIORITY_LOW,
                                  None,
                                  stream_open,
                                  None)
            return

        stripped_album = MediaArt.strip_invalid_entities(album)
        if (artist in self.blacklist
                and stripped_album in self.blacklist[artist]):
            do_callback(None)
            return

        self._lookup_remote(item, callback, itr, art_size)