diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-05-13 18:46:38 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-05-13 18:46:38 +0000 |
commit | 965e6edcf18948ea6971040495e2121a326aa11b (patch) | |
tree | 07d401bd1726b84d73ccba099b677067a05730d4 /src | |
parent | 8c484eeccfaafd2d5eaf7cd77842581004957a8a (diff) | |
download | mpd-965e6edcf18948ea6971040495e2121a326aa11b.tar.gz mpd-965e6edcf18948ea6971040495e2121a326aa11b.tar.xz mpd-965e6edcf18948ea6971040495e2121a326aa11b.zip |
redimentary addition of url's to playlist
git-svn-id: https://svn.musicpd.org/mpd/trunk@1000 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r-- | src/command.c | 9 | ||||
-rw-r--r-- | src/directory.c | 4 | ||||
-rw-r--r-- | src/directory.h | 2 | ||||
-rw-r--r-- | src/ls.c | 22 | ||||
-rw-r--r-- | src/ls.h | 2 | ||||
-rw-r--r-- | src/playlist.c | 27 | ||||
-rw-r--r-- | src/song.h | 2 |
7 files changed, 56 insertions, 12 deletions
diff --git a/src/command.c b/src/command.c index 9a7072c43..bf77dc8e7 100644 --- a/src/command.c +++ b/src/command.c @@ -237,10 +237,13 @@ int handleClose(FILE * fp, unsigned int * permission, int argArrayLength, int handleAdd(FILE * fp, unsigned int * permission, int argArrayLength, char ** argArray) { - char * directory = NULL; + char * path = NULL; - if(argArrayLength == 2) directory = argArray[1]; - return addAllIn(fp,directory); + if(argArrayLength == 2) { + path = argArray[1]; + if(isRemoteUrl(path)) return addToPlaylist(fp,path); + } + return addAllIn(fp,path); } int handleDelete(FILE * fp, unsigned int * permission, int argArrayLength, diff --git a/src/directory.c b/src/directory.c index 356664501..095023f0f 100644 --- a/src/directory.c +++ b/src/directory.c @@ -1045,7 +1045,7 @@ int traverseAllIn(FILE * fp, char * name, if((directory = getDirectory(name))==NULL) { Song * song; - if((song = getSong(name)) && forEachSong) { + if((song = getSongFromDB(name)) && forEachSong) { return forEachSong(fp, song, data); } myfprintf(fp,"%s: directory or file not found\n",COMMAND_RESPOND_ERROR); @@ -1269,7 +1269,7 @@ Song * getSongDetails(char * file, char ** shortnameRet, return (Song *)song; } -Song * getSong(char * file) { +Song * getSongFromDB(char * file) { return getSongDetails(file,NULL,NULL); } diff --git a/src/directory.h b/src/directory.h index 9681d74fc..eb9c6fcc7 100644 --- a/src/directory.h +++ b/src/directory.h @@ -65,7 +65,7 @@ int countSongsIn(FILE * fp, char * name); unsigned long sumSongTimesIn(FILE * fp, char * name); -Song * getSong(char * file); +Song * getSongFromDB(char * file); time_t getDbModTime(); @@ -41,6 +41,28 @@ char * dupAndStripPlaylistSuffix(char * file) { return ret; } +int isRemoteUrl(char * url) { + char * urlPrefixes[] = { + "http://", + "ftp://", + NULL + }; + + while(*urlPrefixes) { + if(strncmp(*urlPrefixes,url,strlen(*urlPrefixes)) == 0) { +#ifdef HAVE_MAD + if(hasMp3Suffix(*urlPrefixes)) return 1; +#endif +#ifdef HAVE_OGG + if(hasOggSuffix(*urlPrefixes)) return 1; + return 0; +#endif + } + } + + return 0; +} + int lsPlaylists(FILE * fp, char * utf8path) { DIR * dir; struct stat st; @@ -26,6 +26,8 @@ int lsPlaylists(FILE * fp, char * utf8path); +int isRemoteUrl(char * url); + int isFile(char * utf8file, time_t * mtime); int isDir(char * utf8name); diff --git a/src/playlist.c b/src/playlist.c index 1bc5147bb..a705b3160 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -149,7 +149,12 @@ int clearPlaylist(FILE * fp) { if(stopPlaylist(fp)<0) return -1; - for(i=0;i<playlist.length;i++) playlist.songs[i] = NULL; + for(i=0;i<playlist.length;i++) { + if(playlist.songs[i]->type == SONG_TYPE_URL) { + free(playlist.songs[i]); + } + playlist.songs[i] = NULL; + } playlist.length = 0; incrPlaylistVersion(); @@ -449,13 +454,18 @@ void clearPlayerQueue() { } } -int addToPlaylist(FILE * fp, char * file) { +int addToPlaylist(FILE * fp, char * url) { Song * song; - DEBUG("add to playlist: %s\n",file); + DEBUG("add to playlist: %s\n",url); - if(!(song = getSong(file))) { - myfprintf(fp,"%s \"%s\" is not in the music db\n",COMMAND_RESPOND_ERROR,file); + if((song = getSongFromDB(url))) { + } + else if(isRemoteUrl(url) && (song = newSong(url,SONG_TYPE_URL))) { + } + else { + myfprintf(fp,"%s \"%s\" is not in the music db\n", + COMMAND_RESPOND_ERROR,url); return -1; } @@ -588,6 +598,9 @@ int deleteFromPlaylist(FILE * fp, int song) { if(playlist.order[i]>song) playlist.order[i]--; } /* now take care of other misc stuff */ + if(playlist.songs[playlist.length-1]->type == SONG_TYPE_URL) { + freeJustSong(playlist.songs[playlist.length-1]); + } playlist.songs[playlist.length-1] = NULL; playlist.length--; @@ -1127,7 +1140,9 @@ int loadPlaylist(FILE * fp, char * utf8file) { temp = fsCharsetToUtf8(s); if(!temp) continue; temp = strdup(temp); - if(s[0]==PLAYLIST_COMMENT && !getSong(temp)) { + if(s[0]==PLAYLIST_COMMENT && !getSongFromDB(temp) + && !isRemoteUrl(temp)) + { free(temp); continue; } diff --git a/src/song.h b/src/song.h index 10286c22c..48d1dcd7f 100644 --- a/src/song.h +++ b/src/song.h @@ -48,6 +48,8 @@ Song * newSong(char * utf8url, SONG_TYPE type); void freeSong(Song *); +void freeJustSong(Song *); + SongList * newSongList(); void freeSongList(SongList * list); |