scanner: Add an extra level if there are multiple media locations.
Before, the top level of folder browsing could be messy if you were using multiple media directories. This should tidyt things up.
This commit is contained in:
parent
16b0963a5b
commit
5b35d3a165
74
scanner.c
74
scanner.c
@ -382,7 +382,7 @@ insert_containers(const char *name, const char *path, const char *refID, const c
|
||||
valid_cache = 1;
|
||||
}
|
||||
|
||||
int
|
||||
int64_t
|
||||
insert_directory(const char *name, const char *path, const char *base, const char *parentID, int objectID)
|
||||
{
|
||||
int64_t detailID = 0;
|
||||
@ -440,7 +440,8 @@ insert_directory(const char *name, const char *path, const char *base, const cha
|
||||
"VALUES"
|
||||
" ('%s%s$%X', '%s%s', %lld, '%s', '%q')",
|
||||
base, parentID, objectID, base, parentID, detailID, class, name);
|
||||
return 0;
|
||||
|
||||
return detailID;
|
||||
}
|
||||
|
||||
int
|
||||
@ -688,7 +689,7 @@ filter_avp(scan_filter *d)
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
ScanDirectory(const char *dir, const char *parent, media_types dir_types)
|
||||
{
|
||||
struct dirent **namelist;
|
||||
@ -779,40 +780,63 @@ ScanDirectory(const char *dir, const char *parent, media_types dir_types)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
start_scanner()
|
||||
static void
|
||||
_notify_start(void)
|
||||
{
|
||||
struct media_dir_s *media_path = media_dirs;
|
||||
char name[MAXPATHLEN];
|
||||
|
||||
if (setpriority(PRIO_PROCESS, 0, 15) == -1)
|
||||
DPRINTF(E_WARN, L_INOTIFY, "Failed to reduce scanner thread priority\n");
|
||||
|
||||
#ifdef READYNAS
|
||||
FILE *flag = fopen("/ramfs/.upnp-av_scan", "w");
|
||||
if( flag )
|
||||
fclose(flag);
|
||||
#endif
|
||||
setlocale(LC_COLLATE, "");
|
||||
}
|
||||
|
||||
av_register_all();
|
||||
av_log_set_level(AV_LOG_PANIC);
|
||||
while( media_path )
|
||||
{
|
||||
int64_t id;
|
||||
strncpyt(name, media_path->path, sizeof(name));
|
||||
id = GetFolderMetadata(basename(name), media_path->path, NULL, NULL, 0);
|
||||
/* Use TIMESTAMP to store the media type */
|
||||
sql_exec(db, "UPDATE DETAILS set TIMESTAMP = %d where ID = %lld", media_path->types, (long long)id);
|
||||
ScanDirectory(media_path->path, NULL, media_path->types);
|
||||
sql_exec(db, "INSERT into SETTINGS values (%Q, %Q)", "media_dir", media_path->path);
|
||||
media_path = media_path->next;
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
void
|
||||
start_scanner()
|
||||
{
|
||||
struct media_dir_s *media_path;
|
||||
char path[MAXPATHLEN];
|
||||
|
||||
if (setpriority(PRIO_PROCESS, 0, 15) == -1)
|
||||
DPRINTF(E_WARN, L_INOTIFY, "Failed to reduce scanner thread priority\n");
|
||||
_notify_start();
|
||||
|
||||
setlocale(LC_COLLATE, "");
|
||||
|
||||
av_register_all();
|
||||
av_log_set_level(AV_LOG_PANIC);
|
||||
for( media_path = media_dirs; media_path != NULL; media_path = media_path->next )
|
||||
{
|
||||
int64_t id;
|
||||
char *bname, *parent = NULL;
|
||||
char buf[8];
|
||||
strncpyt(path, media_path->path, sizeof(path));
|
||||
bname = basename(path);
|
||||
/* If there are multiple media locations, add a level to the ContentDirectory */
|
||||
if( media_dirs && media_dirs->next )
|
||||
{
|
||||
int startID = get_next_available_id("OBJECTS", BROWSEDIR_ID);
|
||||
id = insert_directory(bname, path, BROWSEDIR_ID, "", startID);
|
||||
sprintf(buf, "$%X", startID);
|
||||
parent = buf;
|
||||
}
|
||||
else
|
||||
id = GetFolderMetadata(bname, media_path->path, NULL, NULL, 0);
|
||||
/* Use TIMESTAMP to store the media type */
|
||||
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);
|
||||
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.
|
||||
* This index is very useful for large libraries used with an XBox360 (or any
|
||||
* client that uses UPnPSearch on large containers). */
|
||||
|
Loading…
x
Reference in New Issue
Block a user