* Add support for other operating systems (kFreeBSD, FreeBSD, and OSX for now).
* Switch to autoconf from genconfig.sh.
This commit is contained in:
73
scanner.c
73
scanner.c
@ -23,6 +23,7 @@
|
||||
#include <locale.h>
|
||||
#include <libgen.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
@ -43,6 +44,12 @@
|
||||
#include "albumart.h"
|
||||
#include "log.h"
|
||||
|
||||
#if SCANDIR_CONST
|
||||
typedef const struct dirent scan_filter;
|
||||
#else
|
||||
typedef struct dirent scan_filter;
|
||||
#endif
|
||||
|
||||
int valid_cache = 0;
|
||||
|
||||
struct virtual_item
|
||||
@ -112,7 +119,7 @@ insert_container(const char * item, const char * rootParent, const char * refID,
|
||||
ret = sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
|
||||
"VALUES"
|
||||
" ('%s$%"PRIX64"', '%s', %Q, %"PRId64", 'container.%s', '%q')",
|
||||
" ('%s$%llX', '%s', %Q, %lld, 'container.%s', '%q')",
|
||||
rootParent, *parentID, rootParent, refID, detailID, class, item);
|
||||
}
|
||||
sqlite3_free(result);
|
||||
@ -138,7 +145,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
static struct virtual_item last_camdate;
|
||||
static sqlite_int64 last_all_objectID = 0;
|
||||
|
||||
asprintf(&sql, "SELECT DATE, CREATOR from DETAILS where ID = %"PRId64, detailID);
|
||||
asprintf(&sql, "SELECT DATE, CREATOR from DETAILS where ID = %lld", detailID);
|
||||
ret = sql_get_table(db, sql, &result, &row, &cols);
|
||||
free(sql);
|
||||
if( ret == SQLITE_OK )
|
||||
@ -164,7 +171,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
else
|
||||
{
|
||||
insert_container(date_taken, IMAGE_DATE_ID, NULL, "album.photoAlbum", NULL, NULL, NULL, &objectID, &parentID);
|
||||
sprintf(last_date.parentID, IMAGE_DATE_ID"$%"PRIX64, parentID);
|
||||
sprintf(last_date.parentID, IMAGE_DATE_ID"$%llX", parentID);
|
||||
last_date.objectID = objectID;
|
||||
strcpy(last_date.name, date_taken);
|
||||
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached date item: %s/%s/%X\n", last_date.name, last_date.parentID, last_date.objectID);
|
||||
@ -172,7 +179,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
|
||||
" ('%s$%llX', '%s', '%s', '%s', %lld, %Q)",
|
||||
last_date.parentID, last_date.objectID, last_date.parentID, refID, class, detailID, name);
|
||||
|
||||
if( cam )
|
||||
@ -187,7 +194,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
if( !valid_cache || strcmp(camera, last_cam.name) != 0 )
|
||||
{
|
||||
insert_container(camera, IMAGE_CAMERA_ID, NULL, "storageFolder", NULL, NULL, NULL, &objectID, &parentID);
|
||||
sprintf(last_cam.parentID, IMAGE_CAMERA_ID"$%"PRIX64, parentID);
|
||||
sprintf(last_cam.parentID, IMAGE_CAMERA_ID"$%llX", parentID);
|
||||
strncpy(last_cam.name, camera, 255);
|
||||
last_camdate.name[0] = '\0';
|
||||
}
|
||||
@ -199,7 +206,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
else
|
||||
{
|
||||
insert_container(date_taken, last_cam.parentID, NULL, "album.photoAlbum", NULL, NULL, NULL, &objectID, &parentID);
|
||||
sprintf(last_camdate.parentID, "%s$%"PRIX64, last_cam.parentID, parentID);
|
||||
sprintf(last_camdate.parentID, "%s$%llX", last_cam.parentID, parentID);
|
||||
last_camdate.objectID = objectID;
|
||||
strcpy(last_camdate.name, date_taken);
|
||||
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached camdate item: %s/%s/%s/%X\n", camera, last_camdate.name, last_camdate.parentID, last_camdate.objectID);
|
||||
@ -207,7 +214,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
|
||||
" ('%s$%llX', '%s', '%s', '%s', %lld, %Q)",
|
||||
last_camdate.parentID, last_camdate.objectID, last_camdate.parentID, refID, class, detailID, name);
|
||||
/* All Images */
|
||||
if( !last_all_objectID )
|
||||
@ -217,12 +224,12 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('"IMAGE_ALL_ID"$%"PRIX64"', '"IMAGE_ALL_ID"', '%s', '%s', %"PRId64", %Q)",
|
||||
" ('"IMAGE_ALL_ID"$%llX', '"IMAGE_ALL_ID"', '%s', '%s', %lld, %Q)",
|
||||
last_all_objectID++, refID, class, detailID, name);
|
||||
}
|
||||
else if( strstr(class, "audioItem") )
|
||||
{
|
||||
asprintf(&sql, "SELECT ALBUM, ARTIST, GENRE, ALBUM_ART from DETAILS where ID = %"PRId64, detailID);
|
||||
asprintf(&sql, "SELECT ALBUM, ARTIST, GENRE, ALBUM_ART from DETAILS where ID = %lld", detailID);
|
||||
ret = sql_get_table(db, sql, &result, &row, &cols);
|
||||
free(sql);
|
||||
if( ret != SQLITE_OK )
|
||||
@ -261,7 +268,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
|
||||
" ('%s$%llX', '%s', '%s', '%s', %lld, %Q)",
|
||||
last_album.parentID, last_album.objectID, last_album.parentID, refID, class, detailID, name);
|
||||
}
|
||||
if( artist )
|
||||
@ -269,12 +276,12 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
if( !valid_cache || strcmp(artist, last_artist.name) != 0 )
|
||||
{
|
||||
insert_container(artist, MUSIC_ARTIST_ID, NULL, "person.musicArtist", NULL, genre, NULL, &objectID, &parentID);
|
||||
sprintf(last_artist.parentID, MUSIC_ARTIST_ID"$%"PRIX64, parentID);
|
||||
sprintf(last_artist.parentID, MUSIC_ARTIST_ID"$%llX", parentID);
|
||||
strcpy(last_artist.name, artist);
|
||||
last_artistAlbum.name[0] = '\0';
|
||||
/* Add this file to the "- All Albums -" container as well */
|
||||
insert_container(_("- All Albums -"), last_artist.parentID, NULL, "album", artist, genre, NULL, &objectID, &parentID);
|
||||
sprintf(last_artistAlbumAll.parentID, "%s$%"PRIX64, last_artist.parentID, parentID);
|
||||
sprintf(last_artistAlbumAll.parentID, "%s$%llX", last_artist.parentID, parentID);
|
||||
last_artistAlbumAll.objectID = objectID;
|
||||
}
|
||||
else
|
||||
@ -290,7 +297,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
{
|
||||
insert_container(album?album:_("Unknown Album"), last_artist.parentID, album?last_album.parentID:NULL,
|
||||
"album.musicAlbum", artist, genre, album_art, &objectID, &parentID);
|
||||
sprintf(last_artistAlbum.parentID, "%s$%"PRIX64, last_artist.parentID, parentID);
|
||||
sprintf(last_artistAlbum.parentID, "%s$%llX", last_artist.parentID, parentID);
|
||||
last_artistAlbum.objectID = objectID;
|
||||
strcpy(last_artistAlbum.name, album?album:_("Unknown Album"));
|
||||
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached artist/album item: %s/%s/%X\n", last_artist.name, last_artist.parentID, last_artist.objectID);
|
||||
@ -298,12 +305,12 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
|
||||
" ('%s$%llX', '%s', '%s', '%s', %lld, %Q)",
|
||||
last_artistAlbum.parentID, last_artistAlbum.objectID, last_artistAlbum.parentID, refID, class, detailID, name);
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
|
||||
" ('%s$%llX', '%s', '%s', '%s', %lld, %Q)",
|
||||
last_artistAlbumAll.parentID, last_artistAlbumAll.objectID, last_artistAlbumAll.parentID, refID, class, detailID, name);
|
||||
}
|
||||
if( genre )
|
||||
@ -311,12 +318,12 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
if( !valid_cache || strcmp(genre, last_genre.name) != 0 )
|
||||
{
|
||||
insert_container(genre, MUSIC_GENRE_ID, NULL, "genre.musicGenre", NULL, NULL, NULL, &objectID, &parentID);
|
||||
sprintf(last_genre.parentID, MUSIC_GENRE_ID"$%"PRIX64, parentID);
|
||||
sprintf(last_genre.parentID, MUSIC_GENRE_ID"$%llX", parentID);
|
||||
strcpy(last_genre.name, genre);
|
||||
last_genreArtist.name[0] = '\0';
|
||||
/* Add this file to the "- All Artists -" container as well */
|
||||
insert_container(_("- All Artists -"), last_genre.parentID, NULL, "person", NULL, genre, NULL, &objectID, &parentID);
|
||||
sprintf(last_genreArtistAll.parentID, "%s$%"PRIX64, last_genre.parentID, parentID);
|
||||
sprintf(last_genreArtistAll.parentID, "%s$%llX", last_genre.parentID, parentID);
|
||||
last_genreArtistAll.objectID = objectID;
|
||||
}
|
||||
else
|
||||
@ -331,7 +338,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
{
|
||||
insert_container(artist?artist:_("Unknown Artist"), last_genre.parentID, artist?last_artist.parentID:NULL,
|
||||
"person.musicArtist", NULL, genre, NULL, &objectID, &parentID);
|
||||
sprintf(last_genreArtist.parentID, "%s$%"PRIX64, last_genre.parentID, parentID);
|
||||
sprintf(last_genreArtist.parentID, "%s$%llX", last_genre.parentID, parentID);
|
||||
last_genreArtist.objectID = objectID;
|
||||
strcpy(last_genreArtist.name, artist?artist:_("Unknown Artist"));
|
||||
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached genre/artist item: %s/%s/%X\n", last_genreArtist.name, last_genreArtist.parentID, last_genreArtist.objectID);
|
||||
@ -339,12 +346,12 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
|
||||
" ('%s$%llX', '%s', '%s', '%s', %lld, %Q)",
|
||||
last_genreArtist.parentID, last_genreArtist.objectID, last_genreArtist.parentID, refID, class, detailID, name);
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
|
||||
" ('%s$%llX', '%s', '%s', '%s', %lld, %Q)",
|
||||
last_genreArtistAll.parentID, last_genreArtistAll.objectID, last_genreArtistAll.parentID, refID, class, detailID, name);
|
||||
}
|
||||
/* All Music */
|
||||
@ -355,7 +362,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('"MUSIC_ALL_ID"$%"PRIX64"', '"MUSIC_ALL_ID"', '%s', '%s', %"PRId64", %Q)",
|
||||
" ('"MUSIC_ALL_ID"$%llX', '"MUSIC_ALL_ID"', '%s', '%s', %lld, %Q)",
|
||||
last_all_objectID++, refID, class, detailID, name);
|
||||
}
|
||||
else if( strstr(class, "videoItem") )
|
||||
@ -370,7 +377,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('"VIDEO_ALL_ID"$%"PRIX64"', '"VIDEO_ALL_ID"', '%s', '%s', %"PRId64", %Q)",
|
||||
" ('"VIDEO_ALL_ID"$%llX', '"VIDEO_ALL_ID"', '%s', '%s', %lld, %Q)",
|
||||
last_all_objectID++, refID, class, detailID, name);
|
||||
return;
|
||||
}
|
||||
@ -423,7 +430,7 @@ insert_directory(const char * name, const char * path, const char * base, const
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
|
||||
"VALUES"
|
||||
" ('%s', '%s', %Q, %"PRId64", '%s', '%q')",
|
||||
" ('%s', '%s', %Q, %lld, '%s', '%q')",
|
||||
id_buf, parent_buf, refID, detailID, class, strrchr(dir, '/')+1);
|
||||
if( (p = strrchr(id_buf, '$')) )
|
||||
*p = '\0';
|
||||
@ -444,10 +451,9 @@ insert_directory(const char * name, const char * path, const char * base, const
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
|
||||
"VALUES"
|
||||
" ('%s%s$%X', '%s%s', %Q, %"PRId64", '%s', '%q')",
|
||||
" ('%s%s$%X', '%s%s', %Q, %lld, '%s', '%q')",
|
||||
base, parentID, objectID, base, parentID, refID, detailID, class, name);
|
||||
if( refID )
|
||||
free(refID);
|
||||
free(refID);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -492,8 +498,7 @@ insert_file(char * name, const char * path, const char * parentID, int object)
|
||||
strcpy(class, "item.audioItem.musicTrack");
|
||||
detailID = GetAudioMetadata(path, name);
|
||||
}
|
||||
if( orig_name )
|
||||
free(orig_name);
|
||||
free(orig_name);
|
||||
if( !detailID )
|
||||
{
|
||||
DPRINTF(E_WARN, L_SCANNER, "Unsuccessful getting details for %s!\n", path);
|
||||
@ -505,7 +510,7 @@ insert_file(char * name, const char * path, const char * parentID, int object)
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('%s', '%s%s', '%s', %"PRId64", '%q')",
|
||||
" ('%s', '%s%s', '%s', %lld, '%q')",
|
||||
objectID, BROWSEDIR_ID, parentID, class, detailID, name);
|
||||
|
||||
if( *parentID )
|
||||
@ -524,7 +529,7 @@ insert_file(char * name, const char * path, const char * parentID, int object)
|
||||
sql_exec(db, "INSERT into OBJECTS"
|
||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||
"VALUES"
|
||||
" ('%s%s$%X', '%s%s', '%s', '%s', %"PRId64", '%q')",
|
||||
" ('%s%s$%X', '%s%s', '%s', '%s', %lld, '%q')",
|
||||
base, parentID, object, base, parentID, objectID, class, detailID, name);
|
||||
|
||||
insert_containers(name, path, objectID, class, detailID);
|
||||
@ -655,7 +660,7 @@ sql_failed:
|
||||
}
|
||||
|
||||
int
|
||||
filter_audio(const struct dirent *d)
|
||||
filter_audio(scan_filter *d)
|
||||
{
|
||||
return ( (*d->d_name != '.') &&
|
||||
((d->d_type == DT_DIR) ||
|
||||
@ -669,7 +674,7 @@ filter_audio(const struct dirent *d)
|
||||
}
|
||||
|
||||
int
|
||||
filter_video(const struct dirent *d)
|
||||
filter_video(scan_filter *d)
|
||||
{
|
||||
return ( (*d->d_name != '.') &&
|
||||
((d->d_type == DT_DIR) ||
|
||||
@ -681,7 +686,7 @@ filter_video(const struct dirent *d)
|
||||
}
|
||||
|
||||
int
|
||||
filter_images(const struct dirent *d)
|
||||
filter_images(scan_filter *d)
|
||||
{
|
||||
return ( (*d->d_name != '.') &&
|
||||
((d->d_type == DT_DIR) ||
|
||||
@ -693,7 +698,7 @@ filter_images(const struct dirent *d)
|
||||
}
|
||||
|
||||
int
|
||||
filter_media(const struct dirent *d)
|
||||
filter_media(scan_filter *d)
|
||||
{
|
||||
return ( (*d->d_name != '.') &&
|
||||
((d->d_type == DT_DIR) ||
|
||||
|
Reference in New Issue
Block a user