move time from tag info to song info.
also, if we can't get the time, then don't add the song to the db! git-svn-id: https://svn.musicpd.org/mpd/trunk@236 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
1459ee22fe
commit
ec234e9855
|
@ -25,7 +25,8 @@
|
||||||
|
|
||||||
#include "playerData.h"
|
#include "playerData.h"
|
||||||
|
|
||||||
int audiofile_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
|
int audiofile_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);;
|
||||||
|
|
||||||
int getAudiofileTotalTime(char * file);
|
int getAudiofileTotalTime(char * file);
|
||||||
|
|
||||||
#endif /* HAVE_AUDIOFILE */
|
#endif /* HAVE_AUDIOFILE */
|
||||||
|
|
|
@ -327,10 +327,10 @@ int addToDirectory(Directory * directory, char * shortname, char * name) {
|
||||||
return addSubDirectoryToDirectory(directory,shortname,name);
|
return addSubDirectoryToDirectory(directory,shortname,name);
|
||||||
}
|
}
|
||||||
else if(isMusic(name)) {
|
else if(isMusic(name)) {
|
||||||
LOG("adding %s\n",name);
|
|
||||||
Song * song;
|
Song * song;
|
||||||
song = addSongToList(directory->songs,shortname,name);
|
song = addSongToList(directory->songs,shortname,name);
|
||||||
if(!song) return -1;
|
if(!song) return -1;
|
||||||
|
LOG("added %s\n",name);
|
||||||
addSongToTables(song);
|
addSongToTables(song);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -807,7 +807,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->tag && song->tag->time>=0) *time+=song->tag->time;
|
if(song->time>=0) *time+=song->time;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,6 +282,15 @@ int flac_getAudioFormatAndTime(char * file, AudioFormat * format, float * time)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getFlacTotalTime(char * file) {
|
||||||
|
float totalTime;
|
||||||
|
AudioFormat af;
|
||||||
|
|
||||||
|
if(flac_getAudioFormatAndTime(file,&af,&totalTime)<0) return -1;
|
||||||
|
|
||||||
|
return (int)(totalTime+0.5);
|
||||||
|
}
|
||||||
|
|
||||||
int flac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
|
int flac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
|
||||||
if(flac_getAudioFormatAndTime(dc->file,af,&(cb->totalTime))<0) {
|
if(flac_getAudioFormatAndTime(dc->file,af,&(cb->totalTime))<0) {
|
||||||
ERROR("\"%s\" doesn't seem to be a flac\n",dc->file);
|
ERROR("\"%s\" doesn't seem to be a flac\n",dc->file);
|
||||||
|
|
|
@ -25,4 +25,6 @@
|
||||||
|
|
||||||
int flac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
|
int flac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
|
||||||
|
|
||||||
|
int getFlacTotalTime(char * file);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -72,8 +72,6 @@
|
||||||
/* Define to empty if `const' does not conform to ANSI C. */
|
/* Define to empty if `const' does not conform to ANSI C. */
|
||||||
#undef const
|
#undef const
|
||||||
|
|
||||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
|
||||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
if it is not supported. */
|
||||||
#ifndef __cplusplus
|
|
||||||
#undef inline
|
#undef inline
|
||||||
#endif
|
|
||||||
|
|
|
@ -125,11 +125,9 @@
|
||||||
/* Define to empty if `const' does not conform to ANSI C. */
|
/* Define to empty if `const' does not conform to ANSI C. */
|
||||||
#undef const
|
#undef const
|
||||||
|
|
||||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
|
||||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
if it is not supported. */
|
||||||
#ifndef __cplusplus
|
|
||||||
#undef inline
|
#undef inline
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define to `int' if <sys/types.h> does not define. */
|
/* Define to `int' if <sys/types.h> does not define. */
|
||||||
#undef pid_t
|
#undef pid_t
|
||||||
|
|
|
@ -375,7 +375,7 @@ int getMp3TotalTime(char * file) {
|
||||||
|
|
||||||
initMp3DecodeData(&data);
|
initMp3DecodeData(&data);
|
||||||
if(decodeFirstFrame(&data)<0) ret = -1;
|
if(decodeFirstFrame(&data)<0) ret = -1;
|
||||||
else ret = data.totalTime;
|
else ret = data.totalTime+0.5;
|
||||||
mp3DecodeDataFinalize(&data);
|
mp3DecodeDataFinalize(&data);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -37,6 +37,25 @@
|
||||||
#define OGG_DECODE_USE_BIGENDIAN 0
|
#define OGG_DECODE_USE_BIGENDIAN 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int getOggTotalTime(char * file) {
|
||||||
|
OggVorbis_File vf;
|
||||||
|
FILE * oggfp;
|
||||||
|
int totalTime;
|
||||||
|
|
||||||
|
if(!(oggfp = fopen(file,"r"))) return -1;
|
||||||
|
|
||||||
|
if(ov_open(oggfp, &vf, NULL, 0) < 0) {
|
||||||
|
fclose(oggfp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalTime = ov_time_total(&vf,-1)+0.5;
|
||||||
|
|
||||||
|
ov_clear(&vf);
|
||||||
|
|
||||||
|
return totalTime;
|
||||||
|
}
|
||||||
|
|
||||||
int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
|
int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
|
||||||
{
|
{
|
||||||
OggVorbis_File vf;
|
OggVorbis_File vf;
|
||||||
|
|
|
@ -25,4 +25,6 @@
|
||||||
|
|
||||||
int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
|
int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
|
||||||
|
|
||||||
|
int getOggTotalTime(char * file);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
54
src/song.c
54
src/song.c
|
@ -23,6 +23,11 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "mp3_decode.h"
|
||||||
|
#include "audiofile_decode.h"
|
||||||
|
#include "ogg_decode.h"
|
||||||
|
#include "flac_decode.h"
|
||||||
|
#include "path.h"
|
||||||
|
|
||||||
#define SONG_KEY "key: "
|
#define SONG_KEY "key: "
|
||||||
#define SONG_FILE "file: "
|
#define SONG_FILE "file: "
|
||||||
|
@ -38,32 +43,45 @@
|
||||||
|
|
||||||
Song * newSong(char * utf8file) {
|
Song * newSong(char * utf8file) {
|
||||||
Song * song = malloc(sizeof(Song));
|
Song * song = malloc(sizeof(Song));
|
||||||
|
song->time = -1;
|
||||||
|
|
||||||
song->utf8file = strdup(utf8file);
|
song->utf8file = strdup(utf8file);
|
||||||
|
|
||||||
|
if(0);
|
||||||
#ifdef HAVE_OGG
|
#ifdef HAVE_OGG
|
||||||
if((song->mtime = isOgg(utf8file))) {
|
else if((song->mtime = isOgg(utf8file))) {
|
||||||
song->tag = oggTagDup(utf8file);
|
song->time = getOggTotalTime(
|
||||||
return song;
|
rmp2amp(utf8ToFsCharset(utf8file)));
|
||||||
|
if(song->time>=0) song->tag = oggTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_FLAC
|
#ifdef HAVE_FLAC
|
||||||
if((song->mtime = isFlac(utf8file))) {
|
else if((song->mtime = isFlac(utf8file))) {
|
||||||
song->tag = flacTagDup(utf8file);
|
song->time = getFlacTotalTime(
|
||||||
return song;
|
rmp2amp(utf8ToFsCharset(utf8file)));
|
||||||
|
if(song->time>=0) song->tag = flacTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_MAD
|
#ifdef HAVE_MAD
|
||||||
if((song->mtime = isMp3(utf8file))) {
|
else if((song->mtime = isMp3(utf8file))) {
|
||||||
song->tag = mp3TagDup(utf8file);
|
song->time = getMp3TotalTime(
|
||||||
return song;
|
rmp2amp(utf8ToFsCharset(utf8file)));
|
||||||
|
if(song->time>=0) song->tag = mp3TagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_AUDIOFILE
|
#ifdef HAVE_AUDIOFILE
|
||||||
if((song->mtime = isWave(utf8file))) {
|
else if((song->mtime = isWave(utf8file))) {
|
||||||
song->tag = audiofileTagDup(utf8file);
|
song->time = getAudiofileTotalTime(
|
||||||
return song;
|
rmp2amp(utf8ToFsCharset(utf8file)));
|
||||||
|
if(song->time>=0) song->tag = audiofileTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if(song->time<0) {
|
||||||
|
freeSong(song);
|
||||||
|
song = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,14 +96,13 @@ SongList * newSongList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Song * addSongToList(SongList * list, char * key, char * utf8file) {
|
Song * addSongToList(SongList * list, char * key, char * utf8file) {
|
||||||
Song * song;
|
Song * song = NULL;
|
||||||
|
|
||||||
if(isMusic(utf8file)) {
|
if(isMusic(utf8file)) {
|
||||||
song = newSong(utf8file);
|
song = newSong(utf8file);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return NULL;
|
if(song==NULL) return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
insertInList(list,key,(void *)song);
|
insertInList(list,key,(void *)song);
|
||||||
|
|
||||||
|
@ -99,6 +116,8 @@ 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;
|
||||||
|
@ -172,8 +191,7 @@ 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))) {
|
||||||
if(!song->tag) song->tag = newMpdTag();
|
song->time = atoi(&(buffer[strlen(SONG_TIME)]));
|
||||||
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)]));
|
||||||
|
|
|
@ -32,6 +32,7 @@ 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;
|
||||||
|
|
33
src/tag.c
33
src/tag.c
|
@ -20,8 +20,6 @@
|
||||||
#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>
|
||||||
|
@ -50,7 +48,6 @@ 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
|
||||||
|
@ -138,13 +135,7 @@ 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
|
||||||
|
@ -152,17 +143,9 @@ 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
|
||||||
|
@ -188,7 +171,6 @@ 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;
|
||||||
|
|
||||||
|
@ -315,10 +297,6 @@ 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));
|
||||||
|
@ -333,14 +311,9 @@ 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) {
|
||||||
MpdTag * temp = id3Dup(utf8file);
|
if(ret) freeMpdTag(ret);
|
||||||
if(temp) {
|
ret = id3Dup(utf8file);
|
||||||
temp->time = ret->time;
|
|
||||||
freeMpdTag(ret);
|
|
||||||
ret = temp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -353,7 +326,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,7 +346,6 @@ 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;
|
||||||
|
|
Loading…
Reference in New Issue