* Add thumbnail support on folders, since at least XBMC supports it.
This commit is contained in:
parent
2eedc4bb4a
commit
cdc93f680f
4
NEWS
4
NEWS
@ -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
|
1.0.21 - Released 18-July-2011
|
||||||
--------------------------------
|
--------------------------------
|
||||||
- Fix a few issues with new libav/ffmpeg versions.
|
- Fix a few issues with new libav/ffmpeg versions.
|
||||||
|
48
albumart.c
48
albumart.c
@ -21,6 +21,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -268,16 +269,16 @@ end_art:
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *
|
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;
|
struct album_art_name_s * album_art_name;
|
||||||
image_s * imsrc = NULL;
|
image_s * imsrc = NULL;
|
||||||
int width=0, height=0;
|
int width=0, height=0;
|
||||||
char * art_file;
|
char * art_file;
|
||||||
|
|
||||||
/* First look for file-specific cover art */
|
/* 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( access(file, R_OK) == 0 )
|
||||||
{
|
{
|
||||||
if( art_cache_exists(file, &art_file) )
|
if( art_cache_exists(file, &art_file) )
|
||||||
@ -287,9 +288,10 @@ check_for_album_file(char * dir, const char * path)
|
|||||||
if( imsrc )
|
if( imsrc )
|
||||||
goto found_file;
|
goto found_file;
|
||||||
}
|
}
|
||||||
sprintf(file, "%s", path);
|
snprintf(file, sizeof(file), "%s", path);
|
||||||
strip_ext(file);
|
art_file = strrchr(file, '.');
|
||||||
strcat(file, ".jpg");
|
if( art_file )
|
||||||
|
strcpy(art_file, ".jpg");
|
||||||
if( access(file, R_OK) == 0 )
|
if( access(file, R_OK) == 0 )
|
||||||
{
|
{
|
||||||
if( art_cache_exists(file, &art_file) )
|
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 */
|
/* 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 )
|
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( access(file, R_OK) == 0 )
|
||||||
{
|
{
|
||||||
if( art_cache_exists(file, &art_file) )
|
if( art_cache_exists(file, &art_file) )
|
||||||
{
|
{
|
||||||
existing_file:
|
existing_file:
|
||||||
free(file);
|
|
||||||
return art_file;
|
return art_file;
|
||||||
}
|
}
|
||||||
free(art_file);
|
free(art_file);
|
||||||
@ -320,16 +321,13 @@ found_file:
|
|||||||
width = imsrc->width;
|
width = imsrc->width;
|
||||||
height = imsrc->height;
|
height = imsrc->height;
|
||||||
if( width > 160 || height > 160 )
|
if( width > 160 || height > 160 )
|
||||||
{
|
art_file = save_resized_album_art(imsrc, file);
|
||||||
art_file = file;
|
else
|
||||||
file = save_resized_album_art(imsrc, art_file);
|
art_file = strdup(file);
|
||||||
free(art_file);
|
|
||||||
}
|
|
||||||
image_free(imsrc);
|
image_free(imsrc);
|
||||||
return(file);
|
return(art_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(file);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,10 +339,23 @@ find_album_art(const char * path, const char * image_data, int image_size)
|
|||||||
char ** result;
|
char ** result;
|
||||||
int cols, rows;
|
int cols, rows;
|
||||||
sqlite_int64 ret = 0;
|
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))) ||
|
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);
|
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 )
|
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_table(result);
|
||||||
sqlite3_free(sql);
|
sqlite3_free(sql);
|
||||||
}
|
}
|
||||||
if( album_art )
|
free(album_art);
|
||||||
free(album_art);
|
|
||||||
free(mypath);
|
free(mypath);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -274,7 +274,7 @@ free_metadata(metadata_t * m, uint32_t flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sqlite_int64
|
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;
|
int ret;
|
||||||
|
|
||||||
@ -282,8 +282,7 @@ GetFolderMetadata(const char * name, const char * path, const char * artist, con
|
|||||||
" (TITLE, PATH, CREATOR, ARTIST, GENRE, ALBUM_ART) "
|
" (TITLE, PATH, CREATOR, ARTIST, GENRE, ALBUM_ART) "
|
||||||
"VALUES"
|
"VALUES"
|
||||||
" ('%q', %Q, %Q, %Q, %Q, %lld);",
|
" ('%q', %Q, %Q, %Q, %Q, %lld);",
|
||||||
name, path, artist, artist, genre,
|
name, path, artist, artist, genre, album_art);
|
||||||
album_art ? strtoll(album_art, NULL, 10) : 0);
|
|
||||||
if( ret != SQLITE_OK )
|
if( ret != SQLITE_OK )
|
||||||
ret = 0;
|
ret = 0;
|
||||||
else
|
else
|
||||||
|
@ -88,7 +88,7 @@ void
|
|||||||
check_for_captions(const char * path, sqlite_int64 detailID);
|
check_for_captions(const char * path, sqlite_int64 detailID);
|
||||||
|
|
||||||
sqlite_int64
|
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
|
sqlite_int64
|
||||||
GetAudioMetadata(const char * path, char * name);
|
GetAudioMetadata(const char * path, char * name);
|
||||||
|
@ -121,7 +121,7 @@ fill_playlists()
|
|||||||
if( sql_get_int_field(db, "SELECT ID from OBJECTS where PARENT_ID = '"MUSIC_PLIST_ID"'"
|
if( sql_get_int_field(db, "SELECT ID from OBJECTS where PARENT_ID = '"MUSIC_PLIST_ID"'"
|
||||||
" and NAME = '%q'", plname) <= 0 )
|
" 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"
|
sql_exec(db, "INSERT into OBJECTS"
|
||||||
" (OBJECT_ID, PARENT_ID, DETAIL_ID, CLASS, NAME) "
|
" (OBJECT_ID, PARENT_ID, DETAIL_ID, CLASS, NAME) "
|
||||||
"VALUES"
|
"VALUES"
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "sql.h"
|
#include "sql.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
|
#include "albumart.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
int valid_cache = 0;
|
int valid_cache = 0;
|
||||||
@ -106,7 +107,7 @@ insert_container(const char * item, const char * rootParent, const char * refID,
|
|||||||
}
|
}
|
||||||
if( !detailID )
|
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"
|
ret = sql_exec(db, "INSERT into OBJECTS"
|
||||||
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
|
" (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;
|
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"
|
sql_exec(db, "INSERT into OBJECTS"
|
||||||
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
|
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
|
||||||
"VALUES"
|
"VALUES"
|
||||||
@ -628,7 +629,7 @@ CreateDatabase(void)
|
|||||||
ret = sql_exec(db, "INSERT into OBJECTS (OBJECT_ID, PARENT_ID, DETAIL_ID, CLASS, NAME)"
|
ret = sql_exec(db, "INSERT into OBJECTS (OBJECT_ID, PARENT_ID, DETAIL_ID, CLASS, NAME)"
|
||||||
" values "
|
" values "
|
||||||
"('%s', '%s', %lld, 'container.storageFolder', '%q')",
|
"('%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 )
|
if( ret != SQLITE_OK )
|
||||||
goto sql_failed;
|
goto sql_failed;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user