mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-28 16:15:57 -05:00
[db,jsonapi,smartpl] db usermark flag review
This commit is contained in:
parent
e65203e1e2
commit
d43ce017f5
@ -102,7 +102,7 @@ INTTAG : 'play_count'
|
||||
| 'bits_per_sample'
|
||||
| 'samplerate'
|
||||
| 'song_length'
|
||||
| 'flag'
|
||||
| 'usermark'
|
||||
;
|
||||
|
||||
DATETAG : 'time_added'
|
||||
|
16
src/db.c
16
src/db.c
@ -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 },
|
||||
{ "composer_sort", mfi_offsetof(composer_sort), DB_TYPE_STRING, DB_FIXUP_COMPOSER_SORT },
|
||||
{ "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
|
||||
@ -295,7 +295,7 @@ static const struct col_type_map qi_cols_map[] =
|
||||
{ "bitrate", qi_offsetof(bitrate), DB_TYPE_INT },
|
||||
{ "samplerate", qi_offsetof(samplerate), 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
|
||||
@ -367,7 +367,7 @@ static const ssize_t dbmfi_cols_map[] =
|
||||
dbmfi_offsetof(album_artist_sort),
|
||||
dbmfi_offsetof(composer_sort),
|
||||
dbmfi_offsetof(channels),
|
||||
dbmfi_offsetof(flag),
|
||||
dbmfi_offsetof(usermark),
|
||||
};
|
||||
|
||||
/* 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(samplerate), mfi_offsetof(samplerate), dbmfi_offsetof(samplerate) },
|
||||
{ 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
|
||||
@ -3325,20 +3325,20 @@ db_file_rating_update_byvirtualpath(const char *virtual_path, uint32_t rating)
|
||||
}
|
||||
|
||||
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;
|
||||
int ret;
|
||||
|
||||
query = sqlite3_mprintf(Q_TMPL, flag, id);
|
||||
query = sqlite3_mprintf(Q_TMPL, usermark, id);
|
||||
|
||||
ret = db_query_run(query, 1, 0);
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
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));
|
||||
|
25
src/db.h
25
src/db.h
@ -142,16 +142,17 @@ const char *
|
||||
db_data_kind_label(enum data_kind data_kind);
|
||||
|
||||
|
||||
/* Indicates user marked status on a track */
|
||||
enum flag_kind {
|
||||
FLAG_KIND_NA = 0, // unset
|
||||
FLAG_KIND_DELETE,
|
||||
FLAG_KIND_REXCODE,
|
||||
FLAG_KIND_REVIEW,
|
||||
|
||||
FLAG_KIND_MAX // unused - keep last in enum
|
||||
/* Indicates user marked status on a track - values can be bitwise enumerated */
|
||||
enum user_mark {
|
||||
USER_MARK_NA = 0,
|
||||
USER_MARK_DELETE = 1,
|
||||
USER_MARK_REXCODE = 2,
|
||||
USER_MARK_REVIEW = 4
|
||||
};
|
||||
|
||||
#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 */
|
||||
struct media_file_info {
|
||||
uint32_t id;
|
||||
@ -209,7 +210,7 @@ struct media_file_info {
|
||||
uint32_t time_skipped;
|
||||
|
||||
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
|
||||
char *codectype; /* song.codectype, 4 chars max (32 bits) */
|
||||
@ -405,7 +406,7 @@ struct db_media_file_info {
|
||||
char *album_artist_sort;
|
||||
char *composer_sort;
|
||||
char *channels;
|
||||
char *flag;
|
||||
char *usermark;
|
||||
};
|
||||
|
||||
#define dbmfi_offsetof(field) offsetof(struct db_media_file_info, field)
|
||||
@ -515,7 +516,7 @@ struct db_queue_item {
|
||||
|
||||
int64_t songartistid;
|
||||
|
||||
uint32_t flag;
|
||||
uint32_t usermark;
|
||||
|
||||
/* Not saved in queue table */
|
||||
uint32_t seek;
|
||||
@ -667,7 +668,7 @@ int
|
||||
db_file_rating_update_byid(uint32_t id, uint32_t rating);
|
||||
|
||||
int
|
||||
db_file_flag_update_byid(uint32_t id, uint32_t rating);
|
||||
db_file_usermark_update_byid(uint32_t id, uint32_t usermark);
|
||||
|
||||
int
|
||||
db_file_rating_update_byvirtualpath(const char *virtual_path, uint32_t rating);
|
||||
|
@ -97,7 +97,7 @@
|
||||
" album_artist_sort VARCHAR(1024) DEFAULT NULL COLLATE DAAP," \
|
||||
" composer_sort VARCHAR(1024) DEFAULT NULL COLLATE DAAP," \
|
||||
" channels INTEGER DEFAULT 0," \
|
||||
" flag INTEGER DEFAULT 0" \
|
||||
" usermark INTEGER DEFAULT 0" \
|
||||
");"
|
||||
|
||||
#define T_PL \
|
||||
@ -201,7 +201,7 @@
|
||||
" bitrate INTEGER DEFAULT 0," \
|
||||
" samplerate INTEGER DEFAULT 0," \
|
||||
" channels INTEGER DEFAULT 0," \
|
||||
" flag INTEGER DEFAULT 0" \
|
||||
" usermark INTEGER DEFAULT 0" \
|
||||
");"
|
||||
|
||||
#define Q_PL1 \
|
||||
|
@ -1161,17 +1161,17 @@ static const struct db_upgrade_query db_upgrade_v2106_queries[] =
|
||||
};
|
||||
|
||||
/* ---------------------------- 21.06 -> 21.07 ------------------------------ */
|
||||
#define U_v2107_ALTER_FILES_PENDING_DELETE \
|
||||
"ALTER TABLE files ADD COLUMN flag INTEGER DEFAULT 0;"
|
||||
#define U_v2107_ALTER_QUEUE_PENDING_DELETE \
|
||||
"ALTER TABLE queue ADD COLUMN flag INTEGER DEFAULT 0;"
|
||||
#define U_v2107_ALTER_FILES_USERMARK \
|
||||
"ALTER TABLE files ADD COLUMN usermark INTEGER DEFAULT 0;"
|
||||
#define U_v2107_ALTER_QUEUE_USERMARK \
|
||||
"ALTER TABLE queue ADD COLUMN usermark INTEGER DEFAULT 0;"
|
||||
#define U_v2107_SCVER_MINOR \
|
||||
"UPDATE admin SET value = '07' WHERE key = 'schema_version_minor';"
|
||||
|
||||
static const struct db_upgrade_query db_upgrade_v2107_queries[] =
|
||||
{
|
||||
{ U_v2107_ALTER_FILES_PENDING_DELETE, "update files adding flag" },
|
||||
{ U_v2107_ALTER_QUEUE_PENDING_DELETE, "update queue adding flag" },
|
||||
{ U_v2107_ALTER_FILES_USERMARK, "update files adding usermark" },
|
||||
{ U_v2107_ALTER_QUEUE_USERMARK, "update queue adding usermark" },
|
||||
|
||||
{ U_v2107_SCVER_MINOR, "set schema_version_minor to 07" },
|
||||
};
|
||||
|
@ -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, "bitrate", dbmfi->bitrate);
|
||||
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);
|
||||
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, "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, "flag", json_object_new_int(queue_item->flag));
|
||||
json_object_object_add(item, "usermark", json_object_new_int(queue_item->usermark));
|
||||
|
||||
return item;
|
||||
}
|
||||
@ -3300,6 +3300,7 @@ jsonapi_reply_library_tracks_put_byid(struct httpd_request *hreq)
|
||||
int track_id;
|
||||
const char *param;
|
||||
int val;
|
||||
uint32_t uval;
|
||||
int ret;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// retreive via "/api/search?type=tracks&expression=flag+=+1"
|
||||
param = evhttp_find_header(hreq->query, "flag");
|
||||
// Update usermark
|
||||
// retreive via "/api/search?type=tracks&expression=usermark+=+1"
|
||||
param = evhttp_find_header(hreq->query, "usermark");
|
||||
if (param)
|
||||
{
|
||||
ret = safe_atoi32(param, &val);
|
||||
if (ret < 0 || (ret == 0 && (val < FLAG_KIND_NA || val >= FLAG_KIND_MAX)) )
|
||||
ret = safe_atou32(param, &uval);
|
||||
if (ret < 0)
|
||||
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)
|
||||
return HTTP_INTERNAL;
|
||||
|
Loading…
Reference in New Issue
Block a user