static void
resolve_album_art (ResolveData         *resolve_data,
                   resolution_flags_t   flags)
{
  const gchar *artist, *album;
  GCancellable *cancellable = NULL;
  GFile *cache_file = NULL;

  resolve_data_start_operation (resolve_data, "album-art");

  artist = grl_media_audio_get_artist (GRL_MEDIA_AUDIO (resolve_data->rs->media));
  album = grl_media_audio_get_album (GRL_MEDIA_AUDIO (resolve_data->rs->media));

  if (!artist || !album)
    goto done;

  cancellable = resolve_data_ensure_cancellable (resolve_data);

  media_art_get_file (artist, album, "album", &cache_file);

  if (cache_file) {
    /* Check whether the cache file exists. */
    resolve_data_start_operation (resolve_data, "album-art");
    g_file_query_info_async (cache_file, G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
                             G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT,
                             cancellable, resolve_album_art_cb, resolve_data);
  } else {
    GRL_DEBUG ("Found no thumbnail for artist %s and album %s", artist, album);
  }

done:
  resolve_data_finish_operation (resolve_data, "album-art", NULL);

  g_clear_object (&cache_file);
}
Exemple #2
0
/**
 * media_art_get_path:
 * @artist: (allow-none): the artist
 * @title: (allow-none): the title
 * @prefix: (allow-none): the prefix, for example "album"
 * @cache_path: (out) (transfer full) (allow-none): a string
 * representing the path to the cache for this media art
 * path or %NULL
 *
 * This function calls media_art_get_file() by creating a #GFile for
 * @uri and passing the same arguments to media_art_get_file(). For more
 * details about what this function does, see media_art_get_file().
 *
 * Get the path to media art for a given resource. Newly allocated
 * data returned in @cache_path must be freed with g_free().
 *
 * Returns: %TRUE if @cache_path was returned, otherwise %FALSE.
 *
 * Since: 0.2.0
 */
gboolean
media_art_get_path (const gchar  *artist,
                    const gchar  *title,
                    const gchar  *prefix,
                    gchar       **cache_path)
{
	GFile *cache_file = NULL;

	/* Rules:
	 * 1. artist OR title must be non-NULL.
	 * 2. cache_file must be non-NULL
	 */
	g_return_val_if_fail (artist != NULL || title != NULL, FALSE);
	g_return_val_if_fail (cache_path != NULL, FALSE);

	media_art_get_file (artist, title, prefix, cache_path ? &cache_file : NULL);
	if (cache_path) {
		*cache_path = cache_file ? g_file_get_path (cache_file) : NULL;
	}

	return TRUE;
}