diff --git a/src/db-generic.c b/src/db-generic.c index a246aabc..1aad2ebb 100644 --- a/src/db-generic.c +++ b/src/db-generic.c @@ -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 * diff --git a/src/db-generic.h b/src/db-generic.h index 334cfdec..35af6e85 100644 --- a/src/db-generic.h +++ b/src/db-generic.h @@ -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); diff --git a/src/db-sql.c b/src/db-sql.c index 2a684ffc..18552433 100644 --- a/src/db-sql.c +++ b/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); +} + + diff --git a/src/db-sql.h b/src/db-sql.h index 93f50dee..27a42369 100644 --- a/src/db-sql.h +++ b/src/db-sql.h @@ -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, ...); diff --git a/src/dispatch.c b/src/dispatch.c index 90b4ba81..7b5c6372 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -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);