mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-15 16:48:22 -04:00
db-gdbm.c:
- Added support for db_timestamp field. Field is the modification time of the db record and is checked against the file modification time in file system scans. mp3-scanner.h: - Added db_timestamp field. This is now distinct from the file's modification time which may, in some cases, be embedded in the file. mp3-scanner.c: - Added mac_to_unix_time to convert mac timestamps to unix ones. - Mp3 files get their modification time from the files mod time. - AAC files get their modification time from the embedded mod time. - AAC files get their added time from the embedded creation time.
This commit is contained in:
parent
7cda300daf
commit
5d813e8b13
@ -101,6 +101,7 @@ typedef struct tag_mp3packed {
|
|||||||
int time_added;
|
int time_added;
|
||||||
int time_modified;
|
int time_modified;
|
||||||
int time_played;
|
int time_played;
|
||||||
|
int db_timestamp;
|
||||||
|
|
||||||
int bpm; // DB Version 3
|
int bpm; // DB Version 3
|
||||||
|
|
||||||
@ -647,6 +648,7 @@ datum *db_packrecord(MP3FILE *pmp3) {
|
|||||||
ppacked->time_added=pmp3->time_added;
|
ppacked->time_added=pmp3->time_added;
|
||||||
ppacked->time_modified=pmp3->time_modified;
|
ppacked->time_modified=pmp3->time_modified;
|
||||||
ppacked->time_played=pmp3->time_played;
|
ppacked->time_played=pmp3->time_played;
|
||||||
|
ppacked->db_timestamp=pmp3->db_timestamp;
|
||||||
ppacked->bpm=pmp3->bpm;
|
ppacked->bpm=pmp3->bpm;
|
||||||
ppacked->compilation=pmp3->compilation;
|
ppacked->compilation=pmp3->compilation;
|
||||||
ppacked->id=pmp3->id;
|
ppacked->id=pmp3->id;
|
||||||
@ -755,6 +757,7 @@ int db_unpackrecord(datum *pdatum, MP3FILE *pmp3) {
|
|||||||
pmp3->total_discs=ppacked->total_discs;
|
pmp3->total_discs=ppacked->total_discs;
|
||||||
pmp3->time_added=ppacked->time_added;
|
pmp3->time_added=ppacked->time_added;
|
||||||
pmp3->time_modified=ppacked->time_modified;
|
pmp3->time_modified=ppacked->time_modified;
|
||||||
|
pmp3->db_timestamp=ppacked->db_timestamp;
|
||||||
pmp3->time_played=ppacked->time_played;
|
pmp3->time_played=ppacked->time_played;
|
||||||
pmp3->bpm=ppacked->bpm;
|
pmp3->bpm=ppacked->bpm;
|
||||||
pmp3->compilation=ppacked->compilation;
|
pmp3->compilation=ppacked->compilation;
|
||||||
@ -851,7 +854,9 @@ int db_add(MP3FILE *pmp3) {
|
|||||||
ppacked=(MP3PACKED *)pnew->dptr;
|
ppacked=(MP3PACKED *)pnew->dptr;
|
||||||
if(!ppacked->time_added)
|
if(!ppacked->time_added)
|
||||||
ppacked->time_added=(int)time(NULL);
|
ppacked->time_added=(int)time(NULL);
|
||||||
|
if(!ppacked->time_modified)
|
||||||
ppacked->time_modified=(int)time(NULL);
|
ppacked->time_modified=(int)time(NULL);
|
||||||
|
ppacked->db_timestamp = (int)time(NULL);
|
||||||
ppacked->time_played=0; /* do we want to keep track of this? */
|
ppacked->time_played=0; /* do we want to keep track of this? */
|
||||||
|
|
||||||
db_writelock();
|
db_writelock();
|
||||||
@ -1442,7 +1447,7 @@ int db_last_modified(int id) {
|
|||||||
if(!pmp3) {
|
if(!pmp3) {
|
||||||
retval=0;
|
retval=0;
|
||||||
} else {
|
} else {
|
||||||
retval=pmp3->time_modified;
|
retval = pmp3->db_timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pmp3) {
|
if(pmp3) {
|
||||||
|
@ -68,7 +68,6 @@ typedef struct tag_scan_id3header {
|
|||||||
|
|
||||||
#define MAYBEFREE(a) { if((a)) free((a)); };
|
#define MAYBEFREE(a) { if((a)) free((a)); };
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Globals
|
* Globals
|
||||||
*/
|
*/
|
||||||
@ -281,6 +280,16 @@ static taghandler taghandlers[] = {
|
|||||||
{ NULL, 0 }
|
{ NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
time_t mac_to_unix_time(int t) {
|
||||||
|
struct timeval tv;
|
||||||
|
struct timezone tz;
|
||||||
|
|
||||||
|
gettimeofday(&tv, &tz);
|
||||||
|
|
||||||
|
return (t - (365L * 66L * 24L * 60L * 60L + 17L * 60L * 60L * 24L) +
|
||||||
|
(tz.tz_minuteswest * 60));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* scan_init
|
* scan_init
|
||||||
*
|
*
|
||||||
@ -495,7 +504,7 @@ void scan_music_file(char *path, struct dirent *pde, struct stat *psb) {
|
|||||||
mp3file.time_added=psb->st_mtime;
|
mp3file.time_added=psb->st_mtime;
|
||||||
if(psb->st_ctime < mp3file.time_added)
|
if(psb->st_ctime < mp3file.time_added)
|
||||||
mp3file.time_added=psb->st_ctime;
|
mp3file.time_added=psb->st_ctime;
|
||||||
mp3file.time_modified=time(NULL);
|
mp3file.time_modified=psb->st_mtime;
|
||||||
|
|
||||||
DPRINTF(E_DBG,L_SCAN," Date Added: %d\n",mp3file.time_added);
|
DPRINTF(E_DBG,L_SCAN," Date Added: %d\n",mp3file.time_added);
|
||||||
|
|
||||||
@ -1027,6 +1036,7 @@ int scan_get_aacfileinfo(char *file, MP3FILE *pmp3) {
|
|||||||
off_t file_size;
|
off_t file_size;
|
||||||
int ms;
|
int ms;
|
||||||
unsigned char buffer[2];
|
unsigned char buffer[2];
|
||||||
|
int time = 0;
|
||||||
|
|
||||||
DPRINTF(E_DBG,L_SCAN,"Getting AAC file info\n");
|
DPRINTF(E_DBG,L_SCAN,"Getting AAC file info\n");
|
||||||
|
|
||||||
@ -1044,7 +1054,14 @@ int scan_get_aacfileinfo(char *file, MP3FILE *pmp3) {
|
|||||||
/* now, hunt for the mvhd atom */
|
/* now, hunt for the mvhd atom */
|
||||||
atom_offset = aac_drilltoatom(infile, "moov:mvhd", &atom_length);
|
atom_offset = aac_drilltoatom(infile, "moov:mvhd", &atom_length);
|
||||||
if(atom_offset != -1) {
|
if(atom_offset != -1) {
|
||||||
fseek(infile,12,SEEK_CUR);
|
fseek(infile, 4, SEEK_CUR);
|
||||||
|
fread((void *)&time, sizeof(int), 1, infile);
|
||||||
|
time = ntohl(time);
|
||||||
|
pmp3->time_added = mac_to_unix_time(time);
|
||||||
|
|
||||||
|
fread((void *)&time, sizeof(int), 1, infile);
|
||||||
|
time = ntohl(time);
|
||||||
|
pmp3->time_modified = mac_to_unix_time(time);
|
||||||
fread((void*)&sample_size,1,sizeof(int),infile);
|
fread((void*)&sample_size,1,sizeof(int),infile);
|
||||||
fread((void*)&samples,1,sizeof(int),infile);
|
fread((void*)&samples,1,sizeof(int),infile);
|
||||||
|
|
||||||
@ -1111,6 +1128,7 @@ int scan_get_aacfileinfo(char *file, MP3FILE *pmp3) {
|
|||||||
if (atom_offset != -1) {
|
if (atom_offset != -1) {
|
||||||
pmp3->bitrate = atom_length / ((pmp3->song_length / 1000) * 128);
|
pmp3->bitrate = atom_length / ((pmp3->song_length / 1000) * 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
|
@ -54,6 +54,7 @@ typedef struct tag_mp3file {
|
|||||||
int time_added;
|
int time_added;
|
||||||
int time_modified;
|
int time_modified;
|
||||||
int time_played;
|
int time_played;
|
||||||
|
int db_timestamp;
|
||||||
|
|
||||||
int bpm; /* TBPM */
|
int bpm; /* TBPM */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user