~ubuntu-branches/ubuntu/wily/easytag/wily

« back to all changes in this revision

Viewing changes to src/id3v24_tag.c

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2013-10-11 17:07:47 UTC
  • mto: (8.1.4 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: package-import@ubuntu.com-20131011170747-uqvgtx7uyd046j7z
Tags: upstream-2.1.8
ImportĀ upstreamĀ versionĀ 2.1.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "misc.h"
42
42
#include "log.h"
43
43
#include "et_core.h"
44
 
#include "msgbox.h"
45
44
#include "charset.h"
46
45
 
47
 
#ifdef WIN32
48
 
#   include "win32/win32dep.h"
49
 
#endif
 
46
#ifdef G_OS_WIN32
 
47
#include "win32/win32dep.h"
 
48
#endif /* G_OS_WIN32 */
50
49
 
51
50
 
52
51
#ifdef ENABLE_MP3
80
79
static void   Id3tag_delete_frames      (struct id3_tag *tag, const gchar *name, int start);
81
80
static void   Id3tag_delete_txxframes   (struct id3_tag *tag, const gchar *param1, int start);
82
81
static struct id3_frame *Id3tag_find_and_create_frame    (struct id3_tag *tag, const gchar *name);
83
 
static struct id3_frame *Id3tag_find_and_create_txxframe (struct id3_tag *tag, const gchar *param1);
84
82
static int    id3taglib_set_field       (struct id3_frame *frame, const gchar *str, enum id3_field_type type, int num, int clear, int id3v1);
85
83
static int    etag_set_tags             (const gchar *str, const char *frame_name, enum id3_field_type field_type, struct id3_tag *v1tag, struct id3_tag *v2tag, gboolean *strip_tags);
86
 
static int    etag_write_tags           (const gchar *filename, const struct id3_tag *v1tag, const struct id3_tag *v2tag, gboolean strip_tags);
 
84
static int etag_write_tags (const gchar *filename, struct id3_tag const *v1tag,
 
85
                            struct id3_tag const *v2tag, gboolean strip_tags);
87
86
 
88
87
/*************
89
88
 * Functions *
114
113
    if ( (tmpfile=open(filename,O_RDONLY)) < 0 )
115
114
    {
116
115
        gchar *filename_utf8 = filename_to_display(filename);
117
 
        g_print(_("ERROR while opening file: '%s' (%s).\n\a"),filename_utf8,g_strerror(errno));
 
116
        g_print(_("Error while opening file: '%s' (%s).\n\a"),filename_utf8,g_strerror(errno));
118
117
        g_free(filename_utf8);
119
118
        return FALSE;
120
119
    }
131
130
    if (read(tmpfile, string1, ID3_TAG_QUERYSIZE) != ID3_TAG_QUERYSIZE)
132
131
    {
133
132
        close(tmpfile);
 
133
        g_free (string1);
134
134
        return FALSE;
135
135
    }
136
136
 
149
149
        {
150
150
            /* Determine version if user want to upgrade old tags */
151
151
            if (CONVERT_OLD_ID3V2_TAG_VERSION
152
 
            && (string1 = realloc(string1, tagsize))
 
152
            && (string1 = g_realloc (string1, tagsize))
153
153
            && (read(tmpfile, &string1[ID3_TAG_QUERYSIZE], tagsize - ID3_TAG_QUERYSIZE) == tagsize - ID3_TAG_QUERYSIZE)
154
154
            && (tag = id3_tag_parse((id3_byte_t const *)string1, tagsize))
155
155
               )
701
701
                if (USE_NON_STANDARD_ID3_READING_CHARACTER_SET)
702
702
                {
703
703
                    tmpstr = convert_string(latinstr, FILE_READING_ID3V1V2_CHARACTER_SET, "UTF-8", FALSE);
704
 
                    free(latinstr);
 
704
                    g_free (latinstr);
705
705
                }
706
706
                else
707
707
                    tmpstr = latinstr;
757
757
    if (retstr)
758
758
        *retstr = ret;
759
759
    else
760
 
        free(ret);
 
760
        g_free (ret);
761
761
 
762
762
    return retval;
763
763
}
924
924
    if ((genre_value == ID3_INVALID_GENRE)||(FILE_WRITING_ID3V2_TEXT_ONLY_GENRE))
925
925
        string1 = g_strdup(FileTag->genre);
926
926
    else
927
 
        string1 = g_strdup_printf("%d",genre_value);
 
927
        string1 = g_strdup_printf("(%d)",genre_value);
928
928
 
929
929
    etag_set_tags(string1, ID3_FRAME_GENRE, ID3_FIELD_TYPE_STRINGLIST, v1tag, v2tag, &strip_tags);
930
930
    g_free(string1);
1115
1115
    return frame;
1116
1116
}
1117
1117
 
1118
 
/* Find first "TXX" (user defined text information) frame in tag 'tag'
1119
 
 * with first string parameter (name) 'param'
1120
 
 * create new if not found
1121
 
 */
1122
 
static struct id3_frame *
1123
 
Id3tag_find_and_create_txxframe (struct id3_tag *tag, const gchar *param1)
1124
 
{
1125
 
    const id3_ucs4_t *ucs4string;
1126
 
    struct id3_frame *frame;
1127
 
    union id3_field *field;
1128
 
    int i;
1129
 
    gchar *str;
1130
 
 
1131
 
    if (!tag || !param1 || !*param1)
1132
 
    return NULL;
1133
 
 
1134
 
    for (i = 0; (frame = id3_tag_findframe(tag, "TXXX", i)); i++)
1135
 
    if ( (field = id3_frame_field(frame, 1))
1136
 
    && (ucs4string = id3_field_getstring(field)) )
1137
 
    {
1138
 
        str = NULL;
1139
 
        if ((str = (gchar *)id3_ucs4_latin1duplicate(ucs4string))
1140
 
        && (strncasecmp(str, param1, strlen(param1)) == 0) )
1141
 
        {
1142
 
            g_free(str);
1143
 
            break;
1144
 
        }else
1145
 
            g_free(str);
1146
 
    }
1147
 
 
1148
 
    if (frame == NULL)
1149
 
    {
1150
 
        if ((frame = id3_frame_new("TXXX")) == NULL)
1151
 
            return NULL;
1152
 
        id3_tag_attachframe(tag, frame);
1153
 
    }
1154
 
 
1155
 
    return frame;
1156
 
}
1157
 
 
1158
1118
static int
1159
1119
id3taglib_set_field(struct id3_frame *frame,
1160
1120
                    const gchar *str,
1208
1168
            }
1209
1169
 
1210
1170
            latinstr = convert_string(str, "UTF-8", encname ? encname : "ISO-8859-1//IGNORE", TRUE);
1211
 
            free(encname);
 
1171
            g_free (encname);
1212
1172
            buf = id3_latin1_ucs4duplicate((id3_latin1_t const *)latinstr);
1213
1173
        } else
1214
1174
        {
1354
1314
 
1355
1315
static int
1356
1316
etag_write_tags (const gchar *filename, 
1357
 
                 const struct id3_tag *v1tag, 
1358
 
                 const struct id3_tag *v2tag, 
 
1317
                 struct id3_tag const *v1tag,
 
1318
                 struct id3_tag const *v2tag,
1359
1319
                 gboolean strip_tags)
1360
1320
{
1361
1321
    id3_byte_t *v1buf, *v2buf;
1515
1475
            gchar *filename_utf8 = filename_to_display(filename);
1516
1476
            gchar *basename_utf8 = g_path_get_basename(filename_utf8);
1517
1477
 
1518
 
            Log_Print(LOG_ERROR,_("Can't write tag of file '%s' (were read %d bytes instead of %d bytes!)"),basename_utf8,size_read,ctxsize);
 
1478
            Log_Print(LOG_ERROR,_("Cannot write tag of file '%s' (%d bytes were read but %d bytes were expected)"),basename_utf8,size_read,ctxsize);
1519
1479
            g_free(filename_utf8);
1520
1480
            g_free(basename_utf8);
1521
1481
            goto out;