mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-24 06:05:56 -05:00
Implement playcount updating
This commit is contained in:
parent
048bef92ed
commit
6efb792704
@ -52,6 +52,7 @@ typedef struct tag_db_functions {
|
||||
int(*dbs_delete_playlist)(char **, int);
|
||||
int(*dbs_delete_playlist_item)(char **, int, int);
|
||||
int(*dbs_edit_playlist)(char **, int, char*, char*);
|
||||
int(*dbs_playcount_increment)(char **, int);
|
||||
int(*dbs_enum_start)(char **, DBQUERYINFO *);
|
||||
int(*dbs_enum_size)(char **, DBQUERYINFO *, int *, int *);
|
||||
int(*dbs_enum_fetch)(char **, DBQUERYINFO *, int *, unsigned char **);
|
||||
@ -82,6 +83,7 @@ DB_FUNCTIONS db_functions[] = {
|
||||
db_sql_delete_playlist,
|
||||
db_sql_delete_playlist_item,
|
||||
db_sql_edit_playlist,
|
||||
db_sql_playcount_increment,
|
||||
db_sql_enum_start,
|
||||
db_sql_enum_size,
|
||||
db_sql_enum_fetch,
|
||||
@ -110,6 +112,7 @@ DB_FUNCTIONS db_functions[] = {
|
||||
db_sql_delete_playlist,
|
||||
db_sql_delete_playlist_item,
|
||||
db_sql_edit_playlist,
|
||||
db_sql_playcount_increment,
|
||||
db_sql_enum_start,
|
||||
db_sql_enum_size,
|
||||
db_sql_enum_fetch,
|
||||
@ -635,6 +638,24 @@ int db_edit_playlist(char **pe, int id, char *name, char *clause) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* increment the playcount info for a particular song
|
||||
* (play_count and time_played).
|
||||
*
|
||||
* @param pe error string
|
||||
* @param id id of song to incrmrent
|
||||
* @returns DB_E_SUCCESS on success, error code otherwise
|
||||
*/
|
||||
int db_playcount_increment(char **pe, int id) {
|
||||
int retval;
|
||||
|
||||
db_writelock();
|
||||
retval = db_current->dbs_playcount_increment(pe, id);
|
||||
db_unlock();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* start a db enumeration, based info in the DBQUERYINFO struct
|
||||
*
|
||||
|
@ -190,6 +190,7 @@ extern int db_dmap_add_container(unsigned char *where, char *tag, int size);
|
||||
* should these be removed? Refactored?
|
||||
*/
|
||||
|
||||
extern int db_playcount_increment(char **pe, int id);
|
||||
extern int db_get_song_count(char **pe, int *count);
|
||||
extern int db_get_playlist_count(char **pe, int *count);
|
||||
extern void db_dispose_item(MP3FILE *pmp3);
|
||||
|
15
src/db-sql.c
15
src/db-sql.c
@ -1745,3 +1745,18 @@ int db_sql_get_count(char **pe, int *count, CountType_t type) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* increment the play_count and time_played
|
||||
*
|
||||
* @param pe error string
|
||||
* @param id id of the song to increment
|
||||
* @returns DB_E_SUCCESS on success, error code otherwise
|
||||
*/
|
||||
int db_sql_playcount_increment(char **pe, int id) {
|
||||
time_t now = time(NULL);
|
||||
|
||||
return db_sql_exec_fn(pe,E_INF,"update songs set play_count=play_count + 1"
|
||||
", time_played=%d where id=%d",now,id);
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,6 +54,7 @@ extern int db_sql_add_playlist_item(char **pe, int playlistid, int songid);
|
||||
extern int db_sql_edit_playlist(char **pe, int id, char *name, char *clause);
|
||||
extern int db_sql_delete_playlist(char **pe, int playlistid);
|
||||
extern int db_sql_delete_playlist_item(char **pe, int playlistid, int songid);
|
||||
extern int db_sql_playcount_increment(char **pe, int id);
|
||||
|
||||
extern int db_sql_fetch_row(char **pe, SQL_ROW *row, char *fmt, ...);
|
||||
extern int db_sql_fetch_int(char **pe, int *result, char *fmt, ...);
|
||||
|
@ -710,6 +710,8 @@ void dispatch_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
} else {
|
||||
DPRINTF(E_INF,L_WS,
|
||||
"Finished streaming converted file to remote\n");
|
||||
db_playcount_increment(NULL,pmp3->id);
|
||||
|
||||
}
|
||||
server_side_convert_close(file_ptr);
|
||||
config_set_status(pwsc,pqi->session_id,NULL);
|
||||
@ -805,6 +807,8 @@ void dispatch_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
} else {
|
||||
DPRINTF(E_INF,L_WS,"Finished streaming file to remote: %d bytes\n",
|
||||
bytes_copied);
|
||||
/* update play counts */
|
||||
db_playcount_increment(NULL,pmp3->id);
|
||||
}
|
||||
|
||||
config_set_status(pwsc,pqi->session_id,NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user