[easytag/wip/disc-number: 7/7] Add total discs support to WavPack tag parser



commit 121ab2a2ddd766e83c8ad64e52c848cad906622a
Author: Mathias Reineke <saihtam gmx net>
Date:   Mon Jul 8 10:58:18 2013 +0200

    Add total discs support to WavPack tag parser

 src/wavpack_tag.c |   50 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 42 insertions(+), 8 deletions(-)
---
diff --git a/src/wavpack_tag.c b/src/wavpack_tag.c
index 977e14f..99b72bc 100644
--- a/src/wavpack_tag.c
+++ b/src/wavpack_tag.c
@@ -35,7 +35,6 @@
 #include "vcedit.h"
 #include "et_core.h"
 #include "picture.h"
-//#include "setting.h"
 #include "charset.h"
 #include "misc.h"
 #include "wavpack_tag.h"
@@ -134,13 +133,26 @@ gboolean Wavpack_Tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
     g_free (field);
 
     /*
-     * Discnumber
+     * Discnumber + Disctotal.
      */
-    field = g_malloc0(sizeof(char) * MAXLEN);
-    length = WavpackGetTagItem(wpc, "part", field, MAXLEN);
+    field = g_malloc0 (sizeof (char) * MAXLEN);
+    length = WavpackGetTagItem (wpc, "part", field, MAXLEN);
+    field2 = g_utf8_strchr (field, -1, '/');
 
-    if ( length > 0 && FileTag->disc_number == NULL ) {
-        FileTag->disc_number = Try_To_Validate_Utf8_String(field);
+    /* Need to cut off the total tracks if present */
+    if (field2)
+    {
+        *field2 = 0;
+        field2++;
+    }
+
+    if (field2 && FileTag->disc_total == NULL)
+    {
+        FileTag->disc_total = et_disc_number_to_string (atoi (Try_To_Validate_Utf8_String (field2)));
+    }
+    if (length > 0 && FileTag->disc_number == NULL)
+    {
+        FileTag->disc_number = et_disc_number_to_string (atoi (Try_To_Validate_Utf8_String (field)));
     }
 
     g_free (field);
@@ -313,8 +325,30 @@ gboolean Wavpack_Tag_Write_File_Tag (ET_File *ETFile)
     /*
      * Discnumber
     */
-    if (FileTag->disc_number && WavpackAppendTagItem(wpc, "part", FileTag->disc_number, 
strlen(FileTag->disc_number)) == 0) {
-        return FALSE;
+       if (FileTag->disc_number && FileTag->disc_total)
+    {
+        buffer = g_strdup_printf ("%s/%s", FileTag->disc_number,
+                                  FileTag->disc_total);
+
+        if (FileTag->track && WavpackAppendTagItem (wpc, "part", buffer,
+                                                    strlen(buffer)) == 0)
+        {
+            g_free (buffer);
+            return FALSE;
+        }
+        else
+        {
+            g_free (buffer);
+        }
+    }
+    else
+    {
+        if (FileTag->track && WavpackAppendTagItem (wpc, "part",
+                                                    FileTag->disc_number,
+                                                    strlen (FileTag->disc_number)) == 0)
+        {
+            return FALSE;
+        }
     }
 
     /*


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