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:
		| @@ -25,7 +25,8 @@ | ||||
|  | ||||
| #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); | ||||
|  | ||||
| #endif /* HAVE_AUDIOFILE */ | ||||
|   | ||||
| @@ -327,10 +327,10 @@ int addToDirectory(Directory * directory, char * shortname, char * name) { | ||||
| 		return addSubDirectoryToDirectory(directory,shortname,name); | ||||
| 	} | ||||
| 	else if(isMusic(name)) { | ||||
| 		LOG("adding %s\n",name); | ||||
| 		Song * song; | ||||
| 		song = addSongToList(directory->songs,shortname,name); | ||||
| 		if(!song) return -1; | ||||
| 		LOG("added %s\n",name); | ||||
| 		addSongToTables(song); | ||||
| 		return 0; | ||||
| 	} | ||||
| @@ -807,7 +807,7 @@ int directoryPrintSongInfo(FILE * fp, Song * song, void * data) { | ||||
| int sumSongTime(FILE * fp, Song * song, void * 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; | ||||
| } | ||||
|   | ||||
| @@ -282,6 +282,15 @@ int flac_getAudioFormatAndTime(char * file, AudioFormat * format, float * time) | ||||
| 	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) { | ||||
| 	if(flac_getAudioFormatAndTime(dc->file,af,&(cb->totalTime))<0) { | ||||
| 		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 getFlacTotalTime(char * file); | ||||
|  | ||||
| #endif | ||||
|   | ||||
| @@ -72,8 +72,6 @@ | ||||
| /* Define to empty if `const' does not conform to ANSI C. */ | ||||
| #undef const | ||||
|  | ||||
| /* Define to `__inline__' or `__inline' if that's what the C compiler | ||||
|    calls it, or to nothing if 'inline' is not supported under any name.  */ | ||||
| #ifndef __cplusplus | ||||
| /* Define as `__inline' if that's what the C compiler calls it, or to nothing | ||||
|    if it is not supported. */ | ||||
| #undef inline | ||||
| #endif | ||||
|   | ||||
| @@ -125,11 +125,9 @@ | ||||
| /* Define to empty if `const' does not conform to ANSI C. */ | ||||
| #undef const | ||||
|  | ||||
| /* Define to `__inline__' or `__inline' if that's what the C compiler | ||||
|    calls it, or to nothing if 'inline' is not supported under any name.  */ | ||||
| #ifndef __cplusplus | ||||
| /* Define as `__inline' if that's what the C compiler calls it, or to nothing | ||||
|    if it is not supported. */ | ||||
| #undef inline | ||||
| #endif | ||||
|  | ||||
| /* Define to `int' if <sys/types.h> does not define. */ | ||||
| #undef pid_t | ||||
|   | ||||
| @@ -375,7 +375,7 @@ int getMp3TotalTime(char * file) { | ||||
|  | ||||
| 	initMp3DecodeData(&data); | ||||
| 	if(decodeFirstFrame(&data)<0) ret = -1; | ||||
| 	else ret = data.totalTime; | ||||
| 	else ret = data.totalTime+0.5; | ||||
| 	mp3DecodeDataFinalize(&data); | ||||
|  | ||||
| 	return ret; | ||||
|   | ||||
| @@ -37,6 +37,25 @@ | ||||
| #define OGG_DECODE_USE_BIGENDIAN	0 | ||||
| #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) | ||||
| { | ||||
| 	OggVorbis_File vf; | ||||
|   | ||||
| @@ -25,4 +25,6 @@ | ||||
|  | ||||
| int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc); | ||||
|  | ||||
| int getOggTotalTime(char * file); | ||||
|  | ||||
| #endif | ||||
|   | ||||
							
								
								
									
										54
									
								
								src/song.c
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								src/song.c
									
									
									
									
									
								
							| @@ -23,6 +23,11 @@ | ||||
| #include "utils.h" | ||||
| #include "tag.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_FILE	"file: " | ||||
| @@ -38,32 +43,45 @@ | ||||
|  | ||||
| Song * newSong(char * utf8file) { | ||||
| 	Song * song = malloc(sizeof(Song)); | ||||
| 	song->time = -1; | ||||
|  | ||||
| 	song->utf8file = strdup(utf8file); | ||||
|  | ||||
| 	if(0); | ||||
| #ifdef HAVE_OGG | ||||
| 	if((song->mtime = isOgg(utf8file))) { | ||||
| 		song->tag = oggTagDup(utf8file); | ||||
| 		return song; | ||||
| 	else if((song->mtime = isOgg(utf8file))) { | ||||
| 		song->time = getOggTotalTime( | ||||
| 				rmp2amp(utf8ToFsCharset(utf8file))); | ||||
| 		if(song->time>=0) song->tag = oggTagDup(utf8file); | ||||
| 	} | ||||
| #endif | ||||
| #ifdef HAVE_FLAC | ||||
| 	if((song->mtime = isFlac(utf8file))) { | ||||
| 		song->tag = flacTagDup(utf8file); | ||||
| 		return song; | ||||
| 	else if((song->mtime = isFlac(utf8file))) { | ||||
| 		song->time = getFlacTotalTime( | ||||
| 				rmp2amp(utf8ToFsCharset(utf8file))); | ||||
| 		if(song->time>=0) song->tag = flacTagDup(utf8file); | ||||
| 	} | ||||
| #endif | ||||
| #ifdef HAVE_MAD | ||||
| 	if((song->mtime = isMp3(utf8file))) { | ||||
| 		song->tag = mp3TagDup(utf8file); | ||||
| 		return song; | ||||
| 	else if((song->mtime = isMp3(utf8file))) { | ||||
| 		song->time = getMp3TotalTime( | ||||
| 				rmp2amp(utf8ToFsCharset(utf8file))); | ||||
| 		if(song->time>=0) song->tag = mp3TagDup(utf8file); | ||||
| 	} | ||||
| #endif | ||||
| #ifdef HAVE_AUDIOFILE | ||||
| 	if((song->mtime = isWave(utf8file))) { | ||||
| 		song->tag = audiofileTagDup(utf8file); | ||||
| 		return song; | ||||
| 	else if((song->mtime = isWave(utf8file))) { | ||||
| 		song->time = getAudiofileTotalTime( | ||||
| 				rmp2amp(utf8ToFsCharset(utf8file))); | ||||
| 		if(song->time>=0) song->tag = audiofileTagDup(utf8file); | ||||
| 	} | ||||
| #endif | ||||
|  | ||||
| 	if(song->time<0) { | ||||
| 		freeSong(song); | ||||
| 		song = NULL; | ||||
| 	} | ||||
|  | ||||
| 	return song; | ||||
| } | ||||
|  | ||||
| @@ -78,14 +96,13 @@ SongList * newSongList() { | ||||
| } | ||||
|  | ||||
| Song * addSongToList(SongList * list, char * key, char * utf8file) { | ||||
| 	Song * song; | ||||
| 	Song * song = NULL; | ||||
| 	 | ||||
| 	if(isMusic(utf8file)) { | ||||
| 		song = newSong(utf8file); | ||||
| 	} | ||||
| 	else { | ||||
| 		return NULL; | ||||
| 	} | ||||
|  | ||||
| 	if(song==NULL) return NULL; | ||||
| 	 | ||||
| 	insertInList(list,key,(void *)song); | ||||
|  | ||||
| @@ -99,6 +116,8 @@ void freeSongList(SongList * list) { | ||||
| int printSongInfo(FILE * fp, Song * song) { | ||||
| 	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); | ||||
|  | ||||
| 	return 0; | ||||
| @@ -172,8 +191,7 @@ void readSongInfoIntoList(FILE * fp, SongList * list) { | ||||
| 			song->tag->title = strdup(&(buffer[strlen(SONG_TITLE)])); | ||||
| 		} | ||||
| 		else if(0==strncmp(SONG_TIME,buffer,strlen(SONG_TIME))) { | ||||
| 			if(!song->tag) song->tag = newMpdTag(); | ||||
| 			song->tag->time = atoi(&(buffer[strlen(SONG_TIME)])); | ||||
| 			song->time = atoi(&(buffer[strlen(SONG_TIME)])); | ||||
| 		} | ||||
| 		else if(0==strncmp(SONG_MTIME,buffer,strlen(SONG_MTIME))) { | ||||
| 			song->mtime = atoi(&(buffer[strlen(SONG_TITLE)])); | ||||
|   | ||||
| @@ -32,6 +32,7 @@ typedef struct _Song { | ||||
| 	char * utf8file; | ||||
| 	MpdTag * tag; | ||||
| 	time_t mtime; | ||||
| 	int time; | ||||
| } Song; | ||||
|  | ||||
| typedef List SongList; | ||||
|   | ||||
							
								
								
									
										33
									
								
								src/tag.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								src/tag.c
									
									
									
									
									
								
							| @@ -20,8 +20,6 @@ | ||||
| #include "path.h" | ||||
| #include "myfprintf.h" | ||||
| #include "sig_handlers.h" | ||||
| #include "mp3_decode.h" | ||||
| #include "audiofile_decode.h" | ||||
| #include "utils.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->track) myfprintf(fp,"Track: %s\n",tag->track); | ||||
| 	if(tag->title) myfprintf(fp,"Title: %s\n",tag->title); | ||||
| 	if(tag->time>=0) myfprintf(fp,"Time: %i\n",tag->time); | ||||
| } | ||||
|  | ||||
| #ifdef HAVE_ID3TAG | ||||
| @@ -138,13 +135,7 @@ MpdTag * id3Dup(char * utf8filename) { | ||||
| #ifdef HAVE_AUDIOFILE | ||||
| MpdTag * audiofileTagDup(char * utf8file) { | ||||
| 	MpdTag * ret = NULL; | ||||
| 	int time = getAudiofileTotalTime(rmp2amp(utf8ToFsCharset(utf8file))); | ||||
| 	 | ||||
| 	if (time>=0) { | ||||
| 		if(!ret) ret = newMpdTag(); | ||||
| 		ret->time = time; | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
| #endif | ||||
| @@ -152,17 +143,9 @@ MpdTag * audiofileTagDup(char * utf8file) { | ||||
| #ifdef HAVE_MAD | ||||
| MpdTag * mp3TagDup(char * utf8file) { | ||||
| 	MpdTag * ret = NULL; | ||||
| 	int time; | ||||
|  | ||||
| 	ret = id3Dup(utf8file); | ||||
|  | ||||
| 	time = getMp3TotalTime(rmp2amp(utf8ToFsCharset(utf8file))); | ||||
|  | ||||
| 	if(time>=0) { | ||||
| 		if(!ret) ret = newMpdTag(); | ||||
| 		ret->time = time; | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
| #endif | ||||
| @@ -188,7 +171,6 @@ MpdTag * oggTagDup(char * utf8file) { | ||||
| 	} | ||||
|  | ||||
| 	ret = newMpdTag(); | ||||
| 	ret->time = (int)(ov_time_total(&vf,-1)+0.5); | ||||
|  | ||||
| 	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) { | ||||
| 			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); | ||||
| 	} while(FLAC__metadata_simple_iterator_next(it)); | ||||
| @@ -333,14 +311,9 @@ MpdTag * flacTagDup(char * utf8file) { | ||||
| 	int foundVorbisComment = 0; | ||||
|  | ||||
| 	ret = flacMetadataDup(utf8file,&foundVorbisComment); | ||||
| 	if(!ret) return NULL; | ||||
| 	if(!foundVorbisComment) { | ||||
| 		MpdTag * temp = id3Dup(utf8file); | ||||
| 		if(temp) { | ||||
| 			temp->time = ret->time; | ||||
| 			freeMpdTag(ret); | ||||
| 			ret = temp; | ||||
| 		} | ||||
| 		if(ret) freeMpdTag(ret); | ||||
| 		ret = id3Dup(utf8file); | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
| @@ -353,7 +326,6 @@ MpdTag * newMpdTag() { | ||||
| 	ret->artist = NULL; | ||||
| 	ret->title = NULL; | ||||
| 	ret->track = NULL; | ||||
| 	ret->time = -1; | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| @@ -374,7 +346,6 @@ MpdTag * mpdTagDup(MpdTag * tag) { | ||||
| 		ret->album = strdup(tag->album); | ||||
| 		ret->title = strdup(tag->title); | ||||
| 		ret->track = strdup(tag->track); | ||||
| 		ret->time = tag->time; | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Warren Dukes
					Warren Dukes