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:
Paul Kim 2004-11-20 19:22:40 +00:00
parent 7cda300daf
commit 5d813e8b13
3 changed files with 30 additions and 6 deletions

View File

@ -101,6 +101,7 @@ typedef struct tag_mp3packed {
int time_added;
int time_modified;
int time_played;
int db_timestamp;
int bpm; // DB Version 3
@ -647,6 +648,7 @@ datum *db_packrecord(MP3FILE *pmp3) {
ppacked->time_added=pmp3->time_added;
ppacked->time_modified=pmp3->time_modified;
ppacked->time_played=pmp3->time_played;
ppacked->db_timestamp=pmp3->db_timestamp;
ppacked->bpm=pmp3->bpm;
ppacked->compilation=pmp3->compilation;
ppacked->id=pmp3->id;
@ -755,6 +757,7 @@ int db_unpackrecord(datum *pdatum, MP3FILE *pmp3) {
pmp3->total_discs=ppacked->total_discs;
pmp3->time_added=ppacked->time_added;
pmp3->time_modified=ppacked->time_modified;
pmp3->db_timestamp=ppacked->db_timestamp;
pmp3->time_played=ppacked->time_played;
pmp3->bpm=ppacked->bpm;
pmp3->compilation=ppacked->compilation;
@ -851,7 +854,9 @@ int db_add(MP3FILE *pmp3) {
ppacked=(MP3PACKED *)pnew->dptr;
if(!ppacked->time_added)
ppacked->time_added=(int)time(NULL);
if(!ppacked->time_modified)
ppacked->time_modified=(int)time(NULL);
ppacked->db_timestamp = (int)time(NULL);
ppacked->time_played=0; /* do we want to keep track of this? */
db_writelock();
@ -1442,7 +1447,7 @@ int db_last_modified(int id) {
if(!pmp3) {
retval=0;
} else {
retval=pmp3->time_modified;
retval = pmp3->db_timestamp;
}
if(pmp3) {

View File

@ -68,7 +68,6 @@ typedef struct tag_scan_id3header {
#define MAYBEFREE(a) { if((a)) free((a)); };
/*
* Globals
*/
@ -281,6 +280,16 @@ static taghandler taghandlers[] = {
{ 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
*
@ -495,7 +504,7 @@ void scan_music_file(char *path, struct dirent *pde, struct stat *psb) {
mp3file.time_added=psb->st_mtime;
if(psb->st_ctime < mp3file.time_added)
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);
@ -1027,6 +1036,7 @@ int scan_get_aacfileinfo(char *file, MP3FILE *pmp3) {
off_t file_size;
int ms;
unsigned char buffer[2];
int time = 0;
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 */
atom_offset = aac_drilltoatom(infile, "moov:mvhd", &atom_length);
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*)&samples,1,sizeof(int),infile);
@ -1111,6 +1128,7 @@ int scan_get_aacfileinfo(char *file, MP3FILE *pmp3) {
if (atom_offset != -1) {
pmp3->bitrate = atom_length / ((pmp3->song_length / 1000) * 128);
}
}
fclose(infile);

View File

@ -54,6 +54,7 @@ typedef struct tag_mp3file {
int time_added;
int time_modified;
int time_played;
int db_timestamp;
int bpm; /* TBPM */