[libmediaart/remove-mediaartlocal-rebased-on-async-api: 4/5] extract, cache: Remove all .mediaartlocal uses
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libmediaart/remove-mediaartlocal-rebased-on-async-api: 4/5] extract, cache: Remove all .mediaartlocal uses
- Date: Fri, 17 Oct 2014 10:26:24 +0000 (UTC)
commit e3daca5cacdf5b91212fccb05ccfa87b03e30b8b
Author: Martyn Russell <martyn lanedo com>
Date: Tue Sep 16 10:05:13 2014 +0100
extract, cache: Remove all .mediaartlocal uses
This is deemed quite useless now and we should not be littering the file
system with .mediaartlocal directories everywhere.
https://bugzilla.gnome.org/show_bug.cgi?id=722795
libmediaart/cache.c | 83 ++++------------------
libmediaart/cache.h | 8 +--
libmediaart/extract.c | 184 ++++---------------------------------------------
tests/mediaarttest.c | 38 +++-------
4 files changed, 43 insertions(+), 270 deletions(-)
---
diff --git a/libmediaart/cache.c b/libmediaart/cache.c
index e89b3ab..ecbc7a1 100644
--- a/libmediaart/cache.c
+++ b/libmediaart/cache.c
@@ -241,29 +241,16 @@ media_art_checksum_for_data (GChecksumType checksum_type,
* @artist: (allow-none): the artist
* @title: (allow-none): the title
* @prefix: (allow-none): the prefix for cache files, for example "album"
- * @file: (allow-none): a #GFile representing the actual media art or %NULL
* @cache_file: (out) (transfer full) (allow-none): a pointer to a
* #GFile which represents the cached file for media art, or %NULL
* a #GFile representing the user's cache path, or %NULL
- * @local_file: (out) (transfer full) (allow-none): a pointer to a
* #GFile representing the location of the local media art
*
* Gets the files pointing to cache files suitable for storing the media
* art provided by the @artist, @title and @file arguments. @cache_file
- * will point to a location in the XDG user cache directory, meanwhile
- * @local_file will point to a cache file that resides in the same
- * filesystem than @file.
- *
- * The @file provided is required if @local_file is to be returned.
- * The @local_file relates to a location on the media the local file
- * system or media storage it is found on, so for example, if you have
- * a mounted volume with MP3s on it in
- * <filename>file:///media/martyn/pendrive</filename>, the @local_file
- * will point to a URI that looks like
- * <filename>file:///media/martyn/pendrive/.mediaartlocal/...</filename>.
- *
- * The @cache_file is very different to the @local_file, the
- * @cache_file relates to a symlink stored in XDG cache directories
+ * will point to a location in the XDG user cache directory..
+ *
+ * The @cache_file relates to a symlink stored in XDG cache directories
* for the user. A @cache_file would be expected to look like
* <filename>file:///home/martyn/.cache/media-art/...</filename>. This
* is normally the location that is most useful (assuming the cache
@@ -275,7 +262,7 @@ media_art_checksum_for_data (GChecksumType checksum_type,
* This operation should not use i/o, but it depends on the backend
* GFile implementation.
*
- * Returns: %TRUE if @cache_file or @local_file were returned, otherwise %FALSE.
+ * Returns: %TRUE if @cache_file was returned, otherwise %FALSE.
*
* Since: 0.2.0
*/
@@ -283,9 +270,7 @@ gboolean
media_art_get_file (const gchar *artist,
const gchar *title,
const gchar *prefix,
- GFile *file,
- GFile **cache_file,
- GFile **local_file)
+ GFile **cache_file)
{
const gchar *space_checksum = "7215ee9c7d9dc229d2921a40e899ec5f";
const gchar *a, *b;
@@ -303,16 +288,12 @@ media_art_get_file (const gchar *artist,
*cache_file = NULL;
}
- if (local_file) {
- *local_file = NULL;
- }
-
/* Rules:
* 1. artist OR title must be non-NULL.
- * 2. file AND local_file must be non-NULL OR cache_file 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 (((!G_IS_FILE (file) && !G_IS_FILE (local_file)) || !G_IS_FILE (cache_file)),
FALSE);
+ g_return_val_if_fail (!G_IS_FILE (cache_file), FALSE);
if (artist) {
artist_stripped = media_art_strip_invalid_entities (artist);
@@ -366,19 +347,6 @@ media_art_get_file (const gchar *artist,
g_free (filename);
}
- if (local_file) {
- GFile *parent;
-
- parent = g_file_get_parent (file);
- if (parent) {
- filename = g_build_filename (".mediaartlocal", art_filename, NULL);
- *local_file = g_file_resolve_relative_path (parent, filename);
- g_free (filename);
-
- g_object_unref (parent);
- }
- }
-
g_free (dir);
g_free (art_filename);
@@ -390,22 +358,18 @@ media_art_get_file (const gchar *artist,
* @artist: (allow-none): the artist
* @title: (allow-none): the title
* @prefix: (allow-none): the prefix, for example "album"
- * @uri: (allow-none): the uri of the file or %NULL
* @cache_path: (out) (transfer full) (allow-none): a string
* representing the path to the cache for this media art
* path or %NULL
- * @local_uri: (out) (transfer full) (allow-none): a string
- * representing the URI to the local media art 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 and @local_uri must be freed with g_free().
+ * data returned in @cache_path must be freed with g_free().
*
- * Returns: %TRUE if @cache_path or @local_uri were returned,
- * otherwise %FALSE.
+ * Returns: %TRUE if @cache_path was returned, otherwise %FALSE.
*
* Since: 0.2.0
*/
@@ -413,38 +377,22 @@ gboolean
media_art_get_path (const gchar *artist,
const gchar *title,
const gchar *prefix,
- const gchar *uri,
- gchar **cache_path,
- gchar **local_uri)
+ gchar **cache_path)
{
- GFile *file = NULL, *cache_file = NULL, *local_file = NULL;
+ GFile *cache_file = NULL;
/* Rules:
* 1. artist OR title must be non-NULL.
- * 2. file AND local_file must be non-NULL OR cache_file 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 ((uri != NULL && local_uri != NULL) || cache_path != NULL, FALSE);
+ g_return_val_if_fail (cache_path != NULL, FALSE);
- if (uri) {
- file = g_file_new_for_uri (uri);
- }
-
- media_art_get_file (artist, title, prefix, file,
- cache_path ? &cache_file : NULL,
- local_uri ? &local_file : NULL);
+ 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;
}
- if (local_uri) {
- *local_uri = local_file ? g_file_get_uri (local_file) : NULL;
- }
-
- if (file) {
- g_object_unref (file);
- }
-
return TRUE;
}
@@ -507,7 +455,8 @@ media_art_remove (const gchar *artist,
gint removed = 0;
/* The get_path API does stripping itself */
- media_art_get_path (artist, album, "album", NULL, &target, NULL);
+ media_art_get_path (artist, album, "album", &target);
+
if (target) {
if (g_unlink (target) != 0) {
g_debug ("Could not delete file '%s'", target);
@@ -522,7 +471,7 @@ media_art_remove (const gchar *artist,
/* Add the album path also (to which the symlinks are made) */
if (album) {
- media_art_get_path (NULL, album, "album", NULL, &target, NULL);
+ media_art_get_path (NULL, album, "album", &target);
if (target) {
if (g_unlink (target) != 0) {
g_debug ("Could not delete file '%s'", target);
diff --git a/libmediaart/cache.h b/libmediaart/cache.h
index be18e04..2bb711c 100644
--- a/libmediaart/cache.h
+++ b/libmediaart/cache.h
@@ -34,15 +34,11 @@ gchar * media_art_strip_invalid_entities (const gchar *original);
gboolean media_art_get_path (const gchar *artist,
const gchar *title,
const gchar *prefix,
- const gchar *uri,
- gchar **cache_path,
- gchar **local_uri);
+ gchar **cache_path);
gboolean media_art_get_file (const gchar *artist,
const gchar *title,
const gchar *prefix,
- GFile *file,
- GFile **cache_file,
- GFile **local_file);
+ GFile **cache_file);
gboolean media_art_remove (const gchar *artist,
const gchar *album,
diff --git a/libmediaart/extract.c b/libmediaart/extract.c
index a82b007..b1bedfa 100644
--- a/libmediaart/extract.c
+++ b/libmediaart/extract.c
@@ -763,7 +763,6 @@ media_art_find_by_artist_and_title (const gchar *uri,
static gboolean
get_heuristic (MediaArtType type,
const gchar *filename_uri,
- const gchar *local_uri,
const gchar *artist,
const gchar *title,
GError **error)
@@ -791,44 +790,7 @@ get_heuristic (MediaArtType type,
media_art_get_path (artist_stripped,
title_stripped,
media_art_type_name[type],
- NULL,
- &target,
- NULL);
-
- /* Copy from local album art (.mediaartlocal) to spec */
- if (local_uri) {
- GFile *local_file, *file;
-
- local_file = g_file_new_for_uri (local_uri);
-
- if (g_file_query_exists (local_file, NULL)) {
- g_debug ("Album art being copied from local (.mediaartlocal) file:'%s'",
- local_uri);
-
- file = g_file_new_for_path (target);
-
- g_file_copy_async (local_file,
- file,
- 0,
- 0,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL);
-
- g_object_unref (file);
- g_object_unref (local_file);
-
- g_free (target);
- g_free (artist_stripped);
- g_free (title_stripped);
-
- return TRUE;
- }
-
- g_object_unref (local_file);
- }
+ &target);
art_file_path = media_art_find_by_artist_and_title (filename_uri,
type,
@@ -890,9 +852,7 @@ get_heuristic (MediaArtType type,
media_art_get_path (NULL,
title_stripped,
media_art_type_name [type],
- NULL,
- &album_art_file_path,
- NULL);
+ &album_art_file_path);
if (is_jpeg) {
gchar *sum2 = NULL;
@@ -1010,9 +970,7 @@ get_heuristic (MediaArtType type,
media_art_get_path (NULL,
title_stripped,
media_art_type_name[type],
- NULL,
- &album_art_file_path,
- NULL);
+ &album_art_file_path);
}
g_debug ("Album art (PNG) found in same directory being used:'%s'", art_file_path);
@@ -1104,9 +1062,7 @@ media_art_set (const unsigned char *buffer,
media_art_get_path (artist,
title,
media_art_type_name[type],
- NULL,
- &local_path,
- NULL);
+ &local_path);
/* 2. If not ALBUM! or artist is unknown:
* i) save buffer to jpeg only.
@@ -1135,9 +1091,7 @@ media_art_set (const unsigned char *buffer,
media_art_get_path (NULL,
title,
media_art_type_name[type],
- NULL,
- &album_path,
- NULL);
+ &album_path);
if (!g_file_test (album_path, G_FILE_TEST_EXISTS)) {
media_art_buffer_to_jpeg (buffer, len, mime, album_path, &local_error);
@@ -1351,7 +1305,6 @@ media_art_set (const unsigned char *buffer,
static FileInfo *
file_info_new (MediaArtProcess *process,
- const gchar *local_uri,
const gchar *art_path)
{
FileInfo *fi;
@@ -1359,7 +1312,6 @@ file_info_new (MediaArtProcess *process,
fi = g_slice_new (FileInfo);
fi->process = g_object_ref (process);
- fi->local_uri = g_strdup (local_uri);
fi->art_path = g_strdup (art_path);
return fi;
@@ -1372,7 +1324,6 @@ file_info_free (FileInfo *fi)
return;
}
- g_free (fi->local_uri);
g_free (fi->art_path);
g_object_unref (fi->process);
@@ -1384,7 +1335,6 @@ media_art_request_download (MediaArtProcess *process,
MediaArtType type,
const gchar *album,
const gchar *artist,
- const gchar *local_uri,
const gchar *art_path)
{
MediaArtProcessPrivate *private;
@@ -1402,7 +1352,7 @@ media_art_request_download (MediaArtProcess *process,
return;
}
- info = file_info_new (process, local_uri, art_path);
+ info = file_info_new (process, art_path);
g_dbus_connection_call (private->connection,
ALBUMARTER_SERVICE,
@@ -1424,70 +1374,6 @@ media_art_request_download (MediaArtProcess *process,
}
static void
-media_art_copy_to_local (MediaArtProcess *process,
- const gchar *filename,
- const gchar *local_uri)
-{
- MediaArtProcessPrivate *private;
- GSList *roots, *l;
- gboolean on_removable_device = FALSE;
- guint flen;
-
- private = media_art_process_get_instance_private (process);
-
- roots = storage_get_device_roots (private->storage, STORAGE_REMOVABLE, FALSE);
- flen = strlen (filename);
-
- for (l = roots; l; l = l->next) {
- guint len;
-
- len = strlen (l->data);
-
- if (flen >= len && strncmp (filename, l->data, len)) {
- on_removable_device = TRUE;
- break;
- }
- }
-
- g_slist_foreach (roots, (GFunc) g_free, NULL);
- g_slist_free (roots);
-
- if (on_removable_device) {
- GFile *local_file, *from;
-
- from = g_file_new_for_path (filename);
- local_file = g_file_new_for_uri (local_uri);
-
- /* We don't try to overwrite, but we also ignore all errors.
- * Such an error could be that the removable device is
- * read-only. Well that's fine then ... ignore */
-
- if (!g_file_query_exists (local_file, NULL)) {
- GFile *dirf;
-
- dirf = g_file_get_parent (local_file);
- if (dirf) {
- /* Parent file may not exist, as if the file is in the
- * root of a gvfs mount. In this case we won't try to
- * create the parent directory, just try to copy the
- * file there. */
- g_file_make_directory_with_parents (dirf, NULL, NULL);
- g_object_unref (dirf);
- }
-
- g_debug ("Copying media art from:'%s' to:'%s'",
- filename, local_uri);
-
- g_file_copy_async (from, local_file, 0, 0,
- NULL, NULL, NULL, NULL, NULL);
- }
-
- g_object_unref (local_file);
- g_object_unref (from);
- }
-}
-
-static void
media_art_queue_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
@@ -1512,18 +1398,12 @@ media_art_queue_cb (GObject *source_object,
g_clear_error (&error);
}
+ /* Do something with downloaded content, e.g. create symlink to actual cache? */
+
if (v) {
g_variant_unref (v);
}
- if (private->storage &&
- fi->art_path &&
- g_file_test (fi->art_path, G_FILE_TEST_EXISTS)) {
- media_art_copy_to_local (fi->process,
- fi->art_path,
- fi->local_uri);
- }
-
file_info_free (fi);
}
@@ -1765,7 +1645,7 @@ media_art_process_buffer (MediaArtProcess *process,
GCancellable *cancellable,
GError **error)
{
- GFile *cache_art_file, *local_art_file;
+ GFile *cache_art_file;
GError *local_error = NULL;
gchar *cache_art_path, *uri;
gboolean processed, created;
@@ -1804,9 +1684,7 @@ media_art_process_buffer (MediaArtProcess *process,
media_art_get_file (artist,
title,
media_art_type_name[type],
- related_file,
- &cache_art_file,
- &local_art_file);
+ &cache_art_file);
cache_mtime = get_mtime (cache_art_file, &local_error);
@@ -1837,16 +1715,11 @@ media_art_process_buffer (MediaArtProcess *process,
local_error->message);
g_free (uri);
- if (local_art_file) {
- g_object_unref (local_art_file);
- }
-
g_propagate_error (error, local_error);
return FALSE;
}
-
cache_art_path = g_file_get_path (cache_art_file);
if (flags & MEDIA_ART_PROCESS_FLAGS_FORCE ||
@@ -1860,29 +1733,10 @@ media_art_process_buffer (MediaArtProcess *process,
processed = TRUE;
}
- if (!g_cancellable_set_error_if_cancelled (cancellable, error)) {
- if (local_art_file && !g_file_query_exists (local_art_file, NULL)) {
- /* We can't reuse art_exists here because the
- * situation might have changed
- */
- if (g_file_query_exists (cache_art_file, NULL)) {
- gchar *local_art_uri;
-
- local_art_uri = g_file_get_uri (local_art_file);
- media_art_copy_to_local (process, cache_art_path, local_art_uri);
- g_free (local_art_uri);
- }
- }
- }
-
if (cache_art_file) {
g_object_unref (cache_art_file);
}
- if (local_art_file) {
- g_object_unref (local_art_file);
- }
-
g_free (cache_art_path);
g_free (uri);
@@ -2037,7 +1891,7 @@ media_art_process_file (MediaArtProcess *process,
GError **error)
{
MediaArtProcessPrivate *private;
- GFile *cache_art_file, *local_art_file;
+ GFile *cache_art_file;
GError *local_error = NULL;
gchar *cache_art_path, *uri;
gboolean no_cache_or_old;
@@ -2077,9 +1931,7 @@ media_art_process_file (MediaArtProcess *process,
media_art_get_file (artist,
title,
media_art_type_name[type],
- file,
- &cache_art_file,
- &local_art_file);
+ &cache_art_file);
cache_art_path = g_file_get_path (cache_art_file);
@@ -2097,11 +1949,7 @@ media_art_process_file (MediaArtProcess *process,
* potentially trying a download operation.
*/
if (!g_cancellable_set_error_if_cancelled (cancellable, error)) {
- gchar *local_art_uri;
-
- local_art_uri = g_file_get_uri (local_art_file);
-
- if (!get_heuristic (type, uri, local_art_uri, artist, title, error)) {
+ if (!get_heuristic (type, uri, artist, title, error)) {
/* If the heuristic failed, we
* request the download the
* media-art to the media-art
@@ -2111,7 +1959,6 @@ media_art_process_file (MediaArtProcess *process,
type,
artist,
title,
- local_art_uri,
cache_art_path);
/* FIXME: Should return TRUE or FALSE? */
@@ -2122,7 +1969,6 @@ media_art_process_file (MediaArtProcess *process,
g_hash_table_insert (private->media_art_cache,
key,
GINT_TO_POINTER(TRUE));
- g_free (local_art_uri);
}
} else {
g_free (key);
@@ -2137,10 +1983,6 @@ media_art_process_file (MediaArtProcess *process,
g_object_unref (cache_art_file);
}
- if (local_art_file) {
- g_object_unref (local_art_file);
- }
-
g_free (cache_art_path);
g_free (uri);
diff --git a/tests/mediaarttest.c b/tests/mediaarttest.c
index f93845c..e7b15d4 100644
--- a/tests/mediaarttest.c
+++ b/tests/mediaarttest.c
@@ -131,15 +131,13 @@ static void
test_mediaart_location (TestInfo *test_info,
gconstpointer context)
{
- gchar *path = NULL, *local_uri = NULL;
+ gchar *path = NULL;
gchar *expected;
media_art_get_path (test_info->input1,
test_info->input2,
"album",
- "file:///home/test/a.mp3",
- &path,
- &local_uri);
+ &path);
expected = g_build_path (G_DIR_SEPARATOR_S,
g_get_user_cache_dir (),
"media-art",
@@ -149,37 +147,32 @@ test_mediaart_location (TestInfo *test_info,
g_free (expected);
g_free (path);
- g_free (local_uri);
}
static void
test_mediaart_location_null (void)
{
- gchar *path = NULL, *local_uri = NULL;
+ gchar *path = NULL;
- /* NULL parameters */
- media_art_get_path (NULL, "some-title", "album", "file:///a/b/c.mp3", &path, &local_uri);
- g_assert (path != NULL);
- g_assert (local_uri != NULL);
+ /* NULL parameters */
+ media_art_get_path (NULL, "some-title", "album", &path);
+ g_assert (path != NULL);
- media_art_get_path ("some-artist", NULL, "album", "file:///a/b/c.mp3", &path, &local_uri);
- g_assert (path != NULL);
- g_assert (local_uri != NULL);
+ media_art_get_path ("some-artist", NULL, "album", &path);
+ g_assert (path != NULL);
}
static void
test_mediaart_location_path (void)
{
- gchar *path = NULL, *local_uri = NULL;
+ gchar *path = NULL;
gchar *expected;
/* Use path instead of URI */
media_art_get_path (location_test_cases[0].input1,
location_test_cases[0].input2,
"album",
- "/home/test/a.mp3",
- &path,
- &local_uri);
+ &path);
expected = g_build_path (G_DIR_SEPARATOR_S,
g_get_user_cache_dir (),
"media-art",
@@ -189,7 +182,6 @@ test_mediaart_location_path (void)
g_free (expected);
g_free (path);
- g_free (local_uri);
}
static void
@@ -329,9 +321,7 @@ test_mediaart_process_buffer_cb (GObject *source_object,
media_art_get_path ("Lanedo", /* artist / title */
NULL, /* album */
NULL, /* prefix */
- path,
- &out_path,
- &out_uri);
+ &out_path);
g_free (path);
g_object_unref (file);
@@ -364,7 +354,6 @@ test_mediaart_process_buffer (void)
GError *error = NULL;
gchar *path;
gchar *out_path = NULL;
- gchar *out_uri = NULL;
unsigned char *buffer = NULL;
size_t length = 0;
const gchar *mime;
@@ -377,12 +366,9 @@ test_mediaart_process_buffer (void)
media_art_get_path ("Lanedo", /* artist / title */
NULL, /* album */
NULL, /* prefix */
- path,
- &out_path,
- &out_uri);
+ &out_path);
g_assert_false (g_file_test (out_path, G_FILE_TEST_EXISTS));
g_free (out_path);
- g_free (out_uri);
process = media_art_process_new (&error);
g_assert_no_error (error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]