Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gboolean
- tracker_is_albumart (const gchar *filename)
- {
- gchar *name_utf8, *name_strdown, *dirname;
- GDir *dir;
- GFile *file, *dirf;
- GError *error = NULL;
- const gchar *name;
- const gchar *options[5] = { "cover", "front", "folder", "albumart", NULL };
- guint i, count = 0;
- gboolean is_ok = FALSE;
- name_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
- if (!name_utf8) {
- g_debug ("Could not convert filename '%s' to UTF-8", filename);
- return FALSE;
- }
- name_strdown = g_utf8_strdown (name_utf8, -1);
- if (strstr (name_strdown, ".mediaartlocal") != NULL) {
- g_free (name_strdown);
- g_free (name_utf8);
- return TRUE;
- }
- for (i = 0; options[i] != NULL; i++) {
- if (strstr (name_strdown, options[i])) {
- is_ok = TRUE;
- continue;
- }
- }
- g_free (name_strdown);
- g_free (name_utf8);
- if (!is_ok) {
- return FALSE;
- }
- file = g_file_new_for_path (filename);
- dirf = g_file_get_parent (file);
- if (dirf) {
- dirname = g_file_get_path (dirf);
- g_object_unref (dirf);
- }
- g_object_unref (file);
- if (!dirname) {
- g_debug ("Album art directory could not be used:'%s'", dirname);
- return FALSE;
- }
- dir = g_dir_open (dirname, 0, &error);
- if (!dir) {
- g_debug ("Album art directory could not be opened:'%s', %s",
- dirname,
- error ? error->message : "no error given");
- g_clear_error (&error);
- g_free (dirname);
- return FALSE;
- }
- for (name = g_dir_read_name (dir), count = 0;
- name != NULL && count < 50;
- name = g_dir_read_name (dir)) {
- gchar *full = g_build_filename (dirname, name, NULL);
- GFileInfo *info;
- file = g_file_new_for_path (full);
- info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- G_FILE_QUERY_INFO_NONE, NULL, NULL);
- if (g_str_has_prefix (g_file_info_get_content_type (info), "audio/") ||
- g_str_has_prefix (g_file_info_get_content_type (info), "video/")) {
- count++;
- }
- g_object_unref (info);
- g_object_unref (file);
- g_free (full);
- }
- g_dir_close (dir);
- if (count == 0 || count >= 50) {
- return FALSE;
- }
- return TRUE;
- }
Add Comment
Please, Sign In to add comment