2006-07-13 21:20:34 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
2006-07-14 21:37:45 +02:00
|
|
|
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
|
2006-07-13 21:20:34 +02:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
#include "dbUtils.h"
|
|
|
|
|
|
|
|
#include "directory.h"
|
|
|
|
#include "myfprintf.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "playlist.h"
|
2006-10-28 01:07:34 +02:00
|
|
|
#include "song.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
#include "tag.h"
|
|
|
|
#include "tagTracker.h"
|
2004-11-11 03:36:25 +01:00
|
|
|
#include "log.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2004-11-10 23:12:11 +01:00
|
|
|
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
|
2006-10-28 01:07:34 +02:00
|
|
|
#define LOCATE_TAG_FILE_KEY SONG_FILE
|
|
|
|
#define LOCATE_TAG_FILE_KEY_OLD "filename"
|
2005-03-01 00:57:47 +01:00
|
|
|
#define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
|
|
|
|
#define LOCATE_TAG_ANY_KEY "any"
|
|
|
|
|
2004-11-12 02:44:27 +01:00
|
|
|
typedef struct _ListCommandItem {
|
2004-11-10 22:58:27 +01:00
|
|
|
mpd_sint8 tagType;
|
|
|
|
int numConditionals;
|
2006-07-20 18:02:40 +02:00
|
|
|
LocateTagItem *conditionals;
|
2004-11-10 22:58:27 +01:00
|
|
|
} ListCommandItem;
|
|
|
|
|
2004-11-12 02:44:27 +01:00
|
|
|
typedef struct _LocateTagItemArray {
|
|
|
|
int numItems;
|
2006-07-20 18:02:40 +02:00
|
|
|
LocateTagItem *items;
|
2004-11-12 02:44:27 +01:00
|
|
|
} LocateTagItemArray;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int getLocateTagItemType(char *str)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
|
|
|
|
2006-10-28 01:07:34 +02:00
|
|
|
if (0 == strcasecmp(str, LOCATE_TAG_FILE_KEY) ||
|
|
|
|
0 == strcasecmp(str, LOCATE_TAG_FILE_KEY_OLD))
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
return LOCATE_TAG_FILE_TYPE;
|
|
|
|
}
|
|
|
|
|
2006-10-28 01:07:34 +02:00
|
|
|
if (0 == strcasecmp(str, LOCATE_TAG_ANY_KEY))
|
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
return LOCATE_TAG_ANY_TYPE;
|
2005-03-01 00:57:47 +01:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2006-10-28 01:07:34 +02:00
|
|
|
for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++)
|
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
if (0 == strcasecmp(str, mpdTagItemKeys[i]))
|
|
|
|
return i;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int initLocateTagItem(LocateTagItem * item, char *typeStr, char *needle)
|
2004-11-12 02:44:27 +01:00
|
|
|
{
|
|
|
|
item->tagType = getLocateTagItemType(typeStr);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (item->tagType < 0)
|
|
|
|
return -1;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-08-26 08:25:57 +02:00
|
|
|
item->needle = xstrdup(needle);
|
2004-11-12 02:44:27 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
LocateTagItem *newLocateTagItem(char *typeStr, char *needle)
|
|
|
|
{
|
2006-08-26 08:25:57 +02:00
|
|
|
LocateTagItem *ret = xmalloc(sizeof(LocateTagItem));
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (initLocateTagItem(ret, typeStr, needle) < 0) {
|
2004-11-10 22:58:27 +01:00
|
|
|
free(ret);
|
2004-11-12 02:44:27 +01:00
|
|
|
ret = NULL;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void freeLocateTagItemArray(int count, LocateTagItem * array)
|
|
|
|
{
|
2004-11-12 02:44:27 +01:00
|
|
|
int i;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
free(array[i].needle);
|
2004-11-12 02:44:27 +01:00
|
|
|
|
|
|
|
free(array);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int newLocateTagItemArrayFromArgArray(char *argArray[],
|
|
|
|
int numArgs, LocateTagItem ** arrayRet)
|
2004-11-12 02:44:27 +01:00
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
int i, j;
|
|
|
|
LocateTagItem *item;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (numArgs == 0)
|
|
|
|
return 0;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (numArgs % 2 != 0)
|
|
|
|
return -1;
|
|
|
|
|
2006-08-26 08:25:57 +02:00
|
|
|
*arrayRet = xmalloc(sizeof(LocateTagItem) * numArgs / 2);
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
for (i = 0, item = *arrayRet; i < numArgs / 2; i++, item++) {
|
|
|
|
if (initLocateTagItem
|
|
|
|
(item, argArray[i * 2], argArray[i * 2 + 1]) < 0)
|
2004-11-12 02:44:27 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
return numArgs / 2;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-08-10 00:18:06 +02:00
|
|
|
fail:
|
2006-07-20 18:02:40 +02:00
|
|
|
for (j = 0; j < i; j++) {
|
2004-11-12 02:44:27 +01:00
|
|
|
free((*arrayRet)[j].needle);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(*arrayRet);
|
|
|
|
*arrayRet = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void freeLocateTagItem(LocateTagItem * item)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
free(item->needle);
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int countSongsInDirectory(int fd, Directory * directory, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
int *count = (int *)data;
|
|
|
|
|
|
|
|
*count += directory->songs->numberOfNodes;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int printDirectoryInDirectory(int fd, Directory * directory,
|
2006-07-20 18:02:40 +02:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
if (directory->path) {
|
2006-07-30 05:43:38 +02:00
|
|
|
fdprintf(fd, "directory: %s\n", getDirectoryPath(directory));
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int printSongInDirectory(int fd, Song * song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2006-07-30 05:43:38 +02:00
|
|
|
printSongUrl(fd, song);
|
2006-07-20 18:02:40 +02:00
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int strstrSearchTag(Song * song, int type, char *str)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
2006-07-20 18:02:40 +02:00
|
|
|
char *dup;
|
2004-11-10 22:58:27 +01:00
|
|
|
int ret = 0;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) {
|
2004-11-11 03:36:25 +01:00
|
|
|
dup = strDupToUpper(getSongUrl(song));
|
2006-07-20 18:02:40 +02:00
|
|
|
if (strstr(dup, str))
|
|
|
|
ret = 1;
|
2004-11-10 22:58:27 +01:00
|
|
|
free(dup);
|
2005-03-01 00:57:47 +01:00
|
|
|
if (ret == 1 || type == LOCATE_TAG_FILE_TYPE) {
|
|
|
|
return ret;
|
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!song->tag)
|
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < song->tag->numOfItems && !ret; i++) {
|
|
|
|
if (type != LOCATE_TAG_ANY_TYPE &&
|
|
|
|
song->tag->items[i].type != type) {
|
|
|
|
continue;
|
2005-03-01 00:57:47 +01:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
dup = strDupToUpper(song->tag->items[i].value);
|
2006-07-20 18:02:40 +02:00
|
|
|
if (strstr(dup, str))
|
|
|
|
ret = 1;
|
2004-11-10 22:58:27 +01:00
|
|
|
free(dup);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int searchInDirectory(int fd, Song * song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
LocateTagItemArray *array = data;
|
2004-11-12 02:44:27 +01:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < array->numItems; i++) {
|
|
|
|
if (!strstrSearchTag(song, array->items[i].tagType,
|
|
|
|
array->items[i].needle)) {
|
2004-11-12 02:44:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
printSongInfo(fd, song);
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
int searchForSongsIn(int fd, char *name, int numItems, LocateTagItem * items)
|
2004-11-12 02:44:27 +01:00
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int ret = -1;
|
2004-11-12 02:44:27 +01:00
|
|
|
int i;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-08-26 08:25:57 +02:00
|
|
|
char **originalNeedles = xmalloc(numItems * sizeof(char *));
|
2004-11-12 02:44:27 +01:00
|
|
|
LocateTagItemArray array;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < numItems; i++) {
|
2004-11-12 02:44:27 +01:00
|
|
|
originalNeedles[i] = items[i].needle;
|
|
|
|
items[i].needle = strDupToUpper(originalNeedles[i]);
|
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2004-11-12 02:44:27 +01:00
|
|
|
array.numItems = numItems;
|
|
|
|
array.items = items;
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
ret = traverseAllIn(fd, name, searchInDirectory, NULL, &array);
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < numItems; i++) {
|
2004-11-12 02:44:27 +01:00
|
|
|
free(items[i].needle);
|
|
|
|
items[i].needle = originalNeedles[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
free(originalNeedles);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int tagItemFoundAndMatches(Song * song, int type, char *str)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (type == LOCATE_TAG_FILE_TYPE) {
|
|
|
|
if (0 == strcmp(str, getSongUrl(song)))
|
|
|
|
return 1;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!song->tag)
|
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
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;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int findInDirectory(int fd, Song * song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
LocateTagItemArray *array = data;
|
2004-11-12 02:44:27 +01:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < array->numItems; i++) {
|
|
|
|
if (!tagItemFoundAndMatches(song, array->items[i].tagType,
|
|
|
|
array->items[i].needle)) {
|
2004-11-12 02:44:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
printSongInfo(fd, song);
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
int findSongsIn(int fd, char *name, int numItems, LocateTagItem * items)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2004-11-12 02:44:27 +01:00
|
|
|
LocateTagItemArray array;
|
|
|
|
|
|
|
|
array.numItems = numItems;
|
|
|
|
array.items = items;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
return traverseAllIn(fd, name, findInDirectory, NULL, (void *)&array);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
int printAllIn(int fd, char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2006-07-30 05:43:38 +02:00
|
|
|
return traverseAllIn(fd, name, printSongInDirectory,
|
2006-07-20 18:02:40 +02:00
|
|
|
printDirectoryInDirectory, NULL);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int directoryAddSongToPlaylist(int fd, Song * song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2006-07-30 05:43:38 +02:00
|
|
|
return addSongToPlaylist(fd, song, 0);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
int addAllIn(int fd, char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2006-07-30 05:43:38 +02:00
|
|
|
return traverseAllIn(fd, name, directoryAddSongToPlaylist, NULL, NULL);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int directoryPrintSongInfo(int fd, Song * song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2006-07-30 05:43:38 +02:00
|
|
|
return printSongInfo(fd, song);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int sumSongTime(int fd, Song * song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
unsigned long *time = (unsigned long *)data;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (song->tag && song->tag->time >= 0)
|
|
|
|
*time += song->tag->time;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
int printInfoForAllIn(int fd, char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2006-07-30 05:43:38 +02:00
|
|
|
return traverseAllIn(fd, name, directoryPrintSongInfo,
|
2006-07-20 18:02:40 +02:00
|
|
|
printDirectoryInDirectory, NULL);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
int countSongsIn(int fd, char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int count = 0;
|
2006-07-20 18:02:40 +02:00
|
|
|
void *ptr = (void *)&count;
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
traverseAllIn(fd, name, NULL, countSongsInDirectory, ptr);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
unsigned long sumSongTimesIn(int fd, char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
unsigned long dbPlayTime = 0;
|
2006-07-20 18:02:40 +02:00
|
|
|
void *ptr = (void *)&dbPlayTime;
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
traverseAllIn(fd, name, sumSongTime, NULL, ptr);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return dbPlayTime;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static ListCommandItem *newListCommandItem(int tagType, int numConditionals,
|
|
|
|
LocateTagItem * conditionals)
|
2004-11-10 22:58:27 +01:00
|
|
|
{
|
2006-08-26 08:25:57 +02:00
|
|
|
ListCommandItem *item = xmalloc(sizeof(ListCommandItem));
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
item->tagType = tagType;
|
|
|
|
item->numConditionals = numConditionals;
|
|
|
|
item->conditionals = conditionals;
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void freeListCommandItem(ListCommandItem * item)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static void visitTag(int fd, Song * song, int tagType)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
2006-07-20 18:02:40 +02:00
|
|
|
MpdTag *tag = song->tag;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (tagType == LOCATE_TAG_FILE_TYPE) {
|
2006-07-30 05:43:38 +02:00
|
|
|
printSongUrl(fd, song);
|
2004-11-10 22:58:27 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!tag)
|
|
|
|
return;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < tag->numOfItems; i++) {
|
|
|
|
if (tag->items[i].type == tagType) {
|
2004-11-11 14:15:41 +01:00
|
|
|
visitInTagTracker(tagType, tag->items[i].value);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int listUniqueTagsInDirectory(int fd, Song * song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
ListCommandItem *item = data;
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < item->numConditionals; i++) {
|
|
|
|
if (!tagItemFoundAndMatches(song, item->conditionals[i].tagType,
|
|
|
|
item->conditionals[i].needle)) {
|
2004-11-10 22:58:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
visitTag(fd, song, item->tagType);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
int listAllUniqueTags(int fd, int type, int numConditionals,
|
2006-07-20 18:02:40 +02:00
|
|
|
LocateTagItem * conditionals)
|
2004-11-10 22:58:27 +01:00
|
|
|
{
|
|
|
|
int ret;
|
2006-07-20 18:02:40 +02:00
|
|
|
ListCommandItem *item = newListCommandItem(type, numConditionals,
|
|
|
|
conditionals);
|
|
|
|
|
|
|
|
if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
|
2004-11-10 22:58:27 +01:00
|
|
|
resetVisitedFlagsInTagTracker(type);
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
ret = traverseAllIn(fd, NULL, listUniqueTagsInDirectory, NULL,
|
2006-07-20 18:02:40 +02:00
|
|
|
(void *)item);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
|
2006-07-30 05:43:38 +02:00
|
|
|
printVisitedInTagTracker(fd, type);
|
2004-11-11 14:15:41 +01:00
|
|
|
}
|
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
freeListCommandItem(item);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2004-11-11 03:36:25 +01:00
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int sumSavedFilenameMemoryInDirectory(int fd, Directory * dir,
|
2006-07-20 18:02:40 +02:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
int *sum = data;
|
2004-11-11 03:36:25 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!dir->path)
|
|
|
|
return 0;
|
2004-11-11 03:36:25 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
*sum += (strlen(getDirectoryPath(dir)) + 1 - sizeof(Directory *)) *
|
|
|
|
dir->songs->numberOfNodes;
|
2004-11-11 03:59:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
static int sumSavedFilenameMemoryInSong(int fd, Song * song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
int *sum = data;
|
|
|
|
|
|
|
|
*sum += strlen(song->url) + 1;
|
2004-11-11 03:59:16 +01:00
|
|
|
|
2004-11-11 03:36:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void printSavedMemoryFromFilenames(void)
|
|
|
|
{
|
2006-07-13 21:40:14 +02:00
|
|
|
int sum = 0;
|
2004-11-11 06:25:05 +01:00
|
|
|
|
2006-07-30 05:43:38 +02:00
|
|
|
traverseAllIn(STDERR_FILENO, NULL, sumSavedFilenameMemoryInSong,
|
2006-07-20 18:02:40 +02:00
|
|
|
sumSavedFilenameMemoryInDirectory, (void *)&sum);
|
2006-07-13 21:40:14 +02:00
|
|
|
|
|
|
|
DEBUG("saved memory from filenames: %i\n", sum);
|
|
|
|
}
|