mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-14 16:25:03 -05:00
[db] inc playcount using filter
This commit is contained in:
parent
1a912d9808
commit
286525a85c
49
src/db.c
49
src/db.c
@ -2514,10 +2514,10 @@ db_files_get_count(uint32_t *nitems, uint32_t *nstreams, const char *filter)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
db_file_inc_playcount(int id)
|
db_file_inc_playcount_byfilter(const char *filter)
|
||||||
{
|
{
|
||||||
#define Q_TMPL "UPDATE files SET play_count = play_count + 1, time_played = %" PRIi64 ", seek = 0 WHERE id = %d;"
|
#define Q_TMPL "UPDATE files SET play_count = play_count + 1, time_played = %" PRIi64 ", seek = 0 WHERE %s;"
|
||||||
/*
|
/*
|
||||||
* Rating calculation is taken from from the beets plugin "mpdstats" (see https://beets.readthedocs.io/en/latest/plugins/mpdstats.html)
|
* Rating calculation is taken from from the beets plugin "mpdstats" (see https://beets.readthedocs.io/en/latest/plugins/mpdstats.html)
|
||||||
* and adapted to the forked-daapd rating rage (0 to 100).
|
* and adapted to the forked-daapd rating rage (0 to 100).
|
||||||
@ -2536,14 +2536,16 @@ db_file_inc_playcount(int id)
|
|||||||
"UPDATE files "\
|
"UPDATE files "\
|
||||||
" SET play_count = play_count + 1, time_played = %" PRIi64 ", seek = 0, "\
|
" SET play_count = play_count + 1, time_played = %" PRIi64 ", seek = 0, "\
|
||||||
" rating = CAST(((play_count + 1.0) / (play_count + skip_count + 2.0) * 100 * 0.75) + ((rating + ((100.0 - rating) / 2.0)) * 0.25) AS INT)" \
|
" rating = CAST(((play_count + 1.0) / (play_count + skip_count + 2.0) * 100 * 0.75) + ((rating + ((100.0 - rating) / 2.0)) * 0.25) AS INT)" \
|
||||||
" WHERE id = %d;"
|
" WHERE %s;"
|
||||||
char *query;
|
char *query;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
||||||
if (db_rating_updates)
|
if (db_rating_updates)
|
||||||
query = sqlite3_mprintf(Q_TMPL_WITH_RATING, (int64_t)time(NULL), id);
|
query = sqlite3_mprintf(Q_TMPL_WITH_RATING, (int64_t)time(NULL), filter);
|
||||||
else
|
else
|
||||||
query = sqlite3_mprintf(Q_TMPL, (int64_t)time(NULL), id);
|
query = sqlite3_mprintf(Q_TMPL, (int64_t)time(NULL), filter);
|
||||||
|
|
||||||
if (!query)
|
if (!query)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
||||||
@ -2558,6 +2560,41 @@ db_file_inc_playcount(int id)
|
|||||||
#undef Q_TMPL_WITH_RATING
|
#undef Q_TMPL_WITH_RATING
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
db_file_inc_playcount_byplid(int id, bool only_unplayed)
|
||||||
|
{
|
||||||
|
char *filter;
|
||||||
|
|
||||||
|
filter = sqlite3_mprintf("path IN (SELECT filepath FROM playlistitems WHERE playlistid = %d) %s",
|
||||||
|
id, only_unplayed ? "AND play_count = 0" : "");
|
||||||
|
|
||||||
|
db_file_inc_playcount_byfilter(filter);
|
||||||
|
sqlite3_free(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
db_file_inc_playcount_bysongalbumid(int64_t id, bool only_unplayed)
|
||||||
|
{
|
||||||
|
char *filter;
|
||||||
|
|
||||||
|
filter = sqlite3_mprintf("songalbumid = %" PRIi64 " %s",
|
||||||
|
id, only_unplayed ? "AND play_count = 0" : "");
|
||||||
|
|
||||||
|
db_file_inc_playcount_byfilter(filter);
|
||||||
|
sqlite3_free(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
db_file_inc_playcount(int id)
|
||||||
|
{
|
||||||
|
char *filter;
|
||||||
|
|
||||||
|
filter = sqlite3_mprintf("id = %d", id);
|
||||||
|
|
||||||
|
db_file_inc_playcount_byfilter(filter);
|
||||||
|
sqlite3_free(filter);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
db_file_inc_skipcount(int id)
|
db_file_inc_skipcount(int id)
|
||||||
{
|
{
|
||||||
|
6
src/db.h
6
src/db.h
@ -580,6 +580,12 @@ db_files_get_count(uint32_t *nitems, uint32_t *nstreams, const char *filter);
|
|||||||
void
|
void
|
||||||
db_file_inc_playcount(int id);
|
db_file_inc_playcount(int id);
|
||||||
|
|
||||||
|
void
|
||||||
|
db_file_inc_playcount_byplid(int id, bool only_unplayed);
|
||||||
|
|
||||||
|
void
|
||||||
|
db_file_inc_playcount_bysongalbumid(int64_t id, bool only_unplayed);
|
||||||
|
|
||||||
void
|
void
|
||||||
db_file_inc_skipcount(int id);
|
db_file_inc_skipcount(int id);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user