[easytag/wip/disc-number: 6/9] Add total discs support to MP3/MP2 tag parser



commit 6f5f1f22d6ca0cacaa584b04049a170edd6e4864
Author: Mathias Reineke <saihtam gmx net>
Date:   Mon Jul 8 10:58:00 2013 +0200

    Add total discs support to MP3/MP2 tag parser

 src/id3_tag.c    |   24 ++++++++++++++++++------
 src/id3v24_tag.c |   35 ++++++++++++++++++++++++++++++++---
 2 files changed, 50 insertions(+), 9 deletions(-)
---
diff --git a/src/id3_tag.c b/src/id3_tag.c
index 35d2adf..7cf8bc0 100644
--- a/src/id3_tag.c
+++ b/src/id3_tag.c
@@ -249,16 +249,28 @@ Id3tag_Write_File_v23Tag (ET_File *ETFile)
     }
 
 
-    /***************
-     * Part of set *
-     ***************/
+    /*****************************
+     * Part of set and Set Total *
+     *****************************/
     while ( (id3_frame = ID3Tag_FindFrameWithID(id3_tag,ID3FID_PARTINSET)) )
         ID3Tag_RemoveFrame(id3_tag,id3_frame);
     if (FileTag->disc_number && g_utf8_strlen(FileTag->disc_number, -1) > 0)
     {
-        id3_frame = ID3Frame_NewID(ID3FID_PARTINSET);
-        ID3Tag_AttachFrame(id3_tag,id3_frame);
-        Id3tag_Set_Field(id3_frame, ID3FN_TEXT, FileTag->disc_number);
+        id3_frame = ID3Frame_NewID (ID3FID_PARTINSET);
+        ID3Tag_AttachFrame (id3_tag, id3_frame);
+
+               if (FileTag->disc_total && g_utf8_strlen (FileTag->disc_total, -1) > 0)
+        {
+            string1 = g_strconcat (FileTag->disc_number, "/",
+                                   FileTag->disc_total, NULL);
+        }
+        else
+        {
+            string1 = g_strdup (FileTag->disc_number);
+        }
+
+        Id3tag_Set_Field (id3_frame, ID3FN_TEXT, string1);
+        g_free (string1);
         has_disc_number = TRUE;
     }
 
diff --git a/src/id3v24_tag.c b/src/id3v24_tag.c
index 3b8f849..cae4116 100644
--- a/src/id3v24_tag.c
+++ b/src/id3v24_tag.c
@@ -232,8 +232,25 @@ gboolean Id3tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
     /************************
      * Part of a set (TPOS) *
      ************************/
-    if ( (frame = id3_tag_findframe(tag,"TPOS", 0)) )
-        update |= libid3tag_Get_Frame_Str(frame, ~0, &FileTag->disc_number);
+    if ((frame = id3_tag_findframe (tag, "TPOS", 0)))
+    {
+        update |= libid3tag_Get_Frame_Str (frame, ~0, &string1);
+
+        if (string1)
+        {
+            string2 = g_utf8_strchr (string1, -1, '/');
+
+            if (string2)
+            {
+                FileTag->disc_total = et_disc_number_to_string (atoi (string2
+                                                                      + 1));
+                *string2 = '\0';
+            }
+
+            FileTag->disc_number = et_disc_number_to_string (atoi (string1));
+            g_free (string1);
+        }
+    }
 
     /********************
      * Year (TYER/TDRC) *
@@ -875,7 +892,19 @@ gboolean Id3tag_Write_File_v24Tag (ET_File *ETFile)
     /***************
      * Part of set *
      ***************/
-    etag_set_tags(FileTag->disc_number, "TPOS", ID3_FIELD_TYPE_STRINGLIST, NULL, v2tag, &strip_tags);
+    if (FileTag->disc_number && FileTag->disc_total && *FileTag->disc_total)
+    {
+        string1 = g_strconcat (FileTag->disc_number, "/", FileTag->disc_total,
+                               NULL);
+    }
+    else
+    {
+        string1 = g_strdup (FileTag->disc_number);
+    }
+
+    etag_set_tags (string1, "TPOS", ID3_FIELD_TYPE_STRINGLIST, NULL, v2tag,
+                   &strip_tags);
+    g_free (string1);
 
     /********
      * Year *


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