mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 07:35:57 -05:00
[db,scan,jsonapi] bug fix to handle date_released before 1970, storing -ve values in db
This commit is contained in:
parent
7c0474b743
commit
7d26c2c954
2
src/db.c
2
src/db.c
@ -187,7 +187,7 @@ static const struct col_type_map mfi_cols_map[] =
|
||||
{ "song_length", mfi_offsetof(song_length), DB_TYPE_INT },
|
||||
{ "file_size", mfi_offsetof(file_size), DB_TYPE_INT64 },
|
||||
{ "year", mfi_offsetof(year), DB_TYPE_INT },
|
||||
{ "date_released", mfi_offsetof(date_released), DB_TYPE_INT },
|
||||
{ "date_released", mfi_offsetof(date_released), DB_TYPE_INT64 },
|
||||
{ "track", mfi_offsetof(track), DB_TYPE_INT },
|
||||
{ "total_tracks", mfi_offsetof(total_tracks), DB_TYPE_INT },
|
||||
{ "disc", mfi_offsetof(disc), DB_TYPE_INT },
|
||||
|
2
src/db.h
2
src/db.h
@ -190,7 +190,7 @@ struct media_file_info {
|
||||
uint32_t song_length;
|
||||
int64_t file_size;
|
||||
uint32_t year; /* TDRC */
|
||||
uint32_t date_released;
|
||||
int64_t date_released; // bumped to (signed) int64 since all 32bits are unsigned
|
||||
|
||||
uint32_t track; /* TRCK */
|
||||
uint32_t total_tracks;
|
||||
|
@ -147,7 +147,7 @@ safe_json_add_time_from_string(json_object *obj, const char *key, const char *va
|
||||
static inline void
|
||||
safe_json_add_date_from_string(json_object *obj, const char *key, const char *value)
|
||||
{
|
||||
uint32_t tmp;
|
||||
int64_t tmp;
|
||||
time_t timestamp;
|
||||
struct tm tm;
|
||||
char result[32];
|
||||
@ -155,9 +155,9 @@ safe_json_add_date_from_string(json_object *obj, const char *key, const char *va
|
||||
if (!value)
|
||||
return;
|
||||
|
||||
if (safe_atou32(value, &tmp) != 0)
|
||||
if (safe_atoi64(value, &tmp) != 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_WEB, "Error converting timestamp to uint32_t: %s\n", value);
|
||||
DPRINTF(E_LOG, L_WEB, "Error converting timestamp to int64_t: %s\n", value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,8 @@ parse_date(struct media_file_info *mfi, char *date_string)
|
||||
{
|
||||
char year_string[32];
|
||||
uint32_t *year = (uint32_t *) ((char *) mfi + mfi_offsetof(year));
|
||||
uint32_t *date_released = (uint32_t *) ((char *) mfi + mfi_offsetof(date_released));
|
||||
// signed in db.h to handle dates before 1970
|
||||
int64_t *date_released = (int64_t *) ((char *) mfi + mfi_offsetof(date_released));
|
||||
struct tm tm = { 0 };
|
||||
int ret = 0;
|
||||
|
||||
@ -111,7 +112,7 @@ parse_date(struct media_file_info *mfi, char *date_string)
|
||||
|| strptime(date_string, "%F", &tm)
|
||||
)
|
||||
{
|
||||
*date_released = (uint32_t)mktime(&tm);
|
||||
*date_released = mktime(&tm);
|
||||
ret++;
|
||||
}
|
||||
|
||||
@ -120,7 +121,7 @@ parse_date(struct media_file_info *mfi, char *date_string)
|
||||
snprintf(year_string, sizeof(year_string), "%" PRIu32 "-01-01T12:00:00", *year);
|
||||
if (strptime(year_string, "%FT%T", &tm))
|
||||
{
|
||||
*date_released = (uint32_t)mktime(&tm);
|
||||
*date_released = mktime(&tm);
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user