[easytag/wip/musicbrainz-support-merge: 3/3] ApplyTAGs also add Disc and Track Tags



commit 4faa16602671cd75caf79e2c0e5af96679b2bf91
Author: Abhinav <abhijangda hotmail com>
Date:   Thu Aug 14 21:12:02 2014 +0530

    ApplyTAGs also add Disc and Track Tags

 src/mb_search.c          |   37 ++++++++-
 src/mb_search.h          |    4 +
 src/musicbrainz_dialog.c |  213 ++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 216 insertions(+), 38 deletions(-)
---
diff --git a/src/mb_search.c b/src/mb_search.c
index d457363..0d2e2a7 100755
--- a/src/mb_search.c
+++ b/src/mb_search.c
@@ -327,7 +327,8 @@ et_musicbrainz_search_in_entity (MbEntityKind child_type,
                 Mb5Release release;
                 release = mb5_metadata_get_release (metadata);
                 list = mb5_release_get_mediumlist (release);
-                param_values[0] = "releases artists artist-credits release-groups";
+                param_values[0] = "releases artists artist-credits" 
+                                  " release-groups mediums artist-rels";
 
                 for (i = 0; i < mb5_medium_list_size (list); i++)
                 {
@@ -465,6 +466,35 @@ et_musicbrainz_search_in_entity (MbEntityKind child_type,
     return FALSE;
 }
 
+int
+et_mb5_recording_get_medium_track_for_release (Mb5Release release, 
+                                               int **discids, int **trackids,
+                                               int *disccount, int **trackcount)
+{
+    Mb5MediumList medium_list;
+    int i;
+
+    medium_list = mb5_release_get_mediumlist (release);
+    *discids = g_malloc (sizeof (int) * mb5_medium_list_size (medium_list));
+    *trackids = g_malloc (sizeof (int) * mb5_medium_list_size (medium_list));
+    *trackcount = g_malloc (sizeof (int) * mb5_medium_list_size (medium_list));
+    *disccount = mb5_medium_list_get_count (medium_list);
+
+    for (i = 0; i < mb5_medium_list_size (medium_list); i++)
+    {
+        Mb5Medium medium;
+        Mb5TrackList track_list;
+
+        medium = mb5_medium_list_item (medium_list, i);
+        track_list = mb5_medium_get_tracklist (medium);
+        (*discids)[i] = mb5_medium_get_position (medium);
+        (*trackids)[i] = mb5_track_get_position (mb5_track_list_item (track_list, 0));
+        (*trackcount)[i] = mb5_track_list_get_count (track_list);
+    }
+
+    return i;
+}
+
 /*
  * et_musicbrainz_set_error_from_query:
  * @query: Query
@@ -884,7 +914,8 @@ et_musicbrainz_search_track (gchar *string, GNode *root, int offset,
 
             list = mb5_metadata_get_recordinglist (metadata);
             param_names[0] = "inc";
-            param_values[0] = "releases artists artist-credits release-groups";
+            param_values[0] = "releases artists artist-credits release-groups"
+                              "  mediums artist-rels";
             message = g_strdup_printf (ngettext (_("Found %d Track"),
                                        _("Found %d Tracks"),
                                        mb5_recording_list_size (list)),
@@ -1316,7 +1347,7 @@ free_mb_tree (GNode **_node)
         {
             mb5_recording_delete ((Mb5Recording)et_entity->entity);
         }
-    
+
         g_slice_free (EtMbEntity, et_entity);
     }
 
diff --git a/src/mb_search.h b/src/mb_search.h
index 195499e..1b2318c 100755
--- a/src/mb_search.h
+++ b/src/mb_search.h
@@ -125,6 +125,10 @@ gchar *
 et_mb5_release_get_artists_names (Mb5Release release);
 gchar *
 et_mb5_recording_get_artists_names (Mb5Recording recording);
+int
+et_mb5_recording_get_medium_track_for_release (Mb5Release release,
+                                               int **discids, int **trackids,
+                                               int *disccount, int **trackcount);
 void
 free_mb_tree (GNode **node);
 void
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index 3fc8e28..7fd7411 100755
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -66,6 +66,10 @@ enum TagChoiceColumns
     TAG_CHOICE_ALBUM_ARTIST,
     TAG_CHOICE_DATE,
     TAG_CHOICE_COUNTRY,
+    TAG_CHOICE_DISC_NUMBER,
+    TAG_CHOICE_DISC_TOTAL,
+    TAG_CHOICE_TRACK_NUMBER,
+    TAG_CHOICE_TRACK_TOTAL,
     TAG_CHOICE_COLS_N
 };
 
@@ -303,7 +307,8 @@ btn_automatic_search_clicked (GtkWidget *button, gpointer data);
 static void
 et_set_file_tag (ET_File *et_file, gchar *title, gchar *artist,
                  gchar *album, gchar *album_artist, gchar *date,
-                 gchar *country);
+                 gchar *country, gchar *disc, gchar *track,
+                 gchar *disc_total, gchar *track_total);
 static void
 btn_apply_changes_clicked (GtkWidget *widget, gpointer data);
 static void
@@ -1704,7 +1709,8 @@ btn_automatic_search_clicked (GtkWidget *btn, gpointer data)
 static void
 et_set_file_tag (ET_File *et_file, gchar *title, gchar *artist,
                  gchar *album, gchar *album_artist, gchar *date,
-                 gchar *country)
+                 gchar *country, gchar *disc, gchar *track,
+                 gchar *disc_total, gchar *track_total)
 {
     File_Tag *file_tag;
 
@@ -1715,6 +1721,11 @@ et_set_file_tag (ET_File *et_file, gchar *title, gchar *artist,
     ET_Set_Field_File_Tag_Item (&file_tag->album, album);
     ET_Set_Field_File_Tag_Item (&file_tag->album_artist, album_artist);
     ET_Set_Field_File_Tag_Item (&file_tag->year, date);
+    ET_Set_Field_File_Tag_Item (&file_tag->track_total, track_total);
+    ET_Set_Field_File_Tag_Item (&file_tag->disc_total, disc_total);
+    ET_Set_Field_File_Tag_Item (&file_tag->track, track);
+    ET_Set_Field_File_Tag_Item (&file_tag->disc_number, disc);
+    printf ("%s %s\n", track_total, disc_total);
     ET_Manage_Changes_Of_File_Data (et_file, NULL, file_tag);
     ET_Display_File_Data_To_UI (ETCore->ETFileDisplayed);
 }
@@ -1868,6 +1879,7 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
                                ET_File *et_file)
 {
     int size;
+    int i;
     Mb5ReleaseList *release_list;
     gchar title[NAME_MAX_SIZE];
     gchar *album_artist;
@@ -1875,6 +1887,10 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
     gchar date[NAME_MAX_SIZE];
     gchar country[NAME_MAX_SIZE];
     gchar *artist;
+    gchar *disc;
+    gchar *track;
+    gchar *track_total;
+    gchar *disc_total;
     GtkTreeIter iter;
     GtkTreeSelection *selection;
     GtkWidget *tag_choice_tree_view;
@@ -1882,7 +1898,15 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
     EtMusicBrainzDialog *dlg;
     Mb5Release release;
     gchar *tag_choice_title;
-
+    int *discids;
+    int *trackids;
+    int n_disc;
+    int *track_count;
+    int disc_count;
+
+    discids = NULL;
+    trackids = NULL;
+    track_count = NULL;
     dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
     mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
     artist = et_mb5_recording_get_artists_names (recording);
@@ -1892,8 +1916,76 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
                                     sizeof (title));
     title[size] = '\0';
     size = mb5_release_list_size (release_list);
+    release = NULL;
+
+    if (album_entity)
+    {
+        gchar id[NAME_MAX_SIZE];
+        
+        mb5_release_get_id (album_entity->entity, id, sizeof (id));
+
+        for (i = 0; i < size; i++)
+        {
+            gchar id1[NAME_MAX_SIZE];
+            
+            mb5_release_get_id (mb5_release_list_item (release_list, i), 
+                                id1, sizeof (id1));
+            if (g_strcmp0 (id1, id) == 0)
+            {
+                release = mb5_release_list_item (release_list, i);
+                break;
+            }
+        }
+    }
 
-    if (!album_entity && size > 1)
+    if (release || size == 1)
+    {
+        if (!release)
+        {
+            release = mb5_release_list_item (release_list, 0);
+        }
+
+        n_disc = et_mb5_recording_get_medium_track_for_release (release, 
+                                                                &discids, &trackids,
+                                                                &disc_count,
+                                                                &track_count);
+        /* As it is a 1-1 relationship so, one track with one recording */
+        mb5_release_get_title (release, album, sizeof (album));
+        album_artist = et_mb5_release_get_artists_names (release);
+        mb5_release_get_date (release, date, sizeof (date));
+        mb5_release_get_country (release, country, sizeof (country));
+
+        if (n_disc != 0)
+        {
+            disc_total = g_strdup_printf ("%d", disc_count);
+            track_total = g_strdup_printf ("%d", *track_count);
+            disc = g_strdup_printf ("%d", *discids);
+            track = g_strdup_printf ("%d", *trackids);
+            et_set_file_tag (et_file, title, artist,
+                             album, album_artist,
+                             date, country, disc, track,
+                             disc_total, track_total);
+            g_free (discids);
+            g_free (trackids);
+            g_free (disc);
+            g_free (track);
+            g_free (disc_total);
+            g_free (track_total);
+            g_free (track_count);
+        }
+        else
+        {
+            et_set_file_tag (et_file, title, artist,
+                             album, album_artist,
+                             date, country, "", "", "", "");
+        }
+
+        g_free (album_artist);
+        g_free (artist);
+
+        return TRUE;
+    }
+    else
     {
         /* More than one releases show Dialog and let user decide */
  
@@ -1904,16 +1996,45 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
             album_artist = et_mb5_release_get_artists_names (release);
             mb5_release_get_date (release, date, sizeof (date));
             mb5_release_get_country (release, country, sizeof (country));
+            n_disc = et_mb5_recording_get_medium_track_for_release (release, 
+                                                                    &discids, &trackids,
+                                                                    &disc_count,
+                                                                    &track_count);
+            for (i = 0; i < n_disc; i++)
+            {
+                disc_total = g_strdup_printf ("%d", disc_count);
+                track_total = g_strdup_printf ("%d", *track_count);
+                disc = g_strdup_printf ("%d", *discids);
+                track = g_strdup_printf ("%d", *trackids);
+                gtk_list_store_insert_with_values (GTK_LIST_STORE (mb_dialog_priv->tag_choice_store),
+                                                   &iter, -1,
+                                                   TAG_CHOICE_TITLE, title,
+                                                   TAG_CHOICE_ALBUM, album,
+                                                   TAG_CHOICE_ARTIST, artist,
+                                                   TAG_CHOICE_ALBUM_ARTIST, 
+                                                   album_artist,
+                                                   TAG_CHOICE_DATE, date,
+                                                   TAG_CHOICE_COUNTRY, 
+                                                   country,
+                                                   TAG_CHOICE_DISC_NUMBER, 
+                                                   disc,
+                                                   TAG_CHOICE_DISC_TOTAL,
+                                                   disc_total,
+                                                   TAG_CHOICE_TRACK_NUMBER, 
+                                                   track,
+                                                   TAG_CHOICE_TRACK_TOTAL,
+                                                   track_total,
+                                                   -1);
+                g_free (disc_total);
+                g_free (track_total);
+                g_free (disc);
+                g_free (track);
+            }
 
-            gtk_list_store_insert_with_values (GTK_LIST_STORE (mb_dialog_priv->tag_choice_store),
-                                               &iter, -1,
-                                               TAG_CHOICE_TITLE, title,
-                                               TAG_CHOICE_ALBUM, album,
-                                               TAG_CHOICE_ARTIST, artist,
-                                               TAG_CHOICE_ALBUM_ARTIST, album_artist,
-                                               TAG_CHOICE_DATE, date,
-                                               TAG_CHOICE_COUNTRY, country, -1);
+            g_free (discids);
+            g_free (trackids);    
             g_free (album_artist);
+            g_free (track_count);
         }
 
         gtk_widget_set_size_request (mb_dialog_priv->tag_choice_dialog,
@@ -1950,15 +2071,24 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
                                 TAG_CHOICE_ALBUM_ARTIST,&ret_album_artist,
                                 TAG_CHOICE_DATE, &ret_date,
                                 TAG_CHOICE_COUNTRY, &ret_country,
+                                TAG_CHOICE_DISC_NUMBER, &disc,
+                                TAG_CHOICE_DISC_TOTAL, &disc_total,
+                                TAG_CHOICE_TRACK_NUMBER, &track,
+                                TAG_CHOICE_TRACK_TOTAL, &track_total,
                                 -1);
             et_set_file_tag (et_file, title, artist,
                              ret_album, ret_album_artist,
-                             ret_date, ret_country);
+                             ret_date, ret_country, disc, track, disc_total, 
+                             track_total);
             g_free (ret_album);
             g_free (ret_album_artist);
             g_free (ret_date);
             g_free (ret_country);
             g_free (artist);
+            g_free (disc_total);
+            g_free (track_total);
+            g_free (disc);
+            g_free (track);
     
             gtk_widget_hide (mb_dialog_priv->tag_choice_dialog);
             gtk_list_store_clear (GTK_LIST_STORE (mb_dialog_priv->tag_choice_store));
@@ -1974,28 +2104,7 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
     
             return FALSE;
         }
-    }
-
-    if (!album_entity)
-    {
-        release = mb5_release_list_item (release_list, 0);
-    }
-    else
-    {
-        release = album_entity->entity;
-    }
-
-    mb5_release_get_title (release, album, sizeof (album));
-    album_artist = et_mb5_release_get_artists_names (release);
-    mb5_release_get_date (release, date, sizeof (date));
-    mb5_release_get_country (release, country, sizeof (country));
-    et_set_file_tag (et_file, title, artist,
-                     album, album_artist,
-                     date, country);
-    g_free (album_artist);
-    g_free (artist);
-
-    return TRUE;
+    }    
 }
 
 /*
@@ -2049,6 +2158,8 @@ et_initialize_tag_choice_dialog (EtMusicBrainzDialogPrivate *mb_dialog_priv)
     list_store = gtk_list_store_new (TAG_CHOICE_COLS_N, G_TYPE_STRING,
                                      G_TYPE_STRING, G_TYPE_STRING,
                                      G_TYPE_STRING, G_TYPE_STRING,
+                                     G_TYPE_STRING, G_TYPE_STRING,
+                                     G_TYPE_STRING, G_TYPE_STRING,
                                      G_TYPE_STRING);
     mb_dialog_priv->tag_choice_store = GTK_TREE_MODEL (list_store);
     gtk_tree_view_set_model (GTK_TREE_VIEW (tag_choice_list),
@@ -2102,6 +2213,38 @@ et_initialize_tag_choice_dialog (EtMusicBrainzDialogPrivate *mb_dialog_priv)
                                                        NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_list),
                                  column);
+    
+    renderer = gtk_cell_renderer_text_new ();
+    column = gtk_tree_view_column_new_with_attributes ("Disc",
+                                                       renderer, "text",
+                                                       TAG_CHOICE_DISC_NUMBER,
+                                                       NULL);
+    gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_list),
+                                 column);
+    
+    renderer = gtk_cell_renderer_text_new ();
+    column = gtk_tree_view_column_new_with_attributes ("Disc Total",
+                                                       renderer, "text",
+                                                       TAG_CHOICE_DISC_TOTAL,
+                                                       NULL);
+    gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_list),
+                                 column);
+
+    renderer = gtk_cell_renderer_text_new ();
+    column = gtk_tree_view_column_new_with_attributes ("Track",
+                                                       renderer, "text",
+                                                       TAG_CHOICE_TRACK_NUMBER,
+                                                       NULL);
+    gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_list),
+                                 column);
+    
+    renderer = gtk_cell_renderer_text_new ();
+    column = gtk_tree_view_column_new_with_attributes ("Track Total",
+                                                       renderer, "text",
+                                                       TAG_CHOICE_TRACK_TOTAL,
+                                                       NULL);
+    gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_list),
+                                 column);
 }
 
 gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]