[Easytag-mailing] libmp4v2 patch, revised
- From: Honore Doktorr <hdfssk gmail com>
- To: easytag-mailing lists sourceforge net
- Subject: [Easytag-mailing] libmp4v2 patch, revised
- Date: Sat, 16 Jun 2012 20:50:09 -0400
I ran into a couple problems with Nick Lanham’s excellent mp4v2 patch; cover art
data wasn’t being properly duplicated, and easytag’s formatted number setting
wasn’t respected — fixes for which are in this revised version:
diff -uNr easytag-2.1.7/src/mp4_header.c easytag-2.1.7-mp4v2-build/src/mp4_header.c
--- easytag-2.1.7/src/mp4_header.c 2011-07-03 20:59:21.000000000 -0400
+++ easytag-2.1.7-mp4v2-build/src/mp4_header.c 2012-06-15 19:03:01.124697990
-0400
@@ -204,7 +204,7 @@
/* Get size of file */
ETFileInfo->size = Get_File_Size(filename);
- if ((file = MP4Read(filename, 0)) == MP4_INVALID_FILE_HANDLE )
+ if ((file = MP4Read(filename)) == MP4_INVALID_FILE_HANDLE )
{
gchar *filename_utf8 = filename_to_display(filename);
//g_print(_("ERROR while opening file: '%s'
(%s)."),filename_utf8,g_strerror(errno));
@@ -218,7 +218,7 @@
{
gchar *filename_utf8 = filename_to_display(filename);
Log_Print(LOG_ERROR,_("ERROR while opening file: '%s'
(%s)."),filename_utf8,("Contains no audio track"));
- MP4Close(file);
+ MP4Close(file, 0);
g_free(filename_utf8);
return FALSE;
}
@@ -243,7 +243,7 @@
ETFileInfo->mode = MP4GetTrackAudioChannels(file, trackId);
ETFileInfo->duration = MP4ConvertFromTrackDuration(file, trackId,
MP4GetTrackDuration(file, trackId), MP4_SECS_TIME_SCALE);
- MP4Close(file);
+ MP4Close(file, 0);
return TRUE;
}
diff -uNr easytag-2.1.7/src/mp4_tag.c easytag-2.1.7-mp4v2-build/src/mp4_tag.c
--- easytag-2.1.7/src/mp4_tag.c 2011-07-03 20:59:21.000000000 -0400
+++ easytag-2.1.7-mp4v2-build/src/mp4_tag.c 2012-06-16 20:31:46.564581535 -0400
@@ -72,6 +72,8 @@
*
* Read tag data into an Mp4 file.
*
+ * cf.
http://mp4v2.googlecode.com/svn/doc/1.9.0/api/example_2itmf_2tags_8c-example.html
+ *
* Note:
* - for string fields, //if field is found but contains no info
(strlen(str)==0), we don't read it
* - for track numbers, if they are zero, then we don't read it
@@ -80,14 +82,12 @@
{
FILE *file;
MP4FileHandle mp4file = NULL;
+ const MP4Tags *mp4tags = NULL;
uint16_t track, track_total;
uint16_t disk, disktotal;
- u_int8_t *coverArt;
- u_int32_t coverSize;
Picture *prev_pic = NULL;
-#ifdef NEWMP4
- gint pic_num;
-#endif
+ int pic_num;
+ const MP4TagArtwork *mp4artwork = NULL;
if (!filename || !FileTag)
return FALSE;
@@ -102,7 +102,7 @@
fclose(file); // We close it cause mp4 opens/closes file itself
/* Get data from tag */
- mp4file = MP4Read(filename, 0);
+ mp4file = MP4Read(filename);
if (mp4file == MP4_INVALID_FILE_HANDLE)
{
gchar *filename_utf8 = filename_to_display(filename);
@@ -111,28 +111,47 @@
return FALSE;
}
+ mp4tags = MP4TagsAlloc();
+ if (!MP4TagsFetch(mp4tags, mp4file))
+ {
+ gchar *filename_utf8 = filename_to_display(filename);
+ Log_Print(LOG_ERROR,_("ERROR reading tags from file: '%s'
(%s)."),filename_utf8,_("MP4 format invalid"));
+ g_free(filename_utf8);
+ return FALSE;
+ }
+
/* TODO Add error detection */
/*********
* Title *
*********/
- MP4GetMetadataName(mp4file, &FileTag->title);
+ if (mp4tags->name)
+ FileTag->title = g_strdup(mp4tags->name);
/**********
* Artist *
**********/
- MP4GetMetadataArtist(mp4file, &FileTag->artist);
+ if (mp4tags->artist)
+ FileTag->artist = g_strdup(mp4tags->artist);
/*********
* Album *
*********/
- MP4GetMetadataAlbum(mp4file, &FileTag->album);
+ if (mp4tags->album)
+ FileTag->album = g_strdup(mp4tags->album);
+
+ /****************
+ * Album Artist *
+ ****************/
+ if (mp4tags->albumArtist)
+ FileTag->album_artist = g_strdup(mp4tags->albumArtist);
/**********************
* Disk / Total Disks *
**********************/
- if (MP4GetMetadataDisk(mp4file, &disk, &disktotal))
+ if (mp4tags->disk)
{
+ disk = mp4tags->disk->index, disktotal = mp4tags->disk->total;
if (disk != 0 && disktotal != 0)
FileTag->disc_number =
g_strdup_printf("%d/%d",(gint)disk,(gint)disktotal);
else if (disk != 0)
@@ -146,38 +165,45 @@
/********
* Year *
********/
- MP4GetMetadataYear(mp4file, &FileTag->year);
+ if (mp4tags->releaseDate)
+ FileTag->year = g_strdup(mp4tags->releaseDate);
/*************************
* Track and Total Track *
*************************/
- if (MP4GetMetadataTrack(mp4file, &track, &track_total))
+ if (mp4tags->track)
{
+
+ track = mp4tags->track->index, track_total = mp4tags->track->total;
if (track != 0)
- FileTag->track =
g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,(gint)track); // Just
to have numbers like this : '01', '05', '12', ...
+ FileTag->track = NUMBER_TRACK_FORMATED ?
g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,(gint)track) :
g_strdup_printf("%d",(gint)track);
if (track_total != 0)
- FileTag->track_total =
g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,(gint)track_total); //
Just to have numbers like this : '01', '05', '12', ...
+ FileTag->track_total = NUMBER_TRACK_FORMATED ?
g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,(gint)track_total) :
g_strdup_printf("%d",(gint)track_total);
}
/*********
* Genre *
*********/
- MP4GetMetadataGenre(mp4file, &FileTag->genre);
+ if (mp4tags->genre)
+ FileTag->genre = g_strdup(mp4tags->genre);
/***********
* Comment *
***********/
- MP4GetMetadataComment(mp4file, &FileTag->comment);
+ if (mp4tags->comments)
+ FileTag->comment = g_strdup(mp4tags->comments);
/**********************
* Composer or Writer *
**********************/
- MP4GetMetadataWriter(mp4file, &FileTag->composer);
+ if (mp4tags->composer)
+ FileTag->composer = g_strdup(mp4tags->composer);
/*****************
* Encoding Tool *
*****************/
- MP4GetMetadataTool(mp4file, &FileTag->encoded_by);
+ if (mp4tags->encodedBy)
+ FileTag->encoded_by = g_strdup(mp4tags->encodedBy);
/* Unimplemented
Tempo / BPM
@@ -187,14 +213,9 @@
/***********
* Picture *
***********/
-#ifdef NEWMP4
- // There version can handle multiple pictures!
- // Version 1.6 of libmp4v2 introduces an index argument for
MP4GetMetadataCoverart
- for (pic_num = 0; (MP4GetMetadataCoverArt( mp4file, &coverArt,
&coverSize,pic_num )); pic_num++)
-#else
- // There version handle only one picture!
- if ( MP4GetMetadataCoverArt( mp4file, &coverArt, &coverSize ) )
-#endif
+ // Version 1.9.1 of mp4v2 and up handle multiple cover art
+ mp4artwork = mp4tags->artwork;
+ for (pic_num = 0; pic_num < mp4tags->artworkCount; ++pic_num, ++mp4artwork)
{
Picture *pic;
@@ -205,15 +226,16 @@
prev_pic->next = pic;
prev_pic = pic;
- pic->size = coverSize;
- pic->data = coverArt;
- pic->type = PICTURE_TYPE_FRONT_COVER;
+ pic->size = mp4artwork->size;
+ pic->data = g_memdup(mp4artwork->data, pic->size);
+ pic->type = PICTURE_TYPE_FRONT_COVER;/* mp4artwork->type gives image
type */
pic->description = NULL;
}
/* Free allocated data */
- MP4Close(mp4file);
+ MP4TagsFree(mp4tags);
+ MP4Close(mp4file, 0);
return TRUE;
}
@@ -234,8 +256,18 @@
gchar *filename_utf8;
FILE *file;
MP4FileHandle mp4file = NULL;
+ const MP4Tags *mp4tags = NULL;
+ MP4TagDisk mp4disk;
+ MP4TagTrack mp4track;
+ MP4TagArtwork mp4artwork;
gint error = 0;
+ /* extra initializers */
+ mp4disk.index = 0;
+ mp4disk.total = 0;
+ mp4track.index = 0;
+ mp4track.total = 0;
+
if (!ETFile || !ETFile->FileTag)
return FALSE;
@@ -252,23 +284,29 @@
fclose(file);
/* Open file for writing */
- mp4file = MP4Modify(filename,0,0);
+ mp4file = MP4Modify(filename, 0);
if (mp4file == MP4_INVALID_FILE_HANDLE)
{
Log_Print(LOG_ERROR,_("ERROR while opening file: '%s'
(%s)."),filename_utf8,_("MP4 format invalid"));
return FALSE;
}
+ mp4tags = MP4TagsAlloc();
+ if (!MP4TagsFetch(mp4tags, mp4file))
+ {
+ Log_Print(LOG_ERROR,_("ERROR reading tags from file: '%s'
(%s)."),filename_utf8,_("MP4 format invalid"));
+ return FALSE;
+ }
+
/*********
* Title *
*********/
if (FileTag->title && g_utf8_strlen(FileTag->title, -1) > 0)
{
- MP4SetMetadataName(mp4file, FileTag->title);
+ MP4TagsSetName(mp4tags, FileTag->title);
}else
{
- //MP4DeleteMetadataName(mp4file); // Not available on mpeg4ip-1.2 (only
in 1.3)
- MP4SetMetadataName(mp4file, "");
+ MP4TagsSetName(mp4tags, "");
}
/**********
@@ -276,11 +314,10 @@
**********/
if (FileTag->artist && g_utf8_strlen(FileTag->artist, -1) > 0)
{
- MP4SetMetadataArtist(mp4file, FileTag->artist);
+ MP4TagsSetArtist(mp4tags, FileTag->artist);
}else
{
- //MP4DeleteMetadataArtist(mp4file);
- MP4SetMetadataArtist(mp4file, "");
+ MP4TagsSetArtist(mp4tags, "");
}
/*********
@@ -288,11 +325,21 @@
*********/
if (FileTag->album && g_utf8_strlen(FileTag->album, -1) > 0)
{
- MP4SetMetadataAlbum(mp4file, FileTag->album);
+ MP4TagsSetAlbum(mp4tags, FileTag->album);
}else
{
- //MP4DeleteMetadataAlbum(mp4file);
- MP4SetMetadataAlbum(mp4file, "");
+ MP4TagsSetAlbum(mp4tags, "");
+ }
+
+ /****************
+ * Album Artist *
+ ****************/
+ if (FileTag->album_artist && g_utf8_strlen(FileTag->album_artist, -1) > 0)
+ {
+ MP4TagsSetAlbumArtist(mp4tags, FileTag->album_artist);
+ }else
+ {
+ MP4TagsSetAlbumArtist(mp4tags, "");
}
/**********************
@@ -301,9 +348,6 @@
if (FileTag->disc_number && g_utf8_strlen(FileTag->disc_number, -1) > 0)
//|| FileTag->disc_number_total &&
g_utf8_strlen(FileTag->disc_number_total, -1) > 0)
{
- uint16_t disk = 0;
- uint16_t disktotal = 0;
-
/* At the present time, we manage only disk number like '1' or '1/2', we
* don't use disk number total... so here we try to decompose */
if (FileTag->disc_number)
@@ -314,39 +358,34 @@
{
// A disc_number_total was entered
if ( (tmp+1) && atoi(tmp+1) )
- disktotal = atoi(tmp+1);
+ mp4disk.total = atoi(tmp+1);
// Fill disc_number
*tmp = '\0';
- disk = atoi(dn_tmp);
+ mp4disk.index = atoi(dn_tmp);
}else
{
- disk = atoi(FileTag->disc_number);
+ mp4disk.index = atoi(FileTag->disc_number);
}
g_free(dn_tmp);
}
/*if (FileTag->disc_number)
- disk = atoi(FileTag->disc_number);
+ mp4disk.index = atoi(FileTag->disc_number);
if (FileTag->disc_number_total)
- disktotal = atoi(FileTag->disc_number_total);
+ mp4disk.total = atoi(FileTag->disc_number_total);
*/
- MP4SetMetadataDisk(mp4file, disk, disktotal);
- }else
- {
- //MP4DeleteMetadataDisk(mp4file);
- MP4SetMetadataDisk(mp4file, 0, 0);
}
+ MP4TagsSetDisk(mp4tags, &mp4disk);
/********
* Year *
********/
if (FileTag->year && g_utf8_strlen(FileTag->year, -1) > 0)
{
- MP4SetMetadataYear(mp4file, FileTag->year);
+ MP4TagsSetReleaseDate(mp4tags, FileTag->year);
}else
{
- //MP4DeleteMetadataYear(mp4file);
- MP4SetMetadataYear(mp4file, "");
+ MP4TagsSetReleaseDate(mp4tags, "");
}
/*************************
@@ -355,29 +394,22 @@
if ( (FileTag->track && g_utf8_strlen(FileTag->track, -1) > 0)
|| (FileTag->track_total && g_utf8_strlen(FileTag->track_total, -1) > 0) )
{
- uint16_t track = 0;
- uint16_t track_total = 0;
if (FileTag->track)
- track = atoi(FileTag->track);
+ mp4track.index = atoi(FileTag->track);
if (FileTag->track_total)
- track_total = atoi(FileTag->track_total);
- MP4SetMetadataTrack(mp4file, track, track_total);
- }else
- {
- //MP4DeleteMetadataTrack(mp4file);
- MP4SetMetadataTrack(mp4file, 0, 0);
+ mp4track.total = atoi(FileTag->track_total);
}
+ MP4TagsSetTrack(mp4tags, &mp4track);
/*********
* Genre *
*********/
if (FileTag->genre && g_utf8_strlen(FileTag->genre, -1) > 0 )
{
- MP4SetMetadataGenre(mp4file, FileTag->genre);
+ MP4TagsSetGenre(mp4tags, FileTag->genre);
}else
{
- //MP4DeleteMetadataGenre(mp4file);
- MP4SetMetadataGenre(mp4file, "");
+ MP4TagsSetGenre(mp4tags, "");
}
/***********
@@ -385,11 +417,10 @@
***********/
if (FileTag->comment && g_utf8_strlen(FileTag->comment, -1) > 0)
{
- MP4SetMetadataComment(mp4file, FileTag->comment);
+ MP4TagsSetComments(mp4tags, FileTag->comment);
}else
{
- //MP4DeleteMetadataComment(mp4file);
- MP4SetMetadataComment(mp4file, "");
+ MP4TagsSetComments(mp4tags, "");
}
/**********************
@@ -397,11 +428,10 @@
**********************/
if (FileTag->composer && g_utf8_strlen(FileTag->composer, -1) > 0)
{
- MP4SetMetadataWriter(mp4file, FileTag->composer);
+ MP4TagsSetComposer(mp4tags, FileTag->composer);
}else
{
- //MP4DeleteMetadataWriter(mp4file);
- MP4SetMetadataWriter(mp4file, "");
+ MP4TagsSetComposer(mp4tags, "");
}
/*****************
@@ -409,11 +439,10 @@
*****************/
if (FileTag->encoded_by && g_utf8_strlen(FileTag->encoded_by, -1) > 0)
{
- MP4SetMetadataTool(mp4file, FileTag->encoded_by);
+ MP4TagsSetEncodedBy(mp4tags, FileTag->encoded_by);
}else
{
- //MP4DeleteMetadataTool(mp4file);
- MP4SetMetadataTool(mp4file, "");
+ MP4TagsSetEncodedBy(mp4tags, "");
}
/***********
@@ -422,20 +451,36 @@
{
// Can handle only one picture...
Picture *pic;
-
- //MP4DeleteMetadataCoverArt(mp4file);
- MP4SetMetadataCoverArt(mp4file, NULL, 0);
- for( pic = FileTag->picture; pic; pic = pic->next )
+ if (mp4tags->artworkCount && mp4tags->artwork)
+ MP4TagsRemoveArtwork(mp4tags, 0);
+ MP4TagsSetArtwork(mp4tags, 0, NULL);
+ for (pic = FileTag->picture; pic; pic = pic->next)
{
- if( pic->type == PICTURE_TYPE_FRONT_COVER )
+ if (pic->type == PICTURE_TYPE_FRONT_COVER)
{
- MP4SetMetadataCoverArt(mp4file, pic->data, pic->size);
+ mp4artwork.data = pic->data;
+ mp4artwork.size = pic->size;
+ switch (pic->type) {
+ case PICTURE_FORMAT_JPEG:
+ mp4artwork.type = MP4_ART_JPEG;
+ break;
+ case PICTURE_FORMAT_PNG:
+ mp4artwork.type = MP4_ART_PNG;
+ break;
+ default:
+ mp4artwork.type = MP4_ART_UNDEFINED;
+ }
+ if (mp4tags->artworkCount)
+ MP4TagsSetArtwork(mp4tags, 0, &mp4artwork);
+ else
+ MP4TagsAddArtwork(mp4tags, &mp4artwork);
}
}
}
-
- MP4Close(mp4file);
+ MP4TagsStore(mp4tags, mp4file);
+ MP4TagsFree(mp4tags);
+ MP4Close(mp4file, 0);
if (error) return FALSE;
else return TRUE;
diff -uNr easytag-2.1.7/src/mp4_header.c easytag-2.1.7-mp4v2-build/src/mp4_header.c
--- easytag-2.1.7/src/mp4_header.c 2011-07-03 20:59:21.000000000 -0400
+++ easytag-2.1.7-mp4v2-build/src/mp4_header.c 2012-06-15 19:03:01.124697990 -0400
@@ -204,7 +204,7 @@
/* Get size of file */
ETFileInfo->size = Get_File_Size(filename);
- if ((file = MP4Read(filename, 0)) == MP4_INVALID_FILE_HANDLE )
+ if ((file = MP4Read(filename)) == MP4_INVALID_FILE_HANDLE )
{
gchar *filename_utf8 = filename_to_display(filename);
//g_print(_("ERROR while opening file: '%s' (%s)."),filename_utf8,g_strerror(errno));
@@ -218,7 +218,7 @@
{
gchar *filename_utf8 = filename_to_display(filename);
Log_Print(LOG_ERROR,_("ERROR while opening file: '%s' (%s)."),filename_utf8,("Contains no audio track"));
- MP4Close(file);
+ MP4Close(file, 0);
g_free(filename_utf8);
return FALSE;
}
@@ -243,7 +243,7 @@
ETFileInfo->mode = MP4GetTrackAudioChannels(file, trackId);
ETFileInfo->duration = MP4ConvertFromTrackDuration(file, trackId, MP4GetTrackDuration(file, trackId), MP4_SECS_TIME_SCALE);
- MP4Close(file);
+ MP4Close(file, 0);
return TRUE;
}
diff -uNr easytag-2.1.7/src/mp4_tag.c easytag-2.1.7-mp4v2-build/src/mp4_tag.c
--- easytag-2.1.7/src/mp4_tag.c 2011-07-03 20:59:21.000000000 -0400
+++ easytag-2.1.7-mp4v2-build/src/mp4_tag.c 2012-06-16 20:31:46.564581535 -0400
@@ -72,6 +72,8 @@
*
* Read tag data into an Mp4 file.
*
+ * cf. http://mp4v2.googlecode.com/svn/doc/1.9.0/api/example_2itmf_2tags_8c-example.html
+ *
* Note:
* - for string fields, //if field is found but contains no info (strlen(str)==0), we don't read it
* - for track numbers, if they are zero, then we don't read it
@@ -80,14 +82,12 @@
{
FILE *file;
MP4FileHandle mp4file = NULL;
+ const MP4Tags *mp4tags = NULL;
uint16_t track, track_total;
uint16_t disk, disktotal;
- u_int8_t *coverArt;
- u_int32_t coverSize;
Picture *prev_pic = NULL;
-#ifdef NEWMP4
- gint pic_num;
-#endif
+ int pic_num;
+ const MP4TagArtwork *mp4artwork = NULL;
if (!filename || !FileTag)
return FALSE;
@@ -102,7 +102,7 @@
fclose(file); // We close it cause mp4 opens/closes file itself
/* Get data from tag */
- mp4file = MP4Read(filename, 0);
+ mp4file = MP4Read(filename);
if (mp4file == MP4_INVALID_FILE_HANDLE)
{
gchar *filename_utf8 = filename_to_display(filename);
@@ -111,28 +111,47 @@
return FALSE;
}
+ mp4tags = MP4TagsAlloc();
+ if (!MP4TagsFetch(mp4tags, mp4file))
+ {
+ gchar *filename_utf8 = filename_to_display(filename);
+ Log_Print(LOG_ERROR,_("ERROR reading tags from file: '%s' (%s)."),filename_utf8,_("MP4 format invalid"));
+ g_free(filename_utf8);
+ return FALSE;
+ }
+
/* TODO Add error detection */
/*********
* Title *
*********/
- MP4GetMetadataName(mp4file, &FileTag->title);
+ if (mp4tags->name)
+ FileTag->title = g_strdup(mp4tags->name);
/**********
* Artist *
**********/
- MP4GetMetadataArtist(mp4file, &FileTag->artist);
+ if (mp4tags->artist)
+ FileTag->artist = g_strdup(mp4tags->artist);
/*********
* Album *
*********/
- MP4GetMetadataAlbum(mp4file, &FileTag->album);
+ if (mp4tags->album)
+ FileTag->album = g_strdup(mp4tags->album);
+
+ /****************
+ * Album Artist *
+ ****************/
+ if (mp4tags->albumArtist)
+ FileTag->album_artist = g_strdup(mp4tags->albumArtist);
/**********************
* Disk / Total Disks *
**********************/
- if (MP4GetMetadataDisk(mp4file, &disk, &disktotal))
+ if (mp4tags->disk)
{
+ disk = mp4tags->disk->index, disktotal = mp4tags->disk->total;
if (disk != 0 && disktotal != 0)
FileTag->disc_number = g_strdup_printf("%d/%d",(gint)disk,(gint)disktotal);
else if (disk != 0)
@@ -146,38 +165,45 @@
/********
* Year *
********/
- MP4GetMetadataYear(mp4file, &FileTag->year);
+ if (mp4tags->releaseDate)
+ FileTag->year = g_strdup(mp4tags->releaseDate);
/*************************
* Track and Total Track *
*************************/
- if (MP4GetMetadataTrack(mp4file, &track, &track_total))
+ if (mp4tags->track)
{
+
+ track = mp4tags->track->index, track_total = mp4tags->track->total;
if (track != 0)
- FileTag->track = g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,(gint)track); // Just to have numbers like this : '01', '05', '12', ...
+ FileTag->track = NUMBER_TRACK_FORMATED ? g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,(gint)track) : g_strdup_printf("%d",(gint)track);
if (track_total != 0)
- FileTag->track_total = g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,(gint)track_total); // Just to have numbers like this : '01', '05', '12', ...
+ FileTag->track_total = NUMBER_TRACK_FORMATED ? g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,(gint)track_total) : g_strdup_printf("%d",(gint)track_total);
}
/*********
* Genre *
*********/
- MP4GetMetadataGenre(mp4file, &FileTag->genre);
+ if (mp4tags->genre)
+ FileTag->genre = g_strdup(mp4tags->genre);
/***********
* Comment *
***********/
- MP4GetMetadataComment(mp4file, &FileTag->comment);
+ if (mp4tags->comments)
+ FileTag->comment = g_strdup(mp4tags->comments);
/**********************
* Composer or Writer *
**********************/
- MP4GetMetadataWriter(mp4file, &FileTag->composer);
+ if (mp4tags->composer)
+ FileTag->composer = g_strdup(mp4tags->composer);
/*****************
* Encoding Tool *
*****************/
- MP4GetMetadataTool(mp4file, &FileTag->encoded_by);
+ if (mp4tags->encodedBy)
+ FileTag->encoded_by = g_strdup(mp4tags->encodedBy);
/* Unimplemented
Tempo / BPM
@@ -187,14 +213,9 @@
/***********
* Picture *
***********/
-#ifdef NEWMP4
- // There version can handle multiple pictures!
- // Version 1.6 of libmp4v2 introduces an index argument for MP4GetMetadataCoverart
- for (pic_num = 0; (MP4GetMetadataCoverArt( mp4file, &coverArt, &coverSize,pic_num )); pic_num++)
-#else
- // There version handle only one picture!
- if ( MP4GetMetadataCoverArt( mp4file, &coverArt, &coverSize ) )
-#endif
+ // Version 1.9.1 of mp4v2 and up handle multiple cover art
+ mp4artwork = mp4tags->artwork;
+ for (pic_num = 0; pic_num < mp4tags->artworkCount; ++pic_num, ++mp4artwork)
{
Picture *pic;
@@ -205,15 +226,16 @@
prev_pic->next = pic;
prev_pic = pic;
- pic->size = coverSize;
- pic->data = coverArt;
- pic->type = PICTURE_TYPE_FRONT_COVER;
+ pic->size = mp4artwork->size;
+ pic->data = g_memdup(mp4artwork->data, pic->size);
+ pic->type = PICTURE_TYPE_FRONT_COVER;/* mp4artwork->type gives image type */
pic->description = NULL;
}
/* Free allocated data */
- MP4Close(mp4file);
+ MP4TagsFree(mp4tags);
+ MP4Close(mp4file, 0);
return TRUE;
}
@@ -234,8 +256,18 @@
gchar *filename_utf8;
FILE *file;
MP4FileHandle mp4file = NULL;
+ const MP4Tags *mp4tags = NULL;
+ MP4TagDisk mp4disk;
+ MP4TagTrack mp4track;
+ MP4TagArtwork mp4artwork;
gint error = 0;
+ /* extra initializers */
+ mp4disk.index = 0;
+ mp4disk.total = 0;
+ mp4track.index = 0;
+ mp4track.total = 0;
+
if (!ETFile || !ETFile->FileTag)
return FALSE;
@@ -252,23 +284,29 @@
fclose(file);
/* Open file for writing */
- mp4file = MP4Modify(filename,0,0);
+ mp4file = MP4Modify(filename, 0);
if (mp4file == MP4_INVALID_FILE_HANDLE)
{
Log_Print(LOG_ERROR,_("ERROR while opening file: '%s' (%s)."),filename_utf8,_("MP4 format invalid"));
return FALSE;
}
+ mp4tags = MP4TagsAlloc();
+ if (!MP4TagsFetch(mp4tags, mp4file))
+ {
+ Log_Print(LOG_ERROR,_("ERROR reading tags from file: '%s' (%s)."),filename_utf8,_("MP4 format invalid"));
+ return FALSE;
+ }
+
/*********
* Title *
*********/
if (FileTag->title && g_utf8_strlen(FileTag->title, -1) > 0)
{
- MP4SetMetadataName(mp4file, FileTag->title);
+ MP4TagsSetName(mp4tags, FileTag->title);
}else
{
- //MP4DeleteMetadataName(mp4file); // Not available on mpeg4ip-1.2 (only in 1.3)
- MP4SetMetadataName(mp4file, "");
+ MP4TagsSetName(mp4tags, "");
}
/**********
@@ -276,11 +314,10 @@
**********/
if (FileTag->artist && g_utf8_strlen(FileTag->artist, -1) > 0)
{
- MP4SetMetadataArtist(mp4file, FileTag->artist);
+ MP4TagsSetArtist(mp4tags, FileTag->artist);
}else
{
- //MP4DeleteMetadataArtist(mp4file);
- MP4SetMetadataArtist(mp4file, "");
+ MP4TagsSetArtist(mp4tags, "");
}
/*********
@@ -288,11 +325,21 @@
*********/
if (FileTag->album && g_utf8_strlen(FileTag->album, -1) > 0)
{
- MP4SetMetadataAlbum(mp4file, FileTag->album);
+ MP4TagsSetAlbum(mp4tags, FileTag->album);
}else
{
- //MP4DeleteMetadataAlbum(mp4file);
- MP4SetMetadataAlbum(mp4file, "");
+ MP4TagsSetAlbum(mp4tags, "");
+ }
+
+ /****************
+ * Album Artist *
+ ****************/
+ if (FileTag->album_artist && g_utf8_strlen(FileTag->album_artist, -1) > 0)
+ {
+ MP4TagsSetAlbumArtist(mp4tags, FileTag->album_artist);
+ }else
+ {
+ MP4TagsSetAlbumArtist(mp4tags, "");
}
/**********************
@@ -301,9 +348,6 @@
if (FileTag->disc_number && g_utf8_strlen(FileTag->disc_number, -1) > 0)
//|| FileTag->disc_number_total && g_utf8_strlen(FileTag->disc_number_total, -1) > 0)
{
- uint16_t disk = 0;
- uint16_t disktotal = 0;
-
/* At the present time, we manage only disk number like '1' or '1/2', we
* don't use disk number total... so here we try to decompose */
if (FileTag->disc_number)
@@ -314,39 +358,34 @@
{
// A disc_number_total was entered
if ( (tmp+1) && atoi(tmp+1) )
- disktotal = atoi(tmp+1);
+ mp4disk.total = atoi(tmp+1);
// Fill disc_number
*tmp = '\0';
- disk = atoi(dn_tmp);
+ mp4disk.index = atoi(dn_tmp);
}else
{
- disk = atoi(FileTag->disc_number);
+ mp4disk.index = atoi(FileTag->disc_number);
}
g_free(dn_tmp);
}
/*if (FileTag->disc_number)
- disk = atoi(FileTag->disc_number);
+ mp4disk.index = atoi(FileTag->disc_number);
if (FileTag->disc_number_total)
- disktotal = atoi(FileTag->disc_number_total);
+ mp4disk.total = atoi(FileTag->disc_number_total);
*/
- MP4SetMetadataDisk(mp4file, disk, disktotal);
- }else
- {
- //MP4DeleteMetadataDisk(mp4file);
- MP4SetMetadataDisk(mp4file, 0, 0);
}
+ MP4TagsSetDisk(mp4tags, &mp4disk);
/********
* Year *
********/
if (FileTag->year && g_utf8_strlen(FileTag->year, -1) > 0)
{
- MP4SetMetadataYear(mp4file, FileTag->year);
+ MP4TagsSetReleaseDate(mp4tags, FileTag->year);
}else
{
- //MP4DeleteMetadataYear(mp4file);
- MP4SetMetadataYear(mp4file, "");
+ MP4TagsSetReleaseDate(mp4tags, "");
}
/*************************
@@ -355,29 +394,22 @@
if ( (FileTag->track && g_utf8_strlen(FileTag->track, -1) > 0)
|| (FileTag->track_total && g_utf8_strlen(FileTag->track_total, -1) > 0) )
{
- uint16_t track = 0;
- uint16_t track_total = 0;
if (FileTag->track)
- track = atoi(FileTag->track);
+ mp4track.index = atoi(FileTag->track);
if (FileTag->track_total)
- track_total = atoi(FileTag->track_total);
- MP4SetMetadataTrack(mp4file, track, track_total);
- }else
- {
- //MP4DeleteMetadataTrack(mp4file);
- MP4SetMetadataTrack(mp4file, 0, 0);
+ mp4track.total = atoi(FileTag->track_total);
}
+ MP4TagsSetTrack(mp4tags, &mp4track);
/*********
* Genre *
*********/
if (FileTag->genre && g_utf8_strlen(FileTag->genre, -1) > 0 )
{
- MP4SetMetadataGenre(mp4file, FileTag->genre);
+ MP4TagsSetGenre(mp4tags, FileTag->genre);
}else
{
- //MP4DeleteMetadataGenre(mp4file);
- MP4SetMetadataGenre(mp4file, "");
+ MP4TagsSetGenre(mp4tags, "");
}
/***********
@@ -385,11 +417,10 @@
***********/
if (FileTag->comment && g_utf8_strlen(FileTag->comment, -1) > 0)
{
- MP4SetMetadataComment(mp4file, FileTag->comment);
+ MP4TagsSetComments(mp4tags, FileTag->comment);
}else
{
- //MP4DeleteMetadataComment(mp4file);
- MP4SetMetadataComment(mp4file, "");
+ MP4TagsSetComments(mp4tags, "");
}
/**********************
@@ -397,11 +428,10 @@
**********************/
if (FileTag->composer && g_utf8_strlen(FileTag->composer, -1) > 0)
{
- MP4SetMetadataWriter(mp4file, FileTag->composer);
+ MP4TagsSetComposer(mp4tags, FileTag->composer);
}else
{
- //MP4DeleteMetadataWriter(mp4file);
- MP4SetMetadataWriter(mp4file, "");
+ MP4TagsSetComposer(mp4tags, "");
}
/*****************
@@ -409,11 +439,10 @@
*****************/
if (FileTag->encoded_by && g_utf8_strlen(FileTag->encoded_by, -1) > 0)
{
- MP4SetMetadataTool(mp4file, FileTag->encoded_by);
+ MP4TagsSetEncodedBy(mp4tags, FileTag->encoded_by);
}else
{
- //MP4DeleteMetadataTool(mp4file);
- MP4SetMetadataTool(mp4file, "");
+ MP4TagsSetEncodedBy(mp4tags, "");
}
/***********
@@ -422,20 +451,36 @@
{
// Can handle only one picture...
Picture *pic;
-
- //MP4DeleteMetadataCoverArt(mp4file);
- MP4SetMetadataCoverArt(mp4file, NULL, 0);
- for( pic = FileTag->picture; pic; pic = pic->next )
+ if (mp4tags->artworkCount && mp4tags->artwork)
+ MP4TagsRemoveArtwork(mp4tags, 0);
+ MP4TagsSetArtwork(mp4tags, 0, NULL);
+ for (pic = FileTag->picture; pic; pic = pic->next)
{
- if( pic->type == PICTURE_TYPE_FRONT_COVER )
+ if (pic->type == PICTURE_TYPE_FRONT_COVER)
{
- MP4SetMetadataCoverArt(mp4file, pic->data, pic->size);
+ mp4artwork.data = pic->data;
+ mp4artwork.size = pic->size;
+ switch (pic->type) {
+ case PICTURE_FORMAT_JPEG:
+ mp4artwork.type = MP4_ART_JPEG;
+ break;
+ case PICTURE_FORMAT_PNG:
+ mp4artwork.type = MP4_ART_PNG;
+ break;
+ default:
+ mp4artwork.type = MP4_ART_UNDEFINED;
+ }
+ if (mp4tags->artworkCount)
+ MP4TagsSetArtwork(mp4tags, 0, &mp4artwork);
+ else
+ MP4TagsAddArtwork(mp4tags, &mp4artwork);
}
}
}
-
- MP4Close(mp4file);
+ MP4TagsStore(mp4tags, mp4file);
+ MP4TagsFree(mp4tags);
+ MP4Close(mp4file, 0);
if (error) return FALSE;
else return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]