summaryrefslogtreecommitdiffstats
path: root/libhb/decmetadata.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhb/decmetadata.c')
-rw-r--r--libhb/decmetadata.c114
1 files changed, 83 insertions, 31 deletions
diff --git a/libhb/decmetadata.c b/libhb/decmetadata.c
index e3829de09..513e64fbe 100644
--- a/libhb/decmetadata.c
+++ b/libhb/decmetadata.c
@@ -11,9 +11,10 @@
#include "common.h"
-static void decmp4metadata( hb_title_t *title )
+static int decmp4metadata( hb_title_t *title )
{
MP4FileHandle input_file;
+ int result = 0;
hb_deep_log( 2, "Got an MP4 input, read the metadata");
input_file = MP4Read( title->path, 0 );
@@ -31,35 +32,93 @@ static void decmp4metadata( hb_title_t *title )
if( tags->name ) {
hb_deep_log( 2, "Metadata Name in input file is '%s'", tags->name );
- strncpy( title->metadata->name, tags->name, sizeof(title->metadata->name) );
+ hb_metadata_set_name(title->metadata, tags->name);
+ result = 1;
}
if( tags->artist )
- strncpy( title->metadata->artist, tags->artist, sizeof(title->metadata->artist) );
+ {
+ hb_metadata_set_artist(title->metadata, tags->artist);
+ result = 1;
+ }
if( tags->composer )
- strncpy( title->metadata->composer, tags->composer, sizeof(title->metadata->composer) );
+ {
+ hb_metadata_set_composer(title->metadata, tags->composer);
+ result = 1;
+ }
if( tags->comments )
- strncpy( title->metadata->comment, tags->comments, sizeof(title->metadata->comment) );
+ {
+ hb_metadata_set_comment(title->metadata, tags->comments);
+ result = 1;
+ }
if( tags->releaseDate )
- strncpy( title->metadata->release_date, tags->releaseDate, sizeof(title->metadata->release_date) );
+ {
+ hb_metadata_set_release_date(title->metadata, tags->releaseDate);
+ result = 1;
+ }
if( tags->album )
- strncpy( title->metadata->album, tags->album, sizeof(title->metadata->album) );
+ {
+ hb_metadata_set_album(title->metadata, tags->album);
+ result = 1;
+ }
+
+ if( tags->albumArtist )
+ {
+ hb_metadata_set_album_artist(title->metadata, tags->albumArtist);
+ result = 1;
+ }
if( tags->genre )
- strncpy( title->metadata->genre, tags->genre, sizeof(title->metadata->genre) );
+ {
+ hb_metadata_set_genre(title->metadata, tags->genre);
+ result = 1;
+ }
+
+ if( tags->description )
+ {
+ hb_metadata_set_description(title->metadata, tags->description);
+ result = 1;
+ }
+
+ if( tags->longDescription )
+ {
+ hb_metadata_set_long_description(title->metadata, tags->longDescription);
+ result = 1;
+ }
- if( tags->artworkCount > 0 ) {
- const MP4TagArtwork* art = tags->artwork + 0; // first element
- title->metadata->coverart = (uint8_t*)malloc( art->size );
- title->metadata->coverart_size = art->size;
- memcpy( title->metadata->coverart, art->data, art->size );
+ int ii;
+ for ( ii = 0; ii < tags->artworkCount; ii++ )
+ {
+ const MP4TagArtwork* art = tags->artwork + ii;
+ int type;
+ switch ( art->type )
+ {
+ case MP4_ART_BMP:
+ type = HB_ART_BMP;
+ break;
+ case MP4_ART_GIF:
+ type = HB_ART_GIF;
+ break;
+ case MP4_ART_JPEG:
+ type = HB_ART_JPEG;
+ break;
+ case MP4_ART_PNG:
+ type = HB_ART_PNG;
+ break;
+ default:
+ type = HB_ART_UNDEFINED;
+ break;
+ }
+ hb_metadata_add_coverart(
+ title->metadata, art->data, art->size, type);
hb_deep_log( 2, "Got some cover art of type %d, size %d",
art->type,
- title->metadata->coverart_size );
+ art->size );
+ result = 1;
}
/* store,free tags */
@@ -91,11 +150,13 @@ static void decmp4metadata( hb_title_t *title )
if( chapter_list[i-1].title )
{
- strcpy( chapter->title, chapter_list[i-1].title );
+ hb_chapter_set_title( chapter, chapter_list[i-1].title );
}
else
{
- sprintf( chapter->title, "Chapter %d", chapter->index );
+ char chapter_title[80];
+ sprintf( chapter_title, "Chapter %d", chapter->index );
+ hb_chapter_set_title( chapter, chapter_title );
}
hb_deep_log( 2, "Added chapter %i, name='%s', dur=%"PRId64", (%02i:%02i:%02i)",
@@ -109,6 +170,7 @@ static void decmp4metadata( hb_title_t *title )
MP4Close( input_file );
}
+ return result;
}
/*
@@ -116,24 +178,16 @@ static void decmp4metadata( hb_title_t *title )
*
* Look at the title and extract whatever metadata we can from that title.
*/
-void decmetadata( hb_title_t *title )
+int decmetadata( hb_title_t *title )
{
if( !title )
{
- return;
+ return 0;
}
- if( title->metadata )
- {
- free( title->metadata );
- title->metadata = NULL;
- }
-
- title->metadata = calloc( sizeof(hb_metadata_t), 1);
-
if( !title->metadata )
{
- return;
+ return 0;
}
/*
@@ -141,9 +195,7 @@ void decmetadata( hb_title_t *title )
*/
if( title->container_name && strcmp(title->container_name, "mov,mp4,m4a,3gp,3g2,mj2") == 0 )
{
- decmp4metadata( title );
- } else {
- free( title->metadata );
- title->metadata = NULL;
+ return decmp4metadata( title );
}
+ return 0;
}