* Add thumbnail support on folders, since at least XBMC supports it.

This commit is contained in:
Justin Maggard 2011-08-05 00:31:20 +00:00
parent 2eedc4bb4a
commit cdc93f680f
6 changed files with 41 additions and 27 deletions

4
NEWS
View File

@ -1,3 +1,7 @@
1.0.22 - Released 00-Month-0000
--------------------------------
- Add thumbnail support on folders, since at least XBMC supports it.
1.0.21 - Released 18-July-2011
--------------------------------
- Fix a few issues with new libav/ffmpeg versions.

View File

@ -21,6 +21,7 @@
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <libgen.h>
#include <setjmp.h>
#include <errno.h>
@ -268,16 +269,16 @@ end_art:
}
char *
check_for_album_file(char * dir, const char * path)
check_for_album_file(const char * dir, const char * path)
{
char * file = malloc(PATH_MAX);
char file[MAXPATHLEN];
struct album_art_name_s * album_art_name;
image_s * imsrc = NULL;
int width=0, height=0;
char * art_file;
/* First look for file-specific cover art */
sprintf(file, "%s.cover.jpg", path);
snprintf(file, sizeof(file), "%s.cover.jpg", path);
if( access(file, R_OK) == 0 )
{
if( art_cache_exists(file, &art_file) )
@ -287,9 +288,10 @@ check_for_album_file(char * dir, const char * path)
if( imsrc )
goto found_file;
}
sprintf(file, "%s", path);
strip_ext(file);
strcat(file, ".jpg");
snprintf(file, sizeof(file), "%s", path);
art_file = strrchr(file, '.');
if( art_file )
strcpy(art_file, ".jpg");
if( access(file, R_OK) == 0 )
{
if( art_cache_exists(file, &art_file) )
@ -303,13 +305,12 @@ check_for_album_file(char * dir, const char * path)
/* Then fall back to possible generic cover art file names */
for( album_art_name = album_art_names; album_art_name; album_art_name = album_art_name->next )
{
sprintf(file, "%s/%s", dir, album_art_name->name);
snprintf(file, sizeof(file), "%s/%s", dir, album_art_name->name);
if( access(file, R_OK) == 0 )
{
if( art_cache_exists(file, &art_file) )
{
existing_file:
free(file);
return art_file;
}
free(art_file);
@ -320,16 +321,13 @@ found_file:
width = imsrc->width;
height = imsrc->height;
if( width > 160 || height > 160 )
{
art_file = file;
file = save_resized_album_art(imsrc, art_file);
free(art_file);
}
art_file = save_resized_album_art(imsrc, file);
else
art_file = strdup(file);
image_free(imsrc);
return(file);
return(art_file);
}
}
free(file);
return NULL;
}
@ -341,10 +339,23 @@ find_album_art(const char * path, const char * image_data, int image_size)
char ** result;
int cols, rows;
sqlite_int64 ret = 0;
char * mypath = strdup(path);
char * mypath;
const char * dir;
struct stat st;
if( stat(path, &st) == 0 && S_ISDIR(st.st_mode) )
{
mypath = NULL;
dir = path;
}
else
{
mypath = strdup(path);
dir = dirname(mypath);
}
if( (image_size && (album_art = check_embedded_art(path, image_data, image_size))) ||
(album_art = check_for_album_file(dirname(mypath), path)) )
(album_art = check_for_album_file(dir, path)) )
{
sql = sqlite3_mprintf("SELECT ID from ALBUM_ART where PATH = '%q'", album_art ? album_art : path);
if( (sql_get_table(db, sql, &result, &rows, &cols) == SQLITE_OK) && rows )
@ -359,8 +370,7 @@ find_album_art(const char * path, const char * image_data, int image_size)
sqlite3_free_table(result);
sqlite3_free(sql);
}
if( album_art )
free(album_art);
free(album_art);
free(mypath);
return ret;

View File

@ -274,7 +274,7 @@ free_metadata(metadata_t * m, uint32_t flags)
}
sqlite_int64
GetFolderMetadata(const char * name, const char * path, const char * artist, const char * genre, const char * album_art)
GetFolderMetadata(const char * name, const char * path, const char * artist, const char * genre, sqlite3_int64 album_art)
{
int ret;
@ -282,8 +282,7 @@ GetFolderMetadata(const char * name, const char * path, const char * artist, con
" (TITLE, PATH, CREATOR, ARTIST, GENRE, ALBUM_ART) "
"VALUES"
" ('%q', %Q, %Q, %Q, %Q, %lld);",
name, path, artist, artist, genre,
album_art ? strtoll(album_art, NULL, 10) : 0);
name, path, artist, artist, genre, album_art);
if( ret != SQLITE_OK )
ret = 0;
else

View File

@ -88,7 +88,7 @@ void
check_for_captions(const char * path, sqlite_int64 detailID);
sqlite_int64
GetFolderMetadata(const char * name, const char * path, const char * artist, const char * genre, const char * album_art);
GetFolderMetadata(const char * name, const char * path, const char * artist, const char * genre, sqlite3_int64 album_art);
sqlite_int64
GetAudioMetadata(const char * path, char * name);

View File

@ -121,7 +121,7 @@ fill_playlists()
if( sql_get_int_field(db, "SELECT ID from OBJECTS where PARENT_ID = '"MUSIC_PLIST_ID"'"
" and NAME = '%q'", plname) <= 0 )
{
detailID = GetFolderMetadata(plname, NULL, NULL, NULL, NULL);
detailID = GetFolderMetadata(plname, NULL, NULL, NULL, 0);
sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, DETAIL_ID, CLASS, NAME) "
"VALUES"

View File

@ -40,6 +40,7 @@
#include "utils.h"
#include "sql.h"
#include "scanner.h"
#include "albumart.h"
#include "log.h"
int valid_cache = 0;
@ -106,7 +107,7 @@ insert_container(const char * item, const char * rootParent, const char * refID,
}
if( !detailID )
{
detailID = GetFolderMetadata(item, NULL, artist, genre, album_art);
detailID = GetFolderMetadata(item, NULL, artist, genre, (album_art ? strtoll(album_art, NULL, 10) : 0));
}
ret = sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
@ -439,7 +440,7 @@ insert_directory(const char * name, const char * path, const char * base, const
return 1;
}
detailID = GetFolderMetadata(name, path, NULL, NULL, NULL);
detailID = GetFolderMetadata(name, path, NULL, NULL, find_album_art(path, NULL, 0));
sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
"VALUES"
@ -628,7 +629,7 @@ CreateDatabase(void)
ret = sql_exec(db, "INSERT into OBJECTS (OBJECT_ID, PARENT_ID, DETAIL_ID, CLASS, NAME)"
" values "
"('%s', '%s', %lld, 'container.storageFolder', '%q')",
containers[i], containers[i+1], GetFolderMetadata(containers[i+2], NULL, NULL, NULL, NULL), containers[i+2]);
containers[i], containers[i+1], GetFolderMetadata(containers[i+2], NULL, NULL, NULL, 0), containers[i+2]);
if( ret != SQLITE_OK )
goto sql_failed;
}