[db,jsonapi,smartpl] db usermark flag review

This commit is contained in:
whatdoineed2do/Ray 2021-09-08 14:51:55 +01:00
parent e65203e1e2
commit d43ce017f5
6 changed files with 42 additions and 36 deletions

View File

@ -102,7 +102,7 @@ INTTAG : 'play_count'
| 'bits_per_sample' | 'bits_per_sample'
| 'samplerate' | 'samplerate'
| 'song_length' | 'song_length'
| 'flag' | 'usermark'
; ;
DATETAG : 'time_added' DATETAG : 'time_added'

View File

@ -227,7 +227,7 @@ static const struct col_type_map mfi_cols_map[] =
{ "album_artist_sort", mfi_offsetof(album_artist_sort), DB_TYPE_STRING, DB_FIXUP_ALBUM_ARTIST_SORT }, { "album_artist_sort", mfi_offsetof(album_artist_sort), DB_TYPE_STRING, DB_FIXUP_ALBUM_ARTIST_SORT },
{ "composer_sort", mfi_offsetof(composer_sort), DB_TYPE_STRING, DB_FIXUP_COMPOSER_SORT }, { "composer_sort", mfi_offsetof(composer_sort), DB_TYPE_STRING, DB_FIXUP_COMPOSER_SORT },
{ "channels", mfi_offsetof(channels), DB_TYPE_INT }, { "channels", mfi_offsetof(channels), DB_TYPE_INT },
{ "flag", mfi_offsetof(flag), DB_TYPE_INT }, { "usermark", mfi_offsetof(usermark), DB_TYPE_INT },
}; };
/* This list must be kept in sync with /* This list must be kept in sync with
@ -295,7 +295,7 @@ static const struct col_type_map qi_cols_map[] =
{ "bitrate", qi_offsetof(bitrate), DB_TYPE_INT }, { "bitrate", qi_offsetof(bitrate), DB_TYPE_INT },
{ "samplerate", qi_offsetof(samplerate), DB_TYPE_INT }, { "samplerate", qi_offsetof(samplerate), DB_TYPE_INT },
{ "channels", qi_offsetof(channels), DB_TYPE_INT }, { "channels", qi_offsetof(channels), DB_TYPE_INT },
{ "flag", qi_offsetof(flag), DB_TYPE_INT }, { "usermark", qi_offsetof(usermark), DB_TYPE_INT },
}; };
/* This list must be kept in sync with /* This list must be kept in sync with
@ -367,7 +367,7 @@ static const ssize_t dbmfi_cols_map[] =
dbmfi_offsetof(album_artist_sort), dbmfi_offsetof(album_artist_sort),
dbmfi_offsetof(composer_sort), dbmfi_offsetof(composer_sort),
dbmfi_offsetof(channels), dbmfi_offsetof(channels),
dbmfi_offsetof(flag), dbmfi_offsetof(usermark),
}; };
/* This list must be kept in sync with /* This list must be kept in sync with
@ -456,7 +456,7 @@ static const struct qi_mfi_map qi_mfi_map[] =
{ qi_offsetof(bitrate), mfi_offsetof(bitrate), dbmfi_offsetof(bitrate) }, { qi_offsetof(bitrate), mfi_offsetof(bitrate), dbmfi_offsetof(bitrate) },
{ qi_offsetof(samplerate), mfi_offsetof(samplerate), dbmfi_offsetof(samplerate) }, { qi_offsetof(samplerate), mfi_offsetof(samplerate), dbmfi_offsetof(samplerate) },
{ qi_offsetof(channels), mfi_offsetof(channels), dbmfi_offsetof(channels) }, { qi_offsetof(channels), mfi_offsetof(channels), dbmfi_offsetof(channels) },
{ qi_offsetof(flag), mfi_offsetof(flag), dbmfi_offsetof(flag) }, { qi_offsetof(usermark), mfi_offsetof(usermark), dbmfi_offsetof(usermark) },
}; };
/* This list must be kept in sync with /* This list must be kept in sync with
@ -3325,20 +3325,20 @@ db_file_rating_update_byvirtualpath(const char *virtual_path, uint32_t rating)
} }
int int
db_file_flag_update_byid(uint32_t id, uint32_t flag) db_file_usermark_update_byid(uint32_t id, uint32_t usermark)
{ {
#define Q_TMPL "UPDATE files SET flag = %d WHERE id = %d;" #define Q_TMPL "UPDATE files SET usermark = %d WHERE id = %d;"
char *query; char *query;
int ret; int ret;
query = sqlite3_mprintf(Q_TMPL, flag, id); query = sqlite3_mprintf(Q_TMPL, usermark, id);
ret = db_query_run(query, 1, 0); ret = db_query_run(query, 1, 0);
if (ret == 0) if (ret == 0)
{ {
db_admin_setint64(DB_ADMIN_DB_MODIFIED, (int64_t) time(NULL)); db_admin_setint64(DB_ADMIN_DB_MODIFIED, (int64_t) time(NULL));
listener_notify(LISTENER_RATING); listener_notify(LISTENER_UPDATE);
} }
return ((ret < 0) ? -1 : sqlite3_changes(hdl)); return ((ret < 0) ? -1 : sqlite3_changes(hdl));

View File

@ -142,16 +142,17 @@ const char *
db_data_kind_label(enum data_kind data_kind); db_data_kind_label(enum data_kind data_kind);
/* Indicates user marked status on a track */ /* Indicates user marked status on a track - values can be bitwise enumerated */
enum flag_kind { enum user_mark {
FLAG_KIND_NA = 0, // unset USER_MARK_NA = 0,
FLAG_KIND_DELETE, USER_MARK_DELETE = 1,
FLAG_KIND_REXCODE, USER_MARK_REXCODE = 2,
FLAG_KIND_REVIEW, USER_MARK_REVIEW = 4
FLAG_KIND_MAX // unused - keep last in enum
}; };
#define DB_FILES_USERMARK_MAX UINT_MAX
/* Note that fields marked as integers in the metadata map in filescanner_ffmpeg must be uint32_t here */ /* Note that fields marked as integers in the metadata map in filescanner_ffmpeg must be uint32_t here */
struct media_file_info { struct media_file_info {
uint32_t id; uint32_t id;
@ -209,7 +210,7 @@ struct media_file_info {
uint32_t time_skipped; uint32_t time_skipped;
int64_t disabled; // Long because it stores up to INOTIFY_FAKE_COOKIE int64_t disabled; // Long because it stores up to INOTIFY_FAKE_COOKIE
uint32_t flag; // See enum flag_kind { } uint32_t usermark; // See enum user_mark { }
uint64_t sample_count; //TODO [unused] sample count is never set and therefor always 0 uint64_t sample_count; //TODO [unused] sample count is never set and therefor always 0
char *codectype; /* song.codectype, 4 chars max (32 bits) */ char *codectype; /* song.codectype, 4 chars max (32 bits) */
@ -405,7 +406,7 @@ struct db_media_file_info {
char *album_artist_sort; char *album_artist_sort;
char *composer_sort; char *composer_sort;
char *channels; char *channels;
char *flag; char *usermark;
}; };
#define dbmfi_offsetof(field) offsetof(struct db_media_file_info, field) #define dbmfi_offsetof(field) offsetof(struct db_media_file_info, field)
@ -515,7 +516,7 @@ struct db_queue_item {
int64_t songartistid; int64_t songartistid;
uint32_t flag; uint32_t usermark;
/* Not saved in queue table */ /* Not saved in queue table */
uint32_t seek; uint32_t seek;
@ -667,7 +668,7 @@ int
db_file_rating_update_byid(uint32_t id, uint32_t rating); db_file_rating_update_byid(uint32_t id, uint32_t rating);
int int
db_file_flag_update_byid(uint32_t id, uint32_t rating); db_file_usermark_update_byid(uint32_t id, uint32_t usermark);
int int
db_file_rating_update_byvirtualpath(const char *virtual_path, uint32_t rating); db_file_rating_update_byvirtualpath(const char *virtual_path, uint32_t rating);

View File

@ -97,7 +97,7 @@
" album_artist_sort VARCHAR(1024) DEFAULT NULL COLLATE DAAP," \ " album_artist_sort VARCHAR(1024) DEFAULT NULL COLLATE DAAP," \
" composer_sort VARCHAR(1024) DEFAULT NULL COLLATE DAAP," \ " composer_sort VARCHAR(1024) DEFAULT NULL COLLATE DAAP," \
" channels INTEGER DEFAULT 0," \ " channels INTEGER DEFAULT 0," \
" flag INTEGER DEFAULT 0" \ " usermark INTEGER DEFAULT 0" \
");" ");"
#define T_PL \ #define T_PL \
@ -201,7 +201,7 @@
" bitrate INTEGER DEFAULT 0," \ " bitrate INTEGER DEFAULT 0," \
" samplerate INTEGER DEFAULT 0," \ " samplerate INTEGER DEFAULT 0," \
" channels INTEGER DEFAULT 0," \ " channels INTEGER DEFAULT 0," \
" flag INTEGER DEFAULT 0" \ " usermark INTEGER DEFAULT 0" \
");" ");"
#define Q_PL1 \ #define Q_PL1 \

View File

@ -1161,17 +1161,17 @@ static const struct db_upgrade_query db_upgrade_v2106_queries[] =
}; };
/* ---------------------------- 21.06 -> 21.07 ------------------------------ */ /* ---------------------------- 21.06 -> 21.07 ------------------------------ */
#define U_v2107_ALTER_FILES_PENDING_DELETE \ #define U_v2107_ALTER_FILES_USERMARK \
"ALTER TABLE files ADD COLUMN flag INTEGER DEFAULT 0;" "ALTER TABLE files ADD COLUMN usermark INTEGER DEFAULT 0;"
#define U_v2107_ALTER_QUEUE_PENDING_DELETE \ #define U_v2107_ALTER_QUEUE_USERMARK \
"ALTER TABLE queue ADD COLUMN flag INTEGER DEFAULT 0;" "ALTER TABLE queue ADD COLUMN usermark INTEGER DEFAULT 0;"
#define U_v2107_SCVER_MINOR \ #define U_v2107_SCVER_MINOR \
"UPDATE admin SET value = '07' WHERE key = 'schema_version_minor';" "UPDATE admin SET value = '07' WHERE key = 'schema_version_minor';"
static const struct db_upgrade_query db_upgrade_v2107_queries[] = static const struct db_upgrade_query db_upgrade_v2107_queries[] =
{ {
{ U_v2107_ALTER_FILES_PENDING_DELETE, "update files adding flag" }, { U_v2107_ALTER_FILES_USERMARK, "update files adding usermark" },
{ U_v2107_ALTER_QUEUE_PENDING_DELETE, "update queue adding flag" }, { U_v2107_ALTER_QUEUE_USERMARK, "update queue adding usermark" },
{ U_v2107_SCVER_MINOR, "set schema_version_minor to 07" }, { U_v2107_SCVER_MINOR, "set schema_version_minor to 07" },
}; };

View File

@ -311,7 +311,7 @@ track_to_json(struct db_media_file_info *dbmfi)
safe_json_add_int_from_string(item, "samplerate", dbmfi->samplerate); safe_json_add_int_from_string(item, "samplerate", dbmfi->samplerate);
safe_json_add_int_from_string(item, "bitrate", dbmfi->bitrate); safe_json_add_int_from_string(item, "bitrate", dbmfi->bitrate);
safe_json_add_int_from_string(item, "channels", dbmfi->channels); safe_json_add_int_from_string(item, "channels", dbmfi->channels);
safe_json_add_int_from_string(item, "flag", dbmfi->flag); safe_json_add_int_from_string(item, "usermark", dbmfi->usermark);
ret = safe_atoi32(dbmfi->media_kind, &intval); ret = safe_atoi32(dbmfi->media_kind, &intval);
if (ret == 0) if (ret == 0)
@ -2222,7 +2222,7 @@ queue_item_to_json(struct db_queue_item *queue_item, char shuffle)
json_object_object_add(item, "bitrate", json_object_new_int(queue_item->bitrate)); json_object_object_add(item, "bitrate", json_object_new_int(queue_item->bitrate));
json_object_object_add(item, "samplerate", json_object_new_int(queue_item->samplerate)); json_object_object_add(item, "samplerate", json_object_new_int(queue_item->samplerate));
json_object_object_add(item, "channels", json_object_new_int(queue_item->channels)); json_object_object_add(item, "channels", json_object_new_int(queue_item->channels));
json_object_object_add(item, "flag", json_object_new_int(queue_item->flag)); json_object_object_add(item, "usermark", json_object_new_int(queue_item->usermark));
return item; return item;
} }
@ -3300,6 +3300,7 @@ jsonapi_reply_library_tracks_put_byid(struct httpd_request *hreq)
int track_id; int track_id;
const char *param; const char *param;
int val; int val;
uint32_t uval;
int ret; int ret;
ret = safe_atoi32(hreq->uri_parsed->path_parts[3], &track_id); ret = safe_atoi32(hreq->uri_parsed->path_parts[3], &track_id);
@ -3341,15 +3342,19 @@ jsonapi_reply_library_tracks_put_byid(struct httpd_request *hreq)
return HTTP_INTERNAL; return HTTP_INTERNAL;
} }
// retreive via "/api/search?type=tracks&expression=flag+=+1" // Update usermark
param = evhttp_find_header(hreq->query, "flag"); // retreive via "/api/search?type=tracks&expression=usermark+=+1"
param = evhttp_find_header(hreq->query, "usermark");
if (param) if (param)
{ {
ret = safe_atoi32(param, &val); ret = safe_atou32(param, &uval);
if (ret < 0 || (ret == 0 && (val < FLAG_KIND_NA || val >= FLAG_KIND_MAX)) ) if (ret < 0)
return HTTP_BADREQUEST; return HTTP_BADREQUEST;
ret = db_file_flag_update_byid(track_id, val); if (uval >= 0 && uval <= DB_FILES_USERMARK_MAX)
ret = db_file_usermark_update_byid(track_id, uval);
else
DPRINTF(E_WARN, L_WEB, "Ignoring invalid usermark value '%u' for track '%d'.\n", uval, track_id);
if (ret < 0) if (ret < 0)
return HTTP_INTERNAL; return HTTP_INTERNAL;