[easytag] Add only numeric characters to TPOS in ID3 Tags



commit 40e2787c8dbb75f36f0b2c69cdf6270aa5df7b28
Author: Abhinav <abhijangda hotmail com>
Date:   Sun Apr 13 11:05:17 2014 +0530

    Add only numeric characters to TPOS in ID3 Tags
    
    https://bugzilla.gnome.org/show_bug.cgi?id=726467

 src/id3_tag.c    |   59 +++++++++++++++++++++++++++++++++++++++++++----------
 src/id3_tag.h    |    1 +
 src/id3v24_tag.c |   16 ++++----------
 3 files changed, 54 insertions(+), 22 deletions(-)
---
diff --git a/src/id3_tag.c b/src/id3_tag.c
index dabec6d..ebd5959 100644
--- a/src/id3_tag.c
+++ b/src/id3_tag.c
@@ -84,6 +84,53 @@ static gboolean Id3tag_Check_If_Id3lib_Is_Bugged (void);
  * Functions *
  *************/
 
+/**
+ * et_id3tag_get_tpos_from_file_tag:
+ * @FileTag: File_Tag to get disc_number and disc_total from
+ *
+ * This function will return TPOS from FileTag.
+ * Returns: a newly allocated string, should be freed using g_free.
+ */
+gchar *
+et_id3tag_get_tpos_from_file_tag (File_Tag *FileTag)
+{
+    GString *gstring;
+    gchar *p;
+
+    gstring = g_string_new ("");
+    p = FileTag->disc_number;
+
+    while (*p)
+    {
+        if (!isdigit (*p))
+        {
+            break;
+        }
+
+        g_string_append_c (gstring, *p);
+        p++;
+    }
+
+    if (FileTag->disc_total && *FileTag->disc_total)
+    {
+        g_string_append_c (gstring, '/');
+        p = FileTag->disc_total;
+
+        while (*p)
+        {
+            if (!isdigit (*p))
+            {
+                break;
+            }
+
+            g_string_append_c (gstring, *p);
+            p++;
+        }
+    }
+
+    return g_string_free (gstring, FALSE);
+}
+
 /*
  * Write the ID3 tags to the file. Returns TRUE on success, else 0.
  */
@@ -258,17 +305,7 @@ Id3tag_Write_File_v23Tag (ET_File *ETFile)
     {
         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);
-        }
-
+        string1 = et_id3tag_get_tpos_from_file_tag (FileTag);
         Id3tag_Set_Field (id3_frame, ID3FN_TEXT, string1);
         g_free (string1);
         has_disc_number = TRUE;
diff --git a/src/id3_tag.h b/src/id3_tag.h
index ffae191..9424506 100644
--- a/src/id3_tag.h
+++ b/src/id3_tag.h
@@ -43,5 +43,6 @@ gboolean Id3tag_Write_File_Tag    (ET_File *ETFile);
 gchar   *Id3tag_Genre_To_String (unsigned char genre_code);
 guchar   Id3tag_String_To_Genre (gchar *genre);
 
+gchar *et_id3tag_get_tpos_from_file_tag (File_Tag *file_tag);
 
 #endif /* __ID3TAG_H__ */
diff --git a/src/id3v24_tag.c b/src/id3v24_tag.c
index 9324ef2..85f16c6 100644
--- a/src/id3v24_tag.c
+++ b/src/id3v24_tag.c
@@ -893,20 +893,14 @@ gboolean Id3tag_Write_File_v24Tag (ET_File *ETFile)
     /***************
      * Part of set *
      ***************/
-    if (FileTag->disc_number && FileTag->disc_total && *FileTag->disc_total)
+    if (FileTag->disc_number)
     {
-        string1 = g_strconcat (FileTag->disc_number, "/", FileTag->disc_total,
-                               NULL);
-    }
-    else
-    {
-        string1 = g_strdup (FileTag->disc_number);
+        string1 = et_id3tag_get_tpos_from_file_tag (FileTag);
+        etag_set_tags (string1, "TPOS", ID3_FIELD_TYPE_STRINGLIST, NULL, v2tag,
+                       &strip_tags);
+        g_free (string1);
     }
 
-    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]