redimentary addition of url's to playlist

git-svn-id: https://svn.musicpd.org/mpd/trunk@1000 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-05-13 18:46:38 +00:00
parent 8c484eeccf
commit 965e6edcf1
7 changed files with 56 additions and 12 deletions

View File

@ -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,

View File

@ -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);
}

View File

@ -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();

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -48,6 +48,8 @@ Song * newSong(char * utf8url, SONG_TYPE type);
void freeSong(Song *);
void freeJustSong(Song *);
SongList * newSongList();
void freeSongList(SongList * list);