Пример #1
0
int64_t
get_next_available_id(const char *table, const char *parentID)
{
		char *ret, *base;
		int64_t objectID = 0;

		ret = sql_get_text_field(db, "SELECT OBJECT_ID from %s where ID = "
		                             "(SELECT max(ID) from %s where PARENT_ID = '%s')",
		                             table, table, parentID);
		if( ret )
		{
			base = strrchr(ret, '$');
			if( base )
				objectID = strtoll(base+1, NULL, 16) + 1;
			sqlite3_free(ret);
		}

		return objectID;
}
void
check_for_captions(const char *path, int64_t detailID)
{
	char *file = malloc(MAXPATHLEN);
	char *id = NULL;

	sprintf(file, "%s", path);
	strip_ext(file);

	/* If we weren't given a detail ID, look for one. */
	if( !detailID )
	{
		id = sql_get_text_field(db, "SELECT ID from DETAILS where (PATH > '%q.' and PATH <= '%q.z')"
		                            " and MIME glob 'video/*' limit 1", file, file);
		if( id )
		{
			DPRINTF(E_DEBUG, L_METADATA, "New file %s looks like a caption file.\n", path);
			detailID = strtoll(id, NULL, 10);
		}
		else
		{
			DPRINTF(E_DEBUG, L_METADATA, "No file found for caption %s.\n", path);
			goto no_source_video;
		}
	}

	strcat(file, ".srt");
        DPRINTF(E_DEBUG, L_METADATA, "search %s.\n", file);
	if( access(file, R_OK) == 0 )
	{
		sql_exec(db, "INSERT into CAPTIONS"
		             " (ID, PATH) "
		             "VALUES"
		             " (%lld, %Q)", detailID, file);
                DPRINTF(E_DEBUG, L_INOTIFY, "INSERT into CAPTIONS (%lld, %s).\n", detailID, file);
	}
no_source_video:
	if( id )
		sqlite3_free(id);
	free(file);
}
Пример #3
0
int
fill_playlists()
{
	int rows, i, found, len;
	char **result;
	char *plpath, *plname, *fname, *last_dir;
	unsigned int hash, last_hash = 0;
	char class[] = "playlistContainer";
	struct song_metadata plist;
	struct stat file;
	char type[4];
	sqlite_int64 plID, detailID;
	char sql_buf[] = "SELECT ID, NAME, PATH from PLAYLISTS where ITEMS > FOUND";

	DPRINTF(E_WARN, L_SCANNER, "Parsing playlists...\n");

	if( sql_get_table(db, sql_buf, &result, &rows, NULL) != SQLITE_OK ) 
		return -1;
	if( !rows )
		goto done;

	rows++;
	for( i=3; i<rows*3; i++ )
	{
		plID = strtoll(result[i], NULL, 10);
		plname = result[++i];
		plpath = result[++i];
		last_dir = NULL;
		last_hash = 0;

		strncpy(type, strrchr(plpath, '.')+1, 4);

		if( start_plist(plpath, NULL, &file, NULL, type) != 0 )
			continue;

		DPRINTF(E_DEBUG, L_SCANNER, "Scanning playlist \"%s\" [%s]\n", plname, plpath);
		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, 0);
			sql_exec(db, "INSERT into OBJECTS"
			             " (OBJECT_ID, PARENT_ID, DETAIL_ID, CLASS, NAME) "
			             "VALUES"
			             " ('%s$%llX', '%s', %lld, 'container.%s', '%q')",
			             MUSIC_PLIST_ID, plID, MUSIC_PLIST_ID, detailID, class, plname);
		}

		plpath = dirname(plpath);
		found = 0;
		while( next_plist_track(&plist, &file, NULL, type) == 0 )
		{
			hash = gen_dir_hash(plist.path);
			if( sql_get_int_field(db, "SELECT 1 from OBJECTS where OBJECT_ID = '%s$%llX$%d'",
			                      MUSIC_PLIST_ID, plID, plist.track) == 1 )
			{
				//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "%d: already in database\n", plist.track);
				found++;
       				freetags(&plist);
				continue;
			}
			if( last_dir )
			{
				if( hash == last_hash )
				{
					fname = basename(plist.path);
					detailID = sql_get_int_field(db, "SELECT ID from DETAILS where PATH = '%q/%q'", last_dir, fname);
				}
				else
					detailID = -1;
				if( detailID <= 0 )
				{
					sqlite3_free(last_dir);
					last_dir = NULL;
				}
				else
					goto found;
			}
			
			fname = plist.path;
			DPRINTF(E_DEBUG, L_SCANNER, "%d: checking database for %s\n", plist.track, plist.path);
			if( !strpbrk(fname, "\\/") )
			{
				len = strlen(fname) + strlen(plpath) + 2;
				plist.path = malloc(len);
				snprintf(plist.path, len, "%s/%s", plpath, fname);
				free(fname);
				fname = plist.path;
			}
			else
			{
				while( *fname == '\\' )
				{
					fname++;
				}
			}
retry:
			//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "* Searching for %s in db\n", fname);
			detailID = sql_get_int_field(db, "SELECT ID from DETAILS where PATH like '%%%q'", fname);
			if( detailID > 0 )
			{
found:
				DPRINTF(E_DEBUG, L_SCANNER, "+ %s found in db\n", fname);
				sql_exec(db, "INSERT into OBJECTS"
				             " (OBJECT_ID, PARENT_ID, CLASS, DETAIL_ID, NAME, REF_ID) "
				             "SELECT"
				             " '%s$%llX$%d', '%s$%llX', CLASS, DETAIL_ID, NAME, OBJECT_ID from OBJECTS"
				             " where DETAIL_ID = %lld and OBJECT_ID glob '" BROWSEDIR_ID "$*'",
				             MUSIC_PLIST_ID, plID, plist.track,
				             MUSIC_PLIST_ID, plID,
				             detailID);
				if( !last_dir )
				{
					last_dir = sql_get_text_field(db, "SELECT PATH from DETAILS where ID = %lld", detailID);
					fname = strrchr(last_dir, '/');
					if( fname )
						*fname = '\0';
					last_hash = hash;
				}
				found++;
			}
			else
			{
				DPRINTF(E_DEBUG, L_SCANNER, "- %s not found in db\n", fname);
				if( strchr(fname, '\\') )
				{
					fname = modifyString(fname, "\\", "/", 0);
					goto retry;
				}
				else if( (fname = strchr(fname, '/')) )
				{
					fname++;
					goto retry;
				}
			}
       			freetags(&plist);
		}
		if( last_dir )
		{
			sqlite3_free(last_dir);
			last_dir = NULL;
		}
		sql_exec(db, "UPDATE PLAYLISTS set FOUND = %d where ID = %lld", found, plID);
	}