Guest User

Untitled

a guest
Feb 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.13 KB | None | 0 0
  1.  
  2. gboolean
  3. tracker_is_albumart (const gchar *filename)
  4. {
  5.     gchar *name_utf8, *name_strdown, *dirname;
  6.     GDir *dir;
  7.     GFile *file, *dirf;
  8.     GError *error = NULL;
  9.     const gchar *name;
  10.     const gchar *options[5] = { "cover", "front", "folder", "albumart", NULL };
  11.     guint i, count = 0;
  12.     gboolean is_ok = FALSE;
  13.  
  14.     name_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
  15.  
  16.     if (!name_utf8) {
  17.         g_debug ("Could not convert filename '%s' to UTF-8", filename);
  18.         return FALSE;
  19.     }
  20.  
  21.     name_strdown = g_utf8_strdown (name_utf8, -1);
  22.  
  23.     if (strstr (name_strdown, ".mediaartlocal") != NULL) {
  24.         g_free (name_strdown);
  25.         g_free (name_utf8);
  26.         return TRUE;
  27.     }
  28.  
  29.     for (i = 0; options[i] != NULL; i++) {
  30.         if (strstr (name_strdown, options[i])) {
  31.             is_ok = TRUE;
  32.             continue;
  33.         }
  34.     }
  35.  
  36.     g_free (name_strdown);
  37.     g_free (name_utf8);
  38.  
  39.     if (!is_ok) {
  40.         return FALSE;
  41.     }
  42.  
  43.     file = g_file_new_for_path (filename);
  44.     dirf = g_file_get_parent (file);
  45.     if (dirf) {
  46.         dirname = g_file_get_path (dirf);
  47.         g_object_unref (dirf);
  48.     }
  49.     g_object_unref (file);
  50.  
  51.     if (!dirname) {
  52.         g_debug ("Album art directory could not be used:'%s'", dirname);
  53.         return FALSE;
  54.     }
  55.  
  56.     dir = g_dir_open (dirname, 0, &error);
  57.  
  58.     if (!dir) {
  59.         g_debug ("Album art directory could not be opened:'%s', %s",
  60.                  dirname,
  61.                  error ? error->message : "no error given");
  62.         g_clear_error (&error);
  63.         g_free (dirname);
  64.         return FALSE;
  65.     }
  66.  
  67.     for (name = g_dir_read_name (dir), count = 0;
  68.          name != NULL && count < 50;
  69.          name = g_dir_read_name (dir)) {
  70.         gchar *full = g_build_filename (dirname, name, NULL);
  71.         GFileInfo *info;
  72.  
  73.         file = g_file_new_for_path (full);
  74.         info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
  75.                                   G_FILE_QUERY_INFO_NONE, NULL, NULL);
  76.  
  77.         if (g_str_has_prefix (g_file_info_get_content_type (info), "audio/") ||
  78.             g_str_has_prefix (g_file_info_get_content_type (info), "video/")) {
  79.             count++;
  80.         }
  81.  
  82.         g_object_unref (info);
  83.         g_object_unref (file);
  84.         g_free (full);
  85.     }
  86.  
  87.     g_dir_close (dir);
  88.  
  89.     if (count == 0 || count >= 50) {
  90.         return FALSE;
  91.     }
  92.  
  93.     return TRUE;
  94. }
Add Comment
Please, Sign In to add comment