lets cleanup some file type detection and not call stat() so much
git-svn-id: https://svn.musicpd.org/mpd/trunk@575 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
995a5deb28
commit
795a1e930b
30
src/ls.c
30
src/ls.c
@ -155,58 +155,28 @@ int hasWaveSuffix(char * utf8file) {
|
|||||||
return hasSuffix(utf8file,"wav");
|
return hasSuffix(utf8file,"wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
int isWave(char * utf8file, time_t * mtime) {
|
|
||||||
if(isFile(utf8file,mtime)) return hasWaveSuffix(utf8file);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int hasFlacSuffix(char * utf8file) {
|
int hasFlacSuffix(char * utf8file) {
|
||||||
return hasSuffix(utf8file,"flac");
|
return hasSuffix(utf8file,"flac");
|
||||||
}
|
}
|
||||||
|
|
||||||
int isFlac(char * utf8file, time_t * mtime) {
|
|
||||||
if(isFile(utf8file,mtime)) return hasFlacSuffix(utf8file);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int hasOggSuffix(char * utf8file) {
|
int hasOggSuffix(char * utf8file) {
|
||||||
return hasSuffix(utf8file,"ogg");
|
return hasSuffix(utf8file,"ogg");
|
||||||
}
|
}
|
||||||
|
|
||||||
int isOgg(char * utf8file, time_t * mtime) {
|
|
||||||
if(isFile(utf8file,mtime)) return hasOggSuffix(utf8file);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int hasAacSuffix(char * utf8file) {
|
int hasAacSuffix(char * utf8file) {
|
||||||
return hasSuffix(utf8file,"aac");
|
return hasSuffix(utf8file,"aac");
|
||||||
}
|
}
|
||||||
|
|
||||||
int isAac(char * utf8file, time_t * mtime) {
|
|
||||||
if(isFile(utf8file,mtime)) return hasAacSuffix(utf8file);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int hasMp4Suffix(char * utf8file) {
|
int hasMp4Suffix(char * utf8file) {
|
||||||
if(hasSuffix(utf8file,"mp4")) return 1;
|
if(hasSuffix(utf8file,"mp4")) return 1;
|
||||||
if(hasSuffix(utf8file,"m4a")) return 1;
|
if(hasSuffix(utf8file,"m4a")) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int isMp4(char * utf8file, time_t * mtime) {
|
|
||||||
if(isFile(utf8file,mtime)) return hasMp4Suffix(utf8file);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int hasMp3Suffix(char * utf8file) {
|
int hasMp3Suffix(char * utf8file) {
|
||||||
return hasSuffix(utf8file,"mp3");
|
return hasSuffix(utf8file,"mp3");
|
||||||
}
|
}
|
||||||
|
|
||||||
int isMp3(char * utf8file, time_t * mtime) {
|
|
||||||
if(isFile(utf8file,mtime)) return hasMp3Suffix(utf8file);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int isDir(char * utf8name, time_t * mtime) {
|
int isDir(char * utf8name, time_t * mtime) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
|
28
src/ls.h
28
src/ls.h
@ -26,24 +26,26 @@
|
|||||||
|
|
||||||
int lsPlaylists(FILE * fp, char * utf8path);
|
int lsPlaylists(FILE * fp, char * utf8path);
|
||||||
|
|
||||||
int isMp3(char * utf8file, time_t * mtime);
|
int isFile(char * utf8file, time_t * mtime);
|
||||||
|
|
||||||
int isAac(char * utf8file, time_t * mtime);
|
|
||||||
|
|
||||||
int isMp4(char * utf8file, time_t * mtime);
|
|
||||||
|
|
||||||
int isOgg(char * utf8file, time_t * mtime);
|
|
||||||
|
|
||||||
int isFlac(char * utf8file, time_t * mtime);
|
|
||||||
|
|
||||||
int isWave(char * utf8file, time_t * mtime);
|
|
||||||
|
|
||||||
int isMusic(char * utf8file, time_t * mtime);
|
|
||||||
|
|
||||||
int isDir(char * utf8name, time_t * mtime);
|
int isDir(char * utf8name, time_t * mtime);
|
||||||
|
|
||||||
int isPlaylist(char * utf8file);
|
int isPlaylist(char * utf8file);
|
||||||
|
|
||||||
|
int isMusic(char * utf8file, time_t * mtime);
|
||||||
|
|
||||||
|
int hasWaveSuffix(char * utf8file);
|
||||||
|
|
||||||
|
int hasMp3Suffix(char * utf8file);
|
||||||
|
|
||||||
|
int hasAacSuffix(char * utf8file);
|
||||||
|
|
||||||
|
int hasMp4Suffix(char * utf8file);
|
||||||
|
|
||||||
|
int hasOggSuffix(char * utf8file);
|
||||||
|
|
||||||
|
int hasFlacSuffix(char * utf8file);
|
||||||
|
|
||||||
char * dupAndStripPlaylistSuffix(char * file);
|
char * dupAndStripPlaylistSuffix(char * file);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
14
src/player.c
14
src/player.c
@ -150,22 +150,22 @@ int playerInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int playerGetDecodeType(char * utf8file) {
|
int playerGetDecodeType(char * utf8file) {
|
||||||
if(0);
|
if(!isFile(utf8file,NULL));
|
||||||
#ifdef HAVE_MAD
|
#ifdef HAVE_MAD
|
||||||
if(isMp3(utf8file,NULL)) return DECODE_TYPE_MP3;
|
else if(hasMp3Suffix(utf8file)) return DECODE_TYPE_MP3;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_OGG
|
#ifdef HAVE_OGG
|
||||||
if(isOgg(utf8file,NULL)) return DECODE_TYPE_OGG;
|
else if(hasOggSuffix(utf8file)) return DECODE_TYPE_OGG;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_FLAC
|
#ifdef HAVE_FLAC
|
||||||
if(isFlac(utf8file,NULL)) return DECODE_TYPE_FLAC;
|
else if(hasFlacSuffix(utf8file)) return DECODE_TYPE_FLAC;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_AUDIOFILE
|
#ifdef HAVE_AUDIOFILE
|
||||||
if(isWave(utf8file,NULL)) return DECODE_TYPE_AUDIOFILE;
|
else if(hasWaveSuffix(utf8file)) return DECODE_TYPE_AUDIOFILE;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_FAAD
|
#ifdef HAVE_FAAD
|
||||||
if(isAac(utf8file,NULL)) return DECODE_TYPE_AAC;
|
else if(hasAacSuffix(utf8file)) return DECODE_TYPE_AAC;
|
||||||
if(isMp4(utf8file,NULL)) return DECODE_TYPE_MP4;
|
else if(hasMp4Suffix(utf8file)) return DECODE_TYPE_MP4;
|
||||||
#endif
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
28
src/song.c
28
src/song.c
@ -57,32 +57,32 @@ Song * newSong(char * utf8file) {
|
|||||||
|
|
||||||
song->utf8file = strdup(utf8file);
|
song->utf8file = strdup(utf8file);
|
||||||
|
|
||||||
if(0);
|
if(!isFile(utf8file,&(song->mtime)));
|
||||||
#ifdef HAVE_OGG
|
#ifdef HAVE_OGG
|
||||||
else if(isOgg(utf8file,&(song->mtime))) {
|
else if(hasOggSuffix(utf8file)) {
|
||||||
song->tag = oggTagDup(utf8file);
|
song->tag = oggTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_FLAC
|
#ifdef HAVE_FLAC
|
||||||
else if((isFlac(utf8file,&(song->mtime)))) {
|
else if((hasFlacSuffix(utf8file))) {
|
||||||
song->tag = flacTagDup(utf8file);
|
song->tag = flacTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_MAD
|
#ifdef HAVE_MAD
|
||||||
else if(isMp3(utf8file,&(song->mtime))) {
|
else if(hasMp3Suffix(utf8file)) {
|
||||||
song->tag = mp3TagDup(utf8file);
|
song->tag = mp3TagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_AUDIOFILE
|
#ifdef HAVE_AUDIOFILE
|
||||||
else if(isWave(utf8file,&(song->mtime))) {
|
else if(hasWaveSuffix(utf8file)) {
|
||||||
song->tag = audiofileTagDup(utf8file);
|
song->tag = audiofileTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_FAAD
|
#ifdef HAVE_FAAD
|
||||||
else if(isAac(utf8file,&(song->mtime))) {
|
else if(hasAacSuffix(utf8file)) {
|
||||||
song->tag = aacTagDup(utf8file);
|
song->tag = aacTagDup(utf8file);
|
||||||
}
|
}
|
||||||
else if(isMp4(utf8file,&(song->mtime))) {
|
else if(hasMp4Suffix(utf8file)) {
|
||||||
song->tag = mp4TagDup(utf8file);
|
song->tag = mp4TagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -227,32 +227,32 @@ int updateSongInfo(Song * song) {
|
|||||||
|
|
||||||
song->tag = NULL;
|
song->tag = NULL;
|
||||||
|
|
||||||
if(0);
|
if(!isFile(utf8file,&(song->mtime)));
|
||||||
#ifdef HAVE_OGG
|
#ifdef HAVE_OGG
|
||||||
else if(isOgg(utf8file,&(song->mtime))) {
|
else if(hasOggSuffix(utf8file)) {
|
||||||
song->tag = oggTagDup(utf8file);
|
song->tag = oggTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_FLAC
|
#ifdef HAVE_FLAC
|
||||||
else if((isFlac(utf8file,&(song->mtime)))) {
|
else if((hasFlacSuffix(utf8file))) {
|
||||||
song->tag = flacTagDup(utf8file);
|
song->tag = flacTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_MAD
|
#ifdef HAVE_MAD
|
||||||
else if(isMp3(utf8file,&(song->mtime))) {
|
else if(hasMp3Suffix(utf8file)) {
|
||||||
song->tag = mp3TagDup(utf8file);
|
song->tag = mp3TagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_AUDIOFILE
|
#ifdef HAVE_AUDIOFILE
|
||||||
else if(isWave(utf8file,&(song->mtime))) {
|
else if(hasWaveSuffix(utf8file)) {
|
||||||
song->tag = audiofileTagDup(utf8file);
|
song->tag = audiofileTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_FAAD
|
#ifdef HAVE_FAAD
|
||||||
else if(isAac(utf8file,&(song->mtime))) {
|
else if(hasAacSuffix(utf8file)) {
|
||||||
song->tag = aacTagDup(utf8file);
|
song->tag = aacTagDup(utf8file);
|
||||||
}
|
}
|
||||||
else if(isMp4(utf8file,&(song->mtime))) {
|
else if(hasMp4Suffix(utf8file)) {
|
||||||
song->tag = mp4TagDup(utf8file);
|
song->tag = mp4TagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user