move time back into MpdTag

git-svn-id: https://svn.musicpd.org/mpd/trunk@250 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-03-11 00:16:49 +00:00
parent 31d44ea775
commit 1157b5d332
6 changed files with 46 additions and 36 deletions

View File

@ -803,7 +803,7 @@ int directoryPrintSongInfo(FILE * fp, Song * song, void * data) {
int sumSongTime(FILE * fp, Song * song, void * data) { int sumSongTime(FILE * fp, Song * song, void * data) {
unsigned long * time = (unsigned long *)data; unsigned long * time = (unsigned long *)data;
if(song->time>=0) *time+=song->time; if(song->tag && song->tag->time>=0) *time+=song->tag->time;
return 0; return 0;
} }

View File

@ -108,9 +108,9 @@ int playerInit() {
sigaction(SIGTERM,&sa,NULL); sigaction(SIGTERM,&sa,NULL);
close(listenSocket); close(listenSocket);
finishPlaylist();
freeAllInterfaces(); freeAllInterfaces();
closeMp3Directory(); closeMp3Directory();
finishPlaylist();
closeTables(); closeTables();
finishPaths(); finishPaths();
finishPermissions(); finishPermissions();

View File

@ -48,7 +48,6 @@ Song * newNullSong() {
song->tag = NULL; song->tag = NULL;
song->utf8file = NULL; song->utf8file = NULL;
song->time = -1;
return song; return song;
} }
@ -61,34 +60,26 @@ Song * newSong(char * utf8file) {
if(0); if(0);
#ifdef HAVE_OGG #ifdef HAVE_OGG
else if(isOgg(utf8file,&(song->mtime))) { else if(isOgg(utf8file,&(song->mtime))) {
song->time = getOggTotalTime( song->tag = oggTagDup(utf8file);
rmp2amp(utf8ToFsCharset(utf8file)));
if(song->time>=0) song->tag = oggTagDup(utf8file);
} }
#endif #endif
#ifdef HAVE_FLAC #ifdef HAVE_FLAC
else if((isFlac(utf8file,&(song->mtime)))) { else if((isFlac(utf8file,&(song->mtime)))) {
song->time = getFlacTotalTime( song->tag = flacTagDup(utf8file);
rmp2amp(utf8ToFsCharset(utf8file)));
if(song->time>=0) song->tag = flacTagDup(utf8file);
} }
#endif #endif
#ifdef HAVE_MAD #ifdef HAVE_MAD
else if(isMp3(utf8file,&(song->mtime))) { else if(isMp3(utf8file,&(song->mtime))) {
song->time = getMp3TotalTime( song->tag = mp3TagDup(utf8file);
rmp2amp(utf8ToFsCharset(utf8file)));
if(song->time>=0) song->tag = mp3TagDup(utf8file);
} }
#endif #endif
#ifdef HAVE_AUDIOFILE #ifdef HAVE_AUDIOFILE
else if(isWave(utf8file,&(song->mtime))) { else if(isWave(utf8file,&(song->mtime))) {
song->time = getAudiofileTotalTime( song->tag = audiofileTagDup(utf8file);
rmp2amp(utf8ToFsCharset(utf8file)));
if(song->time>=0) song->tag = audiofileTagDup(utf8file);
} }
#endif #endif
if(song->time<0) { if(!song->tag || song->tag->time<0) {
freeSong(song); freeSong(song);
song = NULL; song = NULL;
} }
@ -130,8 +121,6 @@ void freeSongList(SongList * list) {
int printSongInfo(FILE * fp, Song * song) { int printSongInfo(FILE * fp, Song * song) {
myfprintf(fp,"%s%s\n",SONG_FILE,song->utf8file); myfprintf(fp,"%s%s\n",SONG_FILE,song->utf8file);
if(song->time>=0) myfprintf(fp,"%s%i\n",SONG_TIME,song->time);
if(song->tag) printMpdTag(fp,song->tag); if(song->tag) printMpdTag(fp,song->tag);
return 0; return 0;
@ -203,7 +192,8 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
song->tag->title = strdup(&(buffer[strlen(SONG_TITLE)])); song->tag->title = strdup(&(buffer[strlen(SONG_TITLE)]));
} }
else if(0==strncmp(SONG_TIME,buffer,strlen(SONG_TIME))) { else if(0==strncmp(SONG_TIME,buffer,strlen(SONG_TIME))) {
song->time = atoi(&(buffer[strlen(SONG_TIME)])); if(!song->tag) song->tag = newMpdTag();
song->tag->time = atoi(&(buffer[strlen(SONG_TIME)]));
} }
else if(0==strncmp(SONG_MTIME,buffer,strlen(SONG_MTIME))) { else if(0==strncmp(SONG_MTIME,buffer,strlen(SONG_MTIME))) {
song->mtime = atoi(&(buffer[strlen(SONG_TITLE)])); song->mtime = atoi(&(buffer[strlen(SONG_TITLE)]));
@ -227,40 +217,31 @@ int updateSongInfo(Song * song) {
removeASongFromTables(song); removeASongFromTables(song);
if(song->tag) freeMpdTag(song->tag); if(song->tag) freeMpdTag(song->tag);
song->time = -1;
song->tag = NULL; song->tag = NULL;
if(0); if(0);
#ifdef HAVE_OGG #ifdef HAVE_OGG
else if(isOgg(utf8file,&(song->mtime))) { else if(isOgg(utf8file,&(song->mtime))) {
song->time = getOggTotalTime( song->tag = oggTagDup(utf8file);
rmp2amp(utf8ToFsCharset(utf8file)));
if(song->time>=0) song->tag = oggTagDup(utf8file);
} }
#endif #endif
#ifdef HAVE_FLAC #ifdef HAVE_FLAC
else if((isFlac(utf8file,&(song->mtime)))) { else if((isFlac(utf8file,&(song->mtime)))) {
song->time = getFlacTotalTime( song->tag = flacTagDup(utf8file);
rmp2amp(utf8ToFsCharset(utf8file)));
if(song->time>=0) song->tag = flacTagDup(utf8file);
} }
#endif #endif
#ifdef HAVE_MAD #ifdef HAVE_MAD
else if(isMp3(utf8file,&(song->mtime))) { else if(isMp3(utf8file,&(song->mtime))) {
song->time = getMp3TotalTime( song->tag = mp3TagDup(utf8file);
rmp2amp(utf8ToFsCharset(utf8file)));
if(song->time>=0) song->tag = mp3TagDup(utf8file);
} }
#endif #endif
#ifdef HAVE_AUDIOFILE #ifdef HAVE_AUDIOFILE
else if(isWave(utf8file,&(song->mtime))) { else if(isWave(utf8file,&(song->mtime))) {
song->time = getAudiofileTotalTime( song->tag = audiofileTagDup(utf8file);
rmp2amp(utf8ToFsCharset(utf8file)));
if(song->time>=0) song->tag = audiofileTagDup(utf8file);
} }
#endif #endif
if(song->time<0) return -1; if(!song->tag || song->tag->time<0) return -1;
else addSongToTables(song); else addSongToTables(song);
return 0; return 0;

View File

@ -32,7 +32,6 @@ typedef struct _Song {
char * utf8file; char * utf8file;
MpdTag * tag; MpdTag * tag;
time_t mtime; time_t mtime;
int time;
} Song; } Song;
typedef List SongList; typedef List SongList;

View File

@ -20,6 +20,8 @@
#include "path.h" #include "path.h"
#include "myfprintf.h" #include "myfprintf.h"
#include "sig_handlers.h" #include "sig_handlers.h"
#include "mp3_decode.h"
#include "audiofile_decode.h"
#include "utils.h" #include "utils.h"
#include <sys/stat.h> #include <sys/stat.h>
@ -48,6 +50,7 @@ void printMpdTag(FILE * fp, MpdTag * tag) {
if(tag->album) myfprintf(fp,"Album: %s\n",tag->album); if(tag->album) myfprintf(fp,"Album: %s\n",tag->album);
if(tag->track) myfprintf(fp,"Track: %s\n",tag->track); if(tag->track) myfprintf(fp,"Track: %s\n",tag->track);
if(tag->title) myfprintf(fp,"Title: %s\n",tag->title); if(tag->title) myfprintf(fp,"Title: %s\n",tag->title);
if(tag->time>=0) myfprintf(fp,"Time: %i\n",tag->time);
} }
#ifdef HAVE_ID3TAG #ifdef HAVE_ID3TAG
@ -135,7 +138,13 @@ MpdTag * id3Dup(char * utf8filename) {
#ifdef HAVE_AUDIOFILE #ifdef HAVE_AUDIOFILE
MpdTag * audiofileTagDup(char * utf8file) { MpdTag * audiofileTagDup(char * utf8file) {
MpdTag * ret = NULL; MpdTag * ret = NULL;
int time = getAudiofileTotalTime(rmp2amp(utf8ToFsCharset(utf8file)));
if (time>=0) {
if(!ret) ret = newMpdTag();
ret->time = time;
}
return ret; return ret;
} }
#endif #endif
@ -143,9 +152,17 @@ MpdTag * audiofileTagDup(char * utf8file) {
#ifdef HAVE_MAD #ifdef HAVE_MAD
MpdTag * mp3TagDup(char * utf8file) { MpdTag * mp3TagDup(char * utf8file) {
MpdTag * ret = NULL; MpdTag * ret = NULL;
int time;
ret = id3Dup(utf8file); ret = id3Dup(utf8file);
time = getMp3TotalTime(rmp2amp(utf8ToFsCharset(utf8file)));
if(time>=0) {
if(!ret) ret = newMpdTag();
ret->time = time;
}
return ret; return ret;
} }
#endif #endif
@ -171,6 +188,7 @@ MpdTag * oggTagDup(char * utf8file) {
} }
ret = newMpdTag(); ret = newMpdTag();
ret->time = (int)(ov_time_total(&vf,-1)+0.5);
comments = ov_comment(&vf,-1)->user_comments; comments = ov_comment(&vf,-1)->user_comments;
@ -297,6 +315,10 @@ MpdTag * flacMetadataDup(char * utf8file, int * vorbisCommentFound) {
} }
else if(block->type == FLAC__METADATA_TYPE_STREAMINFO) { else if(block->type == FLAC__METADATA_TYPE_STREAMINFO) {
if(!ret) ret = newMpdTag(); if(!ret) ret = newMpdTag();
ret->time = ((float)block->data.stream_info.
total_samples) /
block->data.stream_info.sample_rate +
0.5;
} }
FLAC__metadata_object_delete(block); FLAC__metadata_object_delete(block);
} while(FLAC__metadata_simple_iterator_next(it)); } while(FLAC__metadata_simple_iterator_next(it));
@ -311,9 +333,14 @@ MpdTag * flacTagDup(char * utf8file) {
int foundVorbisComment = 0; int foundVorbisComment = 0;
ret = flacMetadataDup(utf8file,&foundVorbisComment); ret = flacMetadataDup(utf8file,&foundVorbisComment);
if(!ret) return NULL;
if(!foundVorbisComment) { if(!foundVorbisComment) {
if(ret) freeMpdTag(ret); MpdTag * temp = id3Dup(utf8file);
ret = id3Dup(utf8file); if(temp) {
temp->time = ret->time;
freeMpdTag(ret);
ret = temp;
}
} }
return ret; return ret;
@ -326,6 +353,7 @@ MpdTag * newMpdTag() {
ret->artist = NULL; ret->artist = NULL;
ret->title = NULL; ret->title = NULL;
ret->track = NULL; ret->track = NULL;
ret->time = -1;
return ret; return ret;
} }
@ -346,6 +374,7 @@ MpdTag * mpdTagDup(MpdTag * tag) {
ret->album = strdup(tag->album); ret->album = strdup(tag->album);
ret->title = strdup(tag->title); ret->title = strdup(tag->title);
ret->track = strdup(tag->track); ret->track = strdup(tag->track);
ret->time = tag->time;
} }
return ret; return ret;

View File

@ -26,6 +26,7 @@ typedef struct _MpdTag {
char * album; char * album;
char * track; char * track;
char * title; char * title;
int time;
} MpdTag; } MpdTag;
MpdTag * newMpdTag(); MpdTag * newMpdTag();