aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/directory.c207
1 files changed, 2 insertions, 205 deletions
diff --git a/src/directory.c b/src/directory.c
index 443c8bfba..5ac78afaf 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -33,6 +33,8 @@
#include "sig_handlers.h"
#include "player.h"
#include "tagTracker.h"
+#include "list.h"
+#include "dbUtils.h"
#include <string.h>
#include <sys/types.h>
@@ -55,11 +57,6 @@
#define DIRECTORY_MPD_VERSION "mpd_version: "
#define DIRECTORY_FS_CHARSET "fs_charset: "
-#define DIRECTORY_SEARCH_ALBUM "album"
-#define DIRECTORY_SEARCH_ARTIST "artist"
-#define DIRECTORY_SEARCH_TITLE "title"
-#define DIRECTORY_SEARCH_FILENAME "filename"
-
#define DIRECTORY_UPDATE_EXIT_NOUPDATE 0
#define DIRECTORY_UPDATE_EXIT_UPDATE 1
#define DIRECTORY_UPDATE_EXIT_ERROR 2
@@ -68,21 +65,6 @@
#define DIRECTORY_RETURN_UPDATE 1
#define DIRECTORY_RETURN_ERROR -1
-typedef List DirectoryList;
-
-typedef struct _DirectoryStat {
- ino_t inode;
- dev_t device;
-} DirectoryStat;
-
-typedef struct _Directory {
- char * utf8name;
- DirectoryList * subDirectories;
- SongList * songs;
- struct _Directory * parent;
- DirectoryStat * stat;
-} Directory;
-
Directory * mp3rootDirectory = NULL;
char * directory_db;
@@ -1173,182 +1155,6 @@ int traverseAllIn(FILE * fp, char * name,
data);
}
-int countSongsInDirectory(FILE * fp, Directory * directory, void * data) {
- int * count = (int *)data;
-
- *count+=directory->songs->numberOfNodes;
-
- return 0;
-}
-
-int printDirectoryInDirectory(FILE * fp, Directory * directory, void * data) {
- if(directory->utf8name) {
- myfprintf(fp,"directory: %s\n",directory->utf8name);
- }
- return 0;
-}
-
-int printSongInDirectory(FILE * fp, Song * song, void * data) {
- myfprintf(fp,"file: %s\n",song->utf8url);
- return 0;
-}
-
-static inline int strstrSearchTag(Song * song, int type, char * str) {
- int i;
- char * dup;
-
- if(!song->tag) return 0;
-
- for(i = 0; i < song->tag->numOfItems; i++) {
- if(song->tag->items[i].type != type) continue;
-
- dup = strDupToUpper(song->tag->items[i].value);
- if(strstr(dup, str)) return 1;
- free(dup);
- }
-
- return 0;
-}
-
-int searchForAlbumInDirectory(FILE * fp, Song * song, void * string) {
- if(strstrSearchTag(song, TAG_ITEM_ALBUM, (char *)string)) {
- printSongInfo(fp, song);
- }
- return 0;
-}
-
-int searchForArtistInDirectory(FILE * fp, Song * song, void * string) {
- if(strstrSearchTag(song, TAG_ITEM_ARTIST, (char *)string)) {
- printSongInfo(fp, song);
- }
- return 0;
-}
-
-int searchForTitleInDirectory(FILE * fp, Song * song, void * string) {
- if(strstrSearchTag(song, TAG_ITEM_TITLE, (char *)string)) {
- printSongInfo(fp, song);
- }
- return 0;
-}
-
-int searchForFilenameInDirectory(FILE * fp, Song * song, void * string) {
- char * dup = strDupToUpper(song->utf8url);
- if(strstr(dup,(char *)string)) printSongInfo(fp,song);
- free(dup);
- return 0;
-}
-
-int searchForSongsIn(FILE * fp, char * name, char * item, char * string) {
- char * dup = strDupToUpper(string);
- int ret = -1;
-
- if(strcmp(item,DIRECTORY_SEARCH_ALBUM)==0) {
- ret = traverseAllIn(fp,name,searchForAlbumInDirectory,NULL,
- (void *)dup);
- }
- else if(strcmp(item,DIRECTORY_SEARCH_ARTIST)==0) {
- ret = traverseAllIn(fp,name,searchForArtistInDirectory,NULL,
- (void *)dup);
- }
- else if(strcmp(item,DIRECTORY_SEARCH_TITLE)==0) {
- ret = traverseAllIn(fp,name,searchForTitleInDirectory,NULL,
- (void *)dup);
- }
- else if(strcmp(item,DIRECTORY_SEARCH_FILENAME)==0) {
- ret = traverseAllIn(fp,name,searchForFilenameInDirectory,NULL,
- (void *)dup);
- }
- else commandError(fp, ACK_ERROR_ARG, "unknown table", NULL);
-
- free(dup);
-
- return ret;
-}
-
-static inline int tagItemFoundAndMatches(Song * song, int type, char * str) {
- int i;
-
- if(!song->tag) return 0;
-
- for(i = 0; i < song->tag->numOfItems; i++) {
- if(song->tag->items[i].type != type) continue;
-
- if(0 == strcmp(str, song->tag->items[i].value)) return 1;
- }
-
- return 0;
-}
-
-int findAlbumInDirectory(FILE * fp, Song * song, void * string) {
- if(tagItemFoundAndMatches(song, TAG_ITEM_ALBUM, (char *)string))
- {
- printSongInfo(fp,song);
- }
-
- return 0;
-}
-
-int findArtistInDirectory(FILE * fp, Song * song, void * string) {
- if(tagItemFoundAndMatches(song, TAG_ITEM_ARTIST, (char *)string))
- {
- printSongInfo(fp,song);
- }
-
- return 0;
-}
-
-int findSongsIn(FILE * fp, char * name, char * item, char * string) {
- if(strcmp(item,DIRECTORY_SEARCH_ALBUM)==0) {
- return traverseAllIn(fp,name,findAlbumInDirectory,NULL,
- (void *)string);
- }
- else if(strcmp(item,DIRECTORY_SEARCH_ARTIST)==0) {
- return traverseAllIn(fp,name,findArtistInDirectory,NULL,
- (void *)string);
- }
-
- commandError(fp, ACK_ERROR_ARG, "unknown table", NULL);
- return -1;
-}
-
-int printAllIn(FILE * fp, char * name) {
- return traverseAllIn(fp,name,printSongInDirectory,
- printDirectoryInDirectory,NULL);
-}
-
-int directoryAddSongToPlaylist(FILE * fp, Song * song, void * data) {
- return addSongToPlaylist(fp, song, 0);
-}
-
-int addAllIn(FILE * fp, char * name) {
- return traverseAllIn(fp,name,directoryAddSongToPlaylist,NULL,NULL);
-}
-
-int directoryPrintSongInfo(FILE * fp, Song * song, void * data) {
- return printSongInfo(fp,song);
-}
-
-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;
-
- return 0;
-}
-
-int printInfoForAllIn(FILE * fp, char * name) {
- return traverseAllIn(fp,name,directoryPrintSongInfo,printDirectoryInDirectory,NULL);
-}
-
-int countSongsIn(FILE * fp, char * name) {
- int count = 0;
- void * ptr = (void *)&count;
-
- traverseAllIn(fp,name,NULL,countSongsInDirectory,ptr);
-
- return count;
-}
-
void freeAllDirectoryStats(Directory * directory) {
ListNode * node = directory->subDirectories->firstNode;
@@ -1360,15 +1166,6 @@ void freeAllDirectoryStats(Directory * directory) {
freeDirectoryStatFromDirectory(directory);
}
-unsigned long sumSongTimesIn(FILE * fp, char * name) {
- unsigned long dbPlayTime = 0;
- void * ptr = (void *)&dbPlayTime;
-
- traverseAllIn(fp,name,sumSongTime,NULL,ptr);
-
- return dbPlayTime;
-}
-
void initMp3Directory() {
struct stat st;