diff --git a/scanner.c b/scanner.c index e0a3bfd..39d392d 100644 --- a/scanner.c +++ b/scanner.c @@ -95,10 +95,11 @@ insert_container(const char * item, const char * rootParent, const char * refID, const char *artist, const char *genre, const char *album_art, const char *art_dlna_pn) { char **result; + char **result2; char *sql; int cols, rows, ret; int parentID = 0, objectID = 0; - sqlite_int64 detailID; + sqlite_int64 detailID = 0; sql = sqlite3_mprintf("SELECT OBJECT_ID from OBJECTS where OBJECT_ID glob '%s$*' and NAME = '%q'", rootParent, item); ret = sql_get_table(db, sql, &result, &rows, &cols); @@ -111,7 +112,24 @@ insert_container(const char * item, const char * rootParent, const char * refID, else { parentID = get_next_available_id("OBJECTS", rootParent); - detailID = GetFolderMetadata(item, NULL, artist, genre, album_art, art_dlna_pn); + if( refID ) + { + sql = sqlite3_mprintf("SELECT DETAIL_ID from OBJECTS where OBJECT_ID = %Q", refID); + ret = sql_get_table(db, sql, &result2, &rows, NULL); + if( ret == SQLITE_OK ) + { + if( rows ) + { + detailID = strtoll(result2[1], NULL, 10); + } + sqlite3_free_table(result2); + } + sqlite3_free(sql); + } + if( !detailID ) + { + detailID = GetFolderMetadata(item, NULL, artist, genre, album_art, art_dlna_pn); + } sql = sqlite3_mprintf( "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) " "VALUES" diff --git a/upnpsoap.c b/upnpsoap.c index 0962ddb..af5992a 100644 --- a/upnpsoap.c +++ b/upnpsoap.c @@ -298,7 +298,10 @@ static int callback(void *args, int argc, char **argv, char **azColName) strcat(passed_args->resp, str_buf); } if( bitrate && (!passed_args->filter || strstr(passed_args->filter, "res@bitrate")) ) { - sprintf(str_buf, "bitrate=\"%s\" ", bitrate); + if( passed_args->client == EXbox ) + sprintf(str_buf, "bitrate=\"%d\" ", atoi(bitrate)/1024); + else + sprintf(str_buf, "bitrate=\"%s\" ", bitrate); strcat(passed_args->resp, str_buf); } if( sampleFrequency && (!passed_args->filter || strstr(passed_args->filter, "res@sampleFrequency")) ) { @@ -536,6 +539,7 @@ SearchContentDirectory(struct upnphttp * h, const char * action) args.requested = RequestedCount; args.resp = NULL; args.filter = NULL; + args.client = h->req_client; if( h->req_client == EXbox ) { if( strcmp(ContainerID, "4") == 0 ) @@ -600,15 +604,15 @@ SearchContentDirectory(struct upnphttp * h, const char * action) DPRINTF(E_DEBUG, L_HTTP, "Translated SearchCriteria: %s\n", SearchCriteria); args.resp = resp; - sql = sqlite3_mprintf("SELECT * from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)" - " where OBJECT_ID glob '%s$*' and (%s) " + sql = sqlite3_mprintf("SELECT distinct * from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)" + " where OBJECT_ID glob '%s$*' and (%s) group by DETAIL_ID " "%z" " order by d.TRACK, d.TITLE, o.NAME limit %d, -1;", - ContainerID, SearchCriteria, - (*ContainerID == '*') ? NULL : - sqlite3_mprintf("UNION ALL SELECT * from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)" - " where OBJECT_ID = '%s' and (%s) ", ContainerID, SearchCriteria), - StartingIndex); + ContainerID, SearchCriteria, + (*ContainerID == '*') ? NULL : + sqlite3_mprintf("UNION ALL SELECT * from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)" + " where OBJECT_ID = '%s' and (%s) ", ContainerID, SearchCriteria), + StartingIndex); DPRINTF(E_DEBUG, L_HTTP, "Search SQL: %s\n", sql); ret = sqlite3_exec(db, sql, callback, (void *) &args, &zErrMsg); if( ret != SQLITE_OK )