* Fallback code for duplicate audio/video extensions (.mp4).

* Fix a couple potential very small memory leaks in the scanner.
This commit is contained in:
Justin Maggard 2009-03-03 08:14:01 +00:00
parent e6aa386f77
commit 9eb6f81a64
2 changed files with 340 additions and 328 deletions

View File

@ -169,7 +169,8 @@ GetAudioMetadata(const char * path, char * name)
if( readtags((char *)path, &song, &file, NULL, type) != 0 )
{
DPRINTF(E_WARN, L_GENERAL, "Cannot extract tags from %s\n", path);
DPRINTF(E_WARN, L_GENERAL, "Cannot extract tags from %s!\n", path);
freetags(&song);
return 0;
}
@ -463,7 +464,7 @@ GetVideoMetadata(const char * path, char * name)
memset(&m, '\0', sizeof(m));
date[0] = '\0';
DPRINTF(E_DEBUG, L_METADATA, "Parsing %s...\n", path);
DPRINTF(E_DEBUG, L_METADATA, "Parsing video %s...\n", path);
if ( stat(path, &file) == 0 )
{
modtime = localtime(&file.st_mtime);
@ -474,8 +475,11 @@ GetVideoMetadata(const char * path, char * name)
//DEBUG DPRINTF(E_DEBUG, L_METADATA, " * size: %d\n", size);
av_register_all();
if( av_open_input_file(&ctx, path, NULL, 0, NULL) == 0 )
if( av_open_input_file(&ctx, path, NULL, 0, NULL) != 0 )
{
DPRINTF(E_WARN, L_METADATA, "Opening %s failed!\n", path);
return 0;
}
av_find_stream_info(ctx);
//dump_format(ctx, 0, NULL, 0);
for( i=0; i<ctx->nb_streams; i++)
@ -493,6 +497,13 @@ GetVideoMetadata(const char * path, char * name)
continue;
}
}
/* This must not be a video file. */
if( video_stream == -1 )
{
av_close_input_file(ctx);
DPRINTF(E_WARN, L_METADATA, "File %s does not contain a video stream!\n", path);
return 0;
}
if( audio_stream >= 0 )
{
switch( ctx->streams[audio_stream]->codec->codec_id )
@ -829,11 +840,6 @@ GetVideoMetadata(const char * path, char * name)
asprintf(&m.mime, "video/mp4");
}
av_close_input_file(ctx);
}
else
{
DPRINTF(E_WARN, L_METADATA, "Opening %s failed!\n", path);
}
sql = sqlite3_mprintf( "INSERT into DETAILS"
" (PATH, SIZE, DURATION, DATE, CHANNELS, BITRATE, SAMPLERATE, RESOLUTION,"

View File

@ -432,6 +432,7 @@ insert_file(char * name, const char * path, const char * parentID, int object)
char * typedir_parentID;
int typedir_objectID;
char * baseid;
char * orig_name = NULL;
if( is_image(name) )
{
@ -439,18 +440,23 @@ insert_file(char * name, const char * path, const char * parentID, int object)
strcpy(class, "item.imageItem.photo");
detailID = GetImageMetadata(path, name);
}
else if( is_audio(name) )
else if( is_video(name) )
{
orig_name = strdup(name);
strcpy(base, VIDEO_DIR_ID);
strcpy(class, "item.videoItem");
detailID = GetVideoMetadata(path, name);
if( !detailID )
strcpy(name, orig_name);
}
if( !detailID && is_audio(name) )
{
strcpy(base, MUSIC_DIR_ID);
strcpy(class, "item.audioItem.musicTrack");
detailID = GetAudioMetadata(path, name);
}
if( !detailID && is_video(name) )
{
strcpy(base, VIDEO_DIR_ID);
strcpy(class, "item.videoItem");
detailID = GetVideoMetadata(path, name);
}
if( orig_name )
free(orig_name);
if( !detailID )
{
DPRINTF(E_WARN, L_SCANNER, "Unsuccessful getting details for %s!\n", path);