"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "scanner.c" between
minidlna-1.2.0.tar.gz and minidlna-1.2.1.tar.gz

About: ReadyMedia (formerly known as MiniDLNA) is a simple media server software, with the aim of being fully compliant with DLNA/UPnP-AV clients.

scanner.c  (minidlna-1.2.0):scanner.c  (minidlna-1.2.1)
skipping to change at line 450 skipping to change at line 450
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"
" ('%s%s$%X', '%s%s', %lld, '%s', '%q')", " ('%s%s$%X', '%s%s', %lld, '%s', '%q')",
base, parentID, objectID, base, parentID, detailID, class, n ame); base, parentID, objectID, base, parentID, detailID, class, n ame);
return detailID; return detailID;
} }
int int
insert_file(char *name, const char *path, const char *parentID, int object, medi a_types types) insert_file(const char *name, const char *path, const char *parentID, int object , media_types types)
{ {
char class[32]; const char *class;
char objectID[64]; char objectID[64];
int64_t detailID = 0; int64_t detailID = 0;
char base[8]; char base[8];
char *typedir_parentID; char *typedir_parentID;
char *baseid; char *baseid;
char *orig_name = NULL; char *objname;
media_types mtype = get_media_type(name);
if( (types & TYPE_IMAGES) && is_image(name) ) if( mtype == TYPE_IMAGE && (types & TYPE_IMAGE) )
{ {
if( is_album_art(name) ) if( is_album_art(name) )
return -1; return -1;
strcpy(base, IMAGE_DIR_ID); strcpy(base, IMAGE_DIR_ID);
strcpy(class, "item.imageItem.photo"); class = "item.imageItem.photo";
detailID = GetImageMetadata(path, name); detailID = GetImageMetadata(path, name);
} }
else if( (types & TYPE_VIDEO) && is_video(name) ) else if( mtype == TYPE_VIDEO && (types & TYPE_VIDEO) )
{ {
orig_name = strdup(name);
strcpy(base, VIDEO_DIR_ID); strcpy(base, VIDEO_DIR_ID);
strcpy(class, "item.videoItem"); class = "item.videoItem";
detailID = GetVideoMetadata(path, name); detailID = GetVideoMetadata(path, name);
if( !detailID )
strcpy(name, orig_name);
} }
else if( is_playlist(name) ) else if( mtype == TYPE_PLAYLIST && (types & TYPE_PLAYLIST) )
{ {
if( insert_playlist(path, name) == 0 ) if( insert_playlist(path, name) == 0 )
return 1; return 1;
} }
if( !detailID && (types & TYPE_AUDIO) && is_audio(name) ) /* Some file extensions can be used for both audio and video.
** Fall back to audio on these files if video parsing fails. */
if (!detailID && (types & TYPE_AUDIO) && is_audio(name) )
{ {
strcpy(base, MUSIC_DIR_ID); strcpy(base, MUSIC_DIR_ID);
strcpy(class, "item.audioItem.musicTrack"); class = "item.audioItem.musicTrack";
detailID = GetAudioMetadata(path, name); detailID = GetAudioMetadata(path, name);
} }
free(orig_name);
if( !detailID ) if( !detailID )
{ {
DPRINTF(E_WARN, L_SCANNER, "Unsuccessful getting details for %s!\ n", path); DPRINTF(E_WARN, L_SCANNER, "Unsuccessful getting details for %s\n ", path);
return -1; return -1;
} }
sprintf(objectID, "%s%s$%X", BROWSEDIR_ID, parentID, object); sprintf(objectID, "%s%s$%X", BROWSEDIR_ID, parentID, object);
objname = strdup(name);
strip_ext(objname);
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s', '%s%s', '%s', %lld, '%q')", " ('%s', '%s%s', '%s', %lld, '%q')",
objectID, BROWSEDIR_ID, parentID, class, detailID, name); objectID, BROWSEDIR_ID, parentID, class, detailID, objname);
if( *parentID ) if( *parentID )
{ {
int typedir_objectID = 0; int typedir_objectID = 0;
typedir_parentID = strdup(parentID); typedir_parentID = strdup(parentID);
baseid = strrchr(typedir_parentID, '$'); baseid = strrchr(typedir_parentID, '$');
if( baseid ) if( baseid )
{ {
typedir_objectID = strtol(baseid+1, NULL, 16); typedir_objectID = strtol(baseid+1, NULL, 16);
*baseid = '\0'; *baseid = '\0';
} }
insert_directory(name, path, base, typedir_parentID, typedir_obje ctID); insert_directory(objname, path, base, typedir_parentID, typedir_o bjectID);
free(typedir_parentID); free(typedir_parentID);
} }
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s%s$%X', '%s%s', '%s', '%s', %lld, '%q')", " ('%s%s$%X', '%s%s', '%s', '%s', %lld, '%q')",
base, parentID, object, base, parentID, objectID, class, det base, parentID, object, base, parentID, objectID, class, det
ailID, name); ailID, objname);
insert_containers(objname, path, objectID, class, detailID);
free(objname);
insert_containers(name, path, objectID, class, detailID);
return 0; return 0;
} }
int int
CreateDatabase(void) CreateDatabase(void)
{ {
int ret, i; int ret, i;
const char *containers[] = { "0","-1", "root", const char *containers[] = { "0","-1", "root",
MUSIC_ID, "0", _("Music"), MUSIC_ID, "0", _("Music"),
MUSIC_ALL_ID, MUSIC_ID, _("All Music"), MUSIC_ALL_ID, MUSIC_ID, _("All Music"),
skipping to change at line 631 skipping to change at line 634
filter_hidden(scan_filter *d) filter_hidden(scan_filter *d)
{ {
return (d->d_name[0] != '.'); return (d->d_name[0] != '.');
} }
static int static int
filter_type(scan_filter *d) filter_type(scan_filter *d)
{ {
#if HAVE_STRUCT_DIRENT_D_TYPE #if HAVE_STRUCT_DIRENT_D_TYPE
return ( (d->d_type == DT_DIR) || return ( (d->d_type == DT_DIR) ||
(d->d_type == DT_LNK) || (d->d_type == DT_LNK) ||
(d->d_type == DT_UNKNOWN) (d->d_type == DT_UNKNOWN)
); );
#else #else
return 1; return 1;
#endif #endif
} }
static int static int
filter_a(scan_filter *d) filter_a(scan_filter *d)
{ {
return ( filter_hidden(d) && return ( filter_hidden(d) &&
(filter_type(d) || (filter_type(d) ||
(is_reg(d) && (is_reg(d) &&
(is_audio(d->d_name) || (is_audio(d->d_name) ||
is_playlist(d->d_name)))) is_playlist(d->d_name))))
); );
} }
static int static int
filter_av(scan_filter *d) filter_av(scan_filter *d)
{ {
return ( filter_hidden(d) && return ( filter_hidden(d) &&
(filter_type(d) || (filter_type(d) ||
(is_reg(d) && (is_reg(d) &&
(is_audio(d->d_name) || (is_audio(d->d_name) ||
is_video(d->d_name) || is_video(d->d_name) ||
is_playlist(d->d_name)))) is_playlist(d->d_name))))
); );
} }
static int static int
filter_ap(scan_filter *d) filter_ap(scan_filter *d)
{ {
return ( filter_hidden(d) && return ( filter_hidden(d) &&
(filter_type(d) || (filter_type(d) ||
(is_reg(d) && (is_reg(d) &&
(is_audio(d->d_name) || (is_audio(d->d_name) ||
is_image(d->d_name) || is_image(d->d_name) ||
is_playlist(d->d_name)))) is_playlist(d->d_name))))
); );
} }
static int static int
filter_v(scan_filter *d) filter_v(scan_filter *d)
{ {
return ( filter_hidden(d) && return ( filter_hidden(d) &&
(filter_type(d) || (filter_type(d) ||
(is_reg(d) && (is_reg(d) &&
is_video(d->d_name))) is_video(d->d_name)))
); );
} }
static int static int
filter_vp(scan_filter *d) filter_vp(scan_filter *d)
{ {
return ( filter_hidden(d) && return ( filter_hidden(d) &&
(filter_type(d) || (filter_type(d) ||
(is_reg(d) && (is_reg(d) &&
(is_video(d->d_name) || (is_video(d->d_name) ||
is_image(d->d_name)))) is_image(d->d_name))))
); );
} }
static int static int
filter_p(scan_filter *d) filter_p(scan_filter *d)
{ {
return ( filter_hidden(d) && return ( filter_hidden(d) &&
(filter_type(d) || (filter_type(d) ||
(is_reg(d) && (is_reg(d) &&
is_image(d->d_name))) is_image(d->d_name)))
); );
} }
static int static int
filter_avp(scan_filter *d) filter_avp(scan_filter *d)
{ {
return ( filter_hidden(d) && return ( filter_hidden(d) &&
(filter_type(d) || (filter_type(d) ||
(is_reg(d) && (is_reg(d) &&
(is_audio(d->d_name) || (is_audio(d->d_name) ||
is_image(d->d_name) || is_image(d->d_name) ||
is_video(d->d_name) || is_video(d->d_name) ||
is_playlist(d->d_name)))) is_playlist(d->d_name))))
); );
} }
static void static void
ScanDirectory(const char *dir, const char *parent, media_types dir_types) ScanDirectory(const char *dir, const char *parent, media_types dir_types)
{ {
struct dirent **namelist; struct dirent **namelist;
int i, n, startID = 0; int i, n, startID = 0;
char *full_path; char *full_path;
char *name = NULL; char *name = NULL;
static long long unsigned int fileno = 0; static long long unsigned int fileno = 0;
skipping to change at line 740 skipping to change at line 743
{ {
case ALL_MEDIA: case ALL_MEDIA:
n = scandir(dir, &namelist, filter_avp, alphasort); n = scandir(dir, &namelist, filter_avp, alphasort);
break; break;
case TYPE_AUDIO: case TYPE_AUDIO:
n = scandir(dir, &namelist, filter_a, alphasort); n = scandir(dir, &namelist, filter_a, alphasort);
break; break;
case TYPE_AUDIO|TYPE_VIDEO: case TYPE_AUDIO|TYPE_VIDEO:
n = scandir(dir, &namelist, filter_av, alphasort); n = scandir(dir, &namelist, filter_av, alphasort);
break; break;
case TYPE_AUDIO|TYPE_IMAGES: case TYPE_AUDIO|TYPE_IMAGE:
n = scandir(dir, &namelist, filter_ap, alphasort); n = scandir(dir, &namelist, filter_ap, alphasort);
break; break;
case TYPE_VIDEO: case TYPE_VIDEO:
n = scandir(dir, &namelist, filter_v, alphasort); n = scandir(dir, &namelist, filter_v, alphasort);
break; break;
case TYPE_VIDEO|TYPE_IMAGES: case TYPE_VIDEO|TYPE_IMAGE:
n = scandir(dir, &namelist, filter_vp, alphasort); n = scandir(dir, &namelist, filter_vp, alphasort);
break; break;
case TYPE_IMAGES: case TYPE_IMAGE:
n = scandir(dir, &namelist, filter_p, alphasort); n = scandir(dir, &namelist, filter_p, alphasort);
break; break;
default: default:
n = -1; n = -1;
errno = EINVAL; errno = EINVAL;
break; break;
} }
if( n < 0 ) if( n < 0 )
{ {
DPRINTF(E_WARN, L_SCANNER, "Error scanning %s [%s]\n", DPRINTF(E_WARN, L_SCANNER, "Error scanning %s [%s]\n",
skipping to change at line 821 skipping to change at line 824
free(namelist[i]); free(namelist[i]);
} }
free(namelist); free(namelist);
free(full_path); free(full_path);
if( !parent ) if( !parent )
{ {
DPRINTF(E_WARN, L_SCANNER, _("Scanning %s finished (%llu files)!\ n"), dir, fileno); DPRINTF(E_WARN, L_SCANNER, _("Scanning %s finished (%llu files)!\ n"), dir, fileno);
} }
} }
static void
_notify_start(void)
{
#ifdef READYNAS
FILE *flag = fopen("/ramfs/.upnp-av_scan", "w");
if( flag )
fclose(flag);
#endif
}
static void
_notify_stop(void)
{
#ifdef READYNAS
if( access("/ramfs/.rescan_done", F_OK) == 0 )
system("/bin/sh /ramfs/.rescan_done");
unlink("/ramfs/.upnp-av_scan");
#endif
}
/* rescan functions added by shrimpkin@sourceforge.net */ /* rescan functions added by shrimpkin@sourceforge.net */
static int static int
cb_orphans(void *args, int argc, char **argv, char **azColName) cb_orphans(void *args, int argc, char **argv, char **azColName)
{ {
const char *path = argv[0]; const char *path = argv[0];
const char *mime = argv[1]; const char *mime = argv[1];
/* If we can't access the path, remove it */ /* If we can't access the path, remove it */
if (access(path, R_OK) != 0) if (access(path, R_OK) != 0)
{ {
skipping to change at line 869 skipping to change at line 852
} }
void void
start_rescan(void) start_rescan(void)
{ {
struct media_dir_s *media_path; struct media_dir_s *media_path;
char *esc_name = NULL; char *esc_name = NULL;
char *zErrMsg; char *zErrMsg;
const char *sql_files = "SELECT path, mime FROM details WHERE path NOT NU LL AND mime IS NOT NULL;"; const char *sql_files = "SELECT path, mime FROM details WHERE path NOT NU LL AND mime IS NOT NULL;";
const char *sql_dir = "SELECT path, mime FROM details WHERE path NOT NULL AND mime IS NULL;"; const char *sql_dir = "SELECT path, mime FROM details WHERE path NOT NULL AND mime IS NULL;";
int changes = sqlite3_total_changes(db);
const char *summary;
int ret; int ret;
DPRINTF(E_INFO, L_SCANNER, "Starting rescan\n"); DPRINTF(E_INFO, L_SCANNER, "Starting rescan\n");
/* Find and remove any dead directory links */ /* Find and remove any dead directory links */
ret = sqlite3_exec(db, sql_dir, cb_orphans, NULL, &zErrMsg); ret = sqlite3_exec(db, sql_dir, cb_orphans, NULL, &zErrMsg);
if (ret != SQLITE_OK) if (ret != SQLITE_OK)
{ {
DPRINTF(E_MAXDEBUG, L_SCANNER, "SQL error: %s\nBAD SQL: %s\n", zE rrMsg, sql_dir); DPRINTF(E_MAXDEBUG, L_SCANNER, "SQL error: %s\nBAD SQL: %s\n", zE rrMsg, sql_dir);
sqlite3_free(zErrMsg); sqlite3_free(zErrMsg);
skipping to change at line 899 skipping to change at line 884
/* Rescan media_paths for new and/or modified files */ /* Rescan media_paths for new and/or modified files */
for (media_path = media_dirs; media_path != NULL; media_path = media_path ->next) for (media_path = media_dirs; media_path != NULL; media_path = media_path ->next)
{ {
char path[MAXPATHLEN], buf[MAXPATHLEN]; char path[MAXPATHLEN], buf[MAXPATHLEN];
strncpyt(path, media_path->path, sizeof(path)); strncpyt(path, media_path->path, sizeof(path));
strncpyt(buf, media_path->path, sizeof(buf)); strncpyt(buf, media_path->path, sizeof(buf));
esc_name = escape_tag(basename(buf), 1); esc_name = escape_tag(basename(buf), 1);
monitor_insert_directory(0, esc_name, path); monitor_insert_directory(0, esc_name, path);
free(esc_name); free(esc_name);
} }
DPRINTF(E_INFO, L_SCANNER, "Rescan completed\n"); fill_playlists();
if (sqlite3_total_changes(db) != changes)
summary = "changes found";
else
summary = "no changes";
DPRINTF(E_INFO, L_SCANNER, "Rescan completed. (%s)\n", summary);
} }
/* end rescan functions */ /* end rescan functions */
void void
start_scanner() start_scanner(void)
{ {
struct media_dir_s *media_path; struct media_dir_s *media_path;
char path[MAXPATHLEN]; char path[MAXPATHLEN];
if (setpriority(PRIO_PROCESS, 0, 15) == -1) if (setpriority(PRIO_PROCESS, 0, 15) == -1)
DPRINTF(E_WARN, L_INOTIFY, "Failed to reduce scanner thread prio rity\n"); DPRINTF(E_WARN, L_INOTIFY, "Failed to reduce scanner thread prio rity\n");
setlocale(LC_COLLATE, ""); setlocale(LC_COLLATE, "");
av_register_all(); av_register_all();
av_log_set_level(AV_LOG_PANIC); av_log_set_level(AV_LOG_PANIC);
if( rescan_db )
{ if( GETFLAG(RESCAN_MASK) )
start_rescan(); return start_rescan();
return;
}
_notify_start();
for( media_path = media_dirs; media_path != NULL; media_path = media_path ->next ) for( media_path = media_dirs; media_path != NULL; media_path = media_path ->next )
{ {
int64_t id; int64_t id;
char *bname, *parent = NULL; char *bname, *parent = NULL;
char buf[8]; char buf[8];
strncpyt(path, media_path->path, sizeof(path)); strncpyt(path, media_path->path, sizeof(path));
bname = basename(path); bname = basename(path);
/* If there are multiple media locations, add a level to the Cont entDirectory */ /* If there are multiple media locations, add a level to the Cont entDirectory */
if( !GETFLAG(MERGE_MEDIA_DIRS_MASK) && media_dirs->next ) if( !GETFLAG(MERGE_MEDIA_DIRS_MASK) && media_dirs->next )
{ {
skipping to change at line 944 skipping to change at line 932
sprintf(buf, "$%X", startID); sprintf(buf, "$%X", startID);
parent = buf; parent = buf;
} }
else else
id = GetFolderMetadata(bname, media_path->path, NULL, NUL L, 0); id = GetFolderMetadata(bname, media_path->path, NULL, NUL L, 0);
/* Use TIMESTAMP to store the media type */ /* Use TIMESTAMP to store the media type */
sql_exec(db, "UPDATE DETAILS set TIMESTAMP = %d where ID = %lld", media_path->types, (long long)id); sql_exec(db, "UPDATE DETAILS set TIMESTAMP = %d where ID = %lld", media_path->types, (long long)id);
ScanDirectory(media_path->path, parent, media_path->types); ScanDirectory(media_path->path, parent, media_path->types);
sql_exec(db, "INSERT into SETTINGS values (%Q, %Q)", "media_dir", media_path->path); sql_exec(db, "INSERT into SETTINGS values (%Q, %Q)", "media_dir", media_path->path);
} }
_notify_stop();
/* Create this index after scanning, so it doesn't slow down the scanning process. /* Create this index after scanning, so it doesn't slow down the scanning process.
* This index is very useful for large libraries used with an XBox360 (or any * This index is very useful for large libraries used with an XBox360 (or any
* client that uses UPnPSearch on large containers). */ * client that uses UPnPSearch on large containers). */
sql_exec(db, "create INDEX IDX_SEARCH_OPT ON OBJECTS(OBJECT_ID, CLASS, DE TAIL_ID);"); sql_exec(db, "create INDEX IDX_SEARCH_OPT ON OBJECTS(OBJECT_ID, CLASS, DE TAIL_ID);");
if( GETFLAG(NO_PLAYLIST_MASK) ) fill_playlists();
{
DPRINTF(E_WARN, L_SCANNER, "Playlist creation disabled\n");
}
else
{
fill_playlists();
}
DPRINTF(E_DEBUG, L_SCANNER, "Initial file scan completed\n"); DPRINTF(E_DEBUG, L_SCANNER, "Initial file scan completed\n");
//JM: Set up a db version number, so we know if we need to rebuild due to a new structure. //JM: Set up a db version number, so we know if we need to rebuild due to a new structure.
sql_exec(db, "pragma user_version = %d;", DB_VERSION); sql_exec(db, "pragma user_version = %d;", DB_VERSION);
} }
 End of changes. 45 change blocks. 
84 lines changed or deleted 64 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)