aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/directory.c11
-rw-r--r--src/playlist.c26
-rw-r--r--src/song.c141
-rw-r--r--src/song.h13
4 files changed, 109 insertions, 82 deletions
diff --git a/src/directory.c b/src/directory.c
index ed0992021..356664501 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -277,7 +277,7 @@ void removeSongFromDirectory(Directory * directory, char * shortname) {
void * song;
if(findInList(directory->songs,shortname,&song)) {
- LOG("removing: %s\n",((Song *)song)->utf8file);
+ LOG("removing: %s\n",((Song *)song)->utf8url);
deleteFromList(directory->songs,shortname);
}
}
@@ -508,7 +508,7 @@ int updatePath(char * utf8path) {
}
else if((song = getSongDetails(path,&shortname,&parentDirectory))) {
/* if this song update is successfull, we are done */
- if(song && isMusic(song->utf8file,&mtime)) {
+ if(song && isMusic(song->utf8url,&mtime)) {
free(path);
if(song->mtime==mtime) return 0;
else if(updateSongInfo(song)==0) return 1;
@@ -655,7 +655,8 @@ int addToDirectory(Directory * directory, char * shortname, char * name) {
}
else if(isMusic(name,NULL)) {
Song * song;
- song = addSongToList(directory->songs,shortname,name);
+ song = addSongToList(directory->songs,shortname,name,
+ SONG_TYPE_FILE);
if(!song) return -1;
LOG("added %s\n",name);
return 1;
@@ -1071,7 +1072,7 @@ int printDirectoryInDirectory(FILE * fp, Directory * directory, void * data) {
}
int printSongInDirectory(FILE * fp, Song * song, void * data) {
- myfprintf(fp,"file: %s\n",song->utf8file);
+ myfprintf(fp,"file: %s\n",song->utf8url);
return 0;
}
@@ -1103,7 +1104,7 @@ int searchForTitleInDirectory(FILE * fp, Song * song, void * string) {
}
int searchForFilenameInDirectory(FILE * fp, Song * song, void * string) {
- char * dup = strDupToUpper(song->utf8file);
+ char * dup = strDupToUpper(song->utf8url);
if(strstr(dup,(char *)string)) printSongInfo(fp,song);
free(dup);
return 0;
diff --git a/src/playlist.c b/src/playlist.c
index e7a5c8438..1bc5147bb 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -161,7 +161,7 @@ int showPlaylist(FILE * fp) {
int i;
for(i=0;i<playlist.length;i++) {
- myfprintf(fp,"%i:%s\n",i,(playlist.songs[i])->utf8file);
+ myfprintf(fp,"%i:%s\n",i,(playlist.songs[i])->utf8url);
}
return 0;
@@ -357,7 +357,7 @@ int playlistInfo(FILE * fp,int song) {
}
for(i=begin;i<end;i++) {
- myfprintf(fp,"file: %s\n",(playlist.songs[i])->utf8file);
+ myfprintf(fp,"file: %s\n",(playlist.songs[i])->utf8url);
if((tag = (playlist.songs[i])->tag)) {
printMpdTag(fp,tag);
}
@@ -380,9 +380,9 @@ void queueNextSongInPlaylist() {
DEBUG("playlist: queue song %i:\"%s\"\n",
playlist.queued,
playlist.songs[playlist.order[
- playlist.queued]]->utf8file);
+ playlist.queued]]->utf8url);
if(queueSong(playlist.songs[playlist.order[
- playlist.queued]]->utf8file)<0) {
+ playlist.queued]]->utf8url)<0) {
playlist.queued = -1;
playlist_queueError = 1;
}
@@ -395,9 +395,9 @@ void queueNextSongInPlaylist() {
DEBUG("playlist: queue song %i:\"%s\"\n",
playlist.queued,
playlist.songs[playlist.order[
- playlist.queued]]->utf8file);
+ playlist.queued]]->utf8url);
if(queueSong(playlist.songs[playlist.order[
- playlist.queued]]->utf8file)<0) {
+ playlist.queued]]->utf8url)<0) {
playlist.queued = -1;
playlist_queueError = 1;
}
@@ -645,10 +645,10 @@ int playPlaylistOrderNumber(FILE * fp, int orderNum) {
playlist.current = orderNum;
DEBUG("playlist: play %i:\"%s\"\n",orderNum,
- (playlist.songs[playlist.order[orderNum]])->utf8file);
+ (playlist.songs[playlist.order[orderNum]])->utf8url);
if(playerPlay(fp,(playlist.songs[playlist.order[orderNum]])->
- utf8file)<0)
+ utf8url)<0)
{
stopPlaylist(fp);
return -1;
@@ -1052,12 +1052,14 @@ int savePlaylist(FILE * fp, char * utf8file) {
}
for(i=0;i<playlist.length;i++) {
- if(playlist_saveAbsolutePaths) {
+ if(playlist_saveAbsolutePaths &&
+ playlist.songs[i]->type==SONG_TYPE_FILE)
+ {
myfprintf(fileP,"%s\n",rmp2amp(utf8ToFsCharset((
- playlist.songs[i])->utf8file)));
+ playlist.songs[i])->utf8url)));
}
else myfprintf(fileP,"%s\n",
- utf8ToFsCharset((playlist.songs[i])->utf8file));
+ utf8ToFsCharset((playlist.songs[i])->utf8url));
}
while(fclose(fileP) && errno==EINTR);
@@ -1203,6 +1205,6 @@ int seekSongInPlaylist(FILE * fp, int song, float time) {
if(playPlaylistOrderNumber(fp,i)<0) return -1;
}
- return playerSeek(fp,playlist.songs[playlist.order[i]]->utf8file,time);
+ return playerSeek(fp,playlist.songs[playlist.order[i]]->utf8url,time);
}
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/song.c b/src/song.c
index 4ce90e023..5991a2612 100644
--- a/src/song.c
+++ b/src/song.c
@@ -47,65 +47,69 @@ Song * newNullSong() {
Song * song = malloc(sizeof(Song));
song->tag = NULL;
- song->utf8file = NULL;
+ song->utf8url = NULL;
+ song->type = SONG_TYPE_FILE;
return song;
}
-Song * newSong(char * utf8file) {
+Song * newSong(char * utf8url, SONG_TYPE type) {
Song * song = newNullSong();
- song->utf8file = strdup(utf8file);
+ song->utf8url = strdup(utf8url);
+ song->type = type;
- if(!isFile(utf8file,&(song->mtime)));
+ if(song->type == SONG_TYPE_FILE) {
+ if(!isFile(utf8url,&(song->mtime)));
#ifdef HAVE_OGG
- else if(hasOggSuffix(utf8file)) {
- song->tag = oggTagDup(utf8file);
- }
+ else if(hasOggSuffix(utf8url)) {
+ song->tag = oggTagDup(utf8url);
+ }
#endif
#ifdef HAVE_FLAC
- else if((hasFlacSuffix(utf8file))) {
- song->tag = flacTagDup(utf8file);
- }
+ else if((hasFlacSuffix(utf8url))) {
+ song->tag = flacTagDup(utf8url);
+ }
#endif
#ifdef HAVE_MAD
- else if(hasMp3Suffix(utf8file)) {
- song->tag = mp3TagDup(utf8file);
- }
+ else if(hasMp3Suffix(utf8url)) {
+ song->tag = mp3TagDup(utf8url);
+ }
#endif
#ifdef HAVE_AUDIOFILE
- else if(hasWaveSuffix(utf8file)) {
- song->tag = audiofileTagDup(utf8file);
- }
+ else if(hasWaveSuffix(utf8url)) {
+ song->tag = audiofileTagDup(utf8url);
+ }
#endif
#ifdef HAVE_FAAD
- else if(hasAacSuffix(utf8file)) {
- song->tag = aacTagDup(utf8file);
- }
- else if(hasMp4Suffix(utf8file)) {
- song->tag = mp4TagDup(utf8file);
- }
+ else if(hasAacSuffix(utf8url)) {
+ song->tag = aacTagDup(utf8url);
+ }
+ else if(hasMp4Suffix(utf8url)) {
+ song->tag = mp4TagDup(utf8url);
+ }
#endif
- if(!song->tag || song->tag->time<0) {
- freeSong(song);
- song = NULL;
+ if(!song->tag || song->tag->time<0) {
+ freeSong(song);
+ song = NULL;
+ }
+ else addSongToTables(song);
}
- else addSongToTables(song);
return song;
}
void freeSong(Song * song) {
deleteASongFromPlaylist(song);
- removeASongFromTables(song);
- free(song->utf8file);
+ if(song->type == SONG_TYPE_FILE) removeASongFromTables(song);
+ free(song->utf8url);
if(song->tag) freeMpdTag(song->tag);
free(song);
}
void freeJustSong(Song * song) {
- free(song->utf8file);
+ free(song->utf8url);
if(song->tag) freeMpdTag(song->tag);
free(song);
}
@@ -114,11 +118,20 @@ SongList * newSongList() {
return makeList((ListFreeDataFunc *)freeSong);
}
-Song * addSongToList(SongList * list, char * key, char * utf8file) {
+Song * addSongToList(SongList * list, char * key, char * utf8url,
+ SONG_TYPE type)
+{
Song * song = NULL;
-
- if(isMusic(utf8file,NULL)) {
- song = newSong(utf8file);
+
+ switch(type) {
+ case SONG_TYPE_FILE:
+ if(isMusic(utf8url,NULL)) {
+ song = newSong(utf8url,type);
+ }
+ break;
+ case SONG_TYPE_URL:
+ song = newSong(utf8url,type);
+ break;
}
if(song==NULL) return NULL;
@@ -133,7 +146,7 @@ void freeSongList(SongList * list) {
}
int printSongInfo(FILE * fp, Song * song) {
- myfprintf(fp,"%s%s\n",SONG_FILE,song->utf8file);
+ myfprintf(fp,"%s%s\n",SONG_FILE,song->utf8url);
if(song->tag) printMpdTag(fp,song->tag);
@@ -220,13 +233,14 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
key = strdup(&(buffer[strlen(SONG_KEY)]));
song = newNullSong();
+ song->type = SONG_TYPE_FILE;
}
else if(0==strncmp(SONG_FILE,buffer,strlen(SONG_FILE))) {
- if(!song || song->utf8file) {
+ if(!song || song->utf8url) {
ERROR("Problems reading song info\n");
exit(EXIT_FAILURE);
}
- song->utf8file = strdup(&(buffer[strlen(SONG_FILE)]));
+ song->utf8url = strdup(&(buffer[strlen(SONG_FILE)]));
}
else if(0==strncmp(SONG_ARTIST,buffer,strlen(SONG_ARTIST))) {
if(!song->tag) song->tag = newMpdTag();
@@ -271,45 +285,47 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
}
int updateSongInfo(Song * song) {
- char * utf8file = song->utf8file;
+ char * utf8url = song->utf8url;
- removeASongFromTables(song);
- if(song->tag) freeMpdTag(song->tag);
+ if(song->type == SONG_TYPE_FILE) {
+ removeASongFromTables(song);
+ if(song->tag) freeMpdTag(song->tag);
- song->tag = NULL;
+ song->tag = NULL;
- if(!isFile(utf8file,&(song->mtime)));
+ if(!isFile(utf8url,&(song->mtime)));
#ifdef HAVE_OGG
- else if(hasOggSuffix(utf8file)) {
- song->tag = oggTagDup(utf8file);
- }
+ else if(hasOggSuffix(utf8url)) {
+ song->tag = oggTagDup(utf8url);
+ }
#endif
#ifdef HAVE_FLAC
- else if((hasFlacSuffix(utf8file))) {
- song->tag = flacTagDup(utf8file);
- }
+ else if((hasFlacSuffix(utf8url))) {
+ song->tag = flacTagDup(utf8url);
+ }
#endif
#ifdef HAVE_MAD
- else if(hasMp3Suffix(utf8file)) {
- song->tag = mp3TagDup(utf8file);
- }
+ else if(hasMp3Suffix(utf8url)) {
+ song->tag = mp3TagDup(utf8url);
+ }
#endif
#ifdef HAVE_AUDIOFILE
- else if(hasWaveSuffix(utf8file)) {
- song->tag = audiofileTagDup(utf8file);
- }
+ else if(hasWaveSuffix(utf8url)) {
+ song->tag = audiofileTagDup(utf8url);
+ }
#endif
#ifdef HAVE_FAAD
- else if(hasAacSuffix(utf8file)) {
- song->tag = aacTagDup(utf8file);
- }
- else if(hasMp4Suffix(utf8file)) {
- song->tag = mp4TagDup(utf8file);
- }
+ else if(hasAacSuffix(utf8url)) {
+ song->tag = aacTagDup(utf8url);
+ }
+ else if(hasMp4Suffix(utf8url)) {
+ song->tag = mp4TagDup(utf8url);
+ }
#endif
- if(!song->tag || song->tag->time<0) return -1;
- else addSongToTables(song);
+ if(!song->tag || song->tag->time<0) return -1;
+ else addSongToTables(song);
+ }
return 0;
}
@@ -317,9 +333,10 @@ int updateSongInfo(Song * song) {
Song * songDup(Song * song) {
Song * ret = malloc(sizeof(Song));
- ret->utf8file = strdup(song->utf8file);
+ ret->utf8url = strdup(song->utf8url);
ret->mtime = song->mtime;
ret->tag = mpdTagDup(song->tag);
+ ret->type = song->type;
return ret;
}
diff --git a/src/song.h b/src/song.h
index eaa44bedc..10286c22c 100644
--- a/src/song.h
+++ b/src/song.h
@@ -30,15 +30,21 @@
#include "tag.h"
#include "list.h"
+typedef enum {
+ SONG_TYPE_FILE,
+ SONG_TYPE_URL
+} SONG_TYPE;
+
typedef struct _Song {
- char * utf8file;
+ char * utf8url;
+ SONG_TYPE type;
MpdTag * tag;
time_t mtime;
} Song;
typedef List SongList;
-Song * newSong(char * utf8file);
+Song * newSong(char * utf8url, SONG_TYPE type);
void freeSong(Song *);
@@ -46,7 +52,8 @@ SongList * newSongList();
void freeSongList(SongList * list);
-Song * addSongToList(SongList * list, char * key, char * utf8file);
+Song * addSongToList(SongList * list, char * key, char * utf8file,
+ SONG_TYPE type);
int printSongInfo(FILE * fp, Song * song);