2006-07-13 21:20:34 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 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"
|
2008-10-08 11:07:35 +02:00
|
|
|
#include "database.h"
|
2008-09-07 13:53:55 +02:00
|
|
|
#include "client.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
#include "utils.h"
|
|
|
|
#include "playlist.h"
|
2006-10-28 01:07:34 +02:00
|
|
|
#include "song.h"
|
2008-09-07 13:35:01 +02:00
|
|
|
#include "song_print.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
#include "tag.h"
|
2008-09-08 11:47:57 +02:00
|
|
|
#include "strset.h"
|
2004-11-11 03:36:25 +01:00
|
|
|
#include "log.h"
|
2007-05-16 14:02:10 +02:00
|
|
|
#include "storedPlaylist.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2008-10-15 19:36:37 +02:00
|
|
|
#include <glib.h>
|
|
|
|
|
2004-11-12 02:44:27 +01:00
|
|
|
typedef struct _ListCommandItem {
|
2008-09-29 13:29:33 +02:00
|
|
|
int8_t tagType;
|
2004-11-10 22:58:27 +01:00
|
|
|
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;
|
|
|
|
|
2007-04-26 01:46:11 +02:00
|
|
|
typedef struct _SearchStats {
|
|
|
|
LocateTagItemArray locateArray;
|
|
|
|
int numberOfSongs;
|
2007-04-26 02:11:30 +02:00
|
|
|
unsigned long playTime;
|
2007-04-26 01:46:11 +02:00
|
|
|
} SearchStats;
|
|
|
|
|
2008-10-08 10:49:05 +02:00
|
|
|
static int
|
|
|
|
countSongsInDirectory(struct directory *directory, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
int *count = (int *)data;
|
|
|
|
|
2008-09-23 20:48:39 +02:00
|
|
|
*count += directory->songs.nr;
|
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
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:05 +02:00
|
|
|
static int
|
|
|
|
printDirectoryInDirectory(struct directory *directory, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-07 13:53:55 +02:00
|
|
|
struct client *client = data;
|
2008-10-08 11:55:52 +02:00
|
|
|
if (!isRootDirectory(directory->path)) {
|
2008-10-08 11:07:58 +02:00
|
|
|
client_printf(client, "directory: %s\n", directory_get_path(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
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
printSongInDirectory(struct song *song, mpd_unused void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-07 13:53:55 +02:00
|
|
|
struct client *client = data;
|
2008-10-07 22:06:59 +02:00
|
|
|
song_print_url(client, song);
|
2006-07-20 18:02:40 +02:00
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:48:24 +02:00
|
|
|
struct search_data {
|
2008-09-07 13:53:55 +02:00
|
|
|
struct client *client;
|
2008-09-07 13:48:24 +02:00
|
|
|
LocateTagItemArray array;
|
|
|
|
};
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
searchInDirectory(struct song *song, void *_data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-07 13:48:24 +02:00
|
|
|
struct search_data *data = _data;
|
|
|
|
LocateTagItemArray *array = &data->array;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2007-02-24 01:54:54 +01:00
|
|
|
if (strstrSearchTags(song, array->numItems, array->items))
|
2008-10-07 22:07:44 +02:00
|
|
|
return song_print_info(data->client, song);
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
int searchForSongsIn(struct client *client, const char *name,
|
|
|
|
int numItems, LocateTagItem * items)
|
2004-11-12 02:44:27 +01:00
|
|
|
{
|
2008-03-26 11:37:36 +01:00
|
|
|
int ret;
|
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 *));
|
2008-09-07 13:48:24 +02:00
|
|
|
struct search_data data;
|
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;
|
2008-10-15 19:36:37 +02:00
|
|
|
items[i].needle = g_utf8_casefold(originalNeedles[i], -1);
|
2004-11-12 02:44:27 +01:00
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
data.client = client;
|
2008-09-07 13:48:24 +02:00
|
|
|
data.array.numItems = numItems;
|
|
|
|
data.array.items = items;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2008-10-08 11:07:55 +02:00
|
|
|
ret = db_walk(name, searchInDirectory, NULL, &data);
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < numItems; i++) {
|
2008-10-15 19:36:37 +02:00
|
|
|
g_free(items[i].needle);
|
2004-11-12 02:44:27 +01:00
|
|
|
items[i].needle = originalNeedles[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
free(originalNeedles);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
findInDirectory(struct song *song, void *_data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-07 13:48:24 +02:00
|
|
|
struct search_data *data = _data;
|
|
|
|
LocateTagItemArray *array = &data->array;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2007-02-24 01:54:54 +01:00
|
|
|
if (tagItemsFoundAndMatches(song, array->numItems, array->items))
|
2008-10-07 22:07:44 +02:00
|
|
|
return song_print_info(data->client, song);
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
int findSongsIn(struct client *client, const char *name,
|
|
|
|
int numItems, LocateTagItem * items)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-07 13:48:24 +02:00
|
|
|
struct search_data data;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
data.client = client;
|
2008-09-07 13:48:24 +02:00
|
|
|
data.array.numItems = numItems;
|
|
|
|
data.array.items = items;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2008-10-08 11:07:55 +02:00
|
|
|
return db_walk(name, findInDirectory, NULL, &data);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
static void printSearchStats(struct client *client, SearchStats *stats)
|
2007-04-26 01:46:11 +02:00
|
|
|
{
|
2008-09-07 13:53:55 +02:00
|
|
|
client_printf(client, "songs: %i\n", stats->numberOfSongs);
|
|
|
|
client_printf(client, "playtime: %li\n", stats->playTime);
|
2007-04-26 01:46:11 +02:00
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
searchStatsInDirectory(struct song *song, void *data)
|
2007-04-26 01:46:11 +02:00
|
|
|
{
|
|
|
|
SearchStats *stats = data;
|
|
|
|
|
|
|
|
if (tagItemsFoundAndMatches(song, stats->locateArray.numItems,
|
|
|
|
stats->locateArray.items)) {
|
|
|
|
stats->numberOfSongs++;
|
|
|
|
if (song->tag->time > 0)
|
|
|
|
stats->playTime += song->tag->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
int searchStatsForSongsIn(struct client *client, const char *name,
|
|
|
|
int numItems, LocateTagItem * items)
|
2007-04-26 01:46:11 +02:00
|
|
|
{
|
|
|
|
SearchStats stats;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
stats.locateArray.numItems = numItems;
|
|
|
|
stats.locateArray.items = items;
|
|
|
|
stats.numberOfSongs = 0;
|
|
|
|
stats.playTime = 0;
|
|
|
|
|
2008-10-08 11:07:55 +02:00
|
|
|
ret = db_walk(name, searchStatsInDirectory, NULL, &stats);
|
2007-04-26 01:46:11 +02:00
|
|
|
if (ret == 0)
|
2008-09-07 13:53:55 +02:00
|
|
|
printSearchStats(client, &stats);
|
2007-04-26 01:46:11 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
int printAllIn(struct client *client, const char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-08 11:07:55 +02:00
|
|
|
return db_walk(name, printSongInDirectory,
|
|
|
|
printDirectoryInDirectory, client);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
directoryAddSongToPlaylist(struct song *song, mpd_unused void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-07 13:39:31 +02:00
|
|
|
return addSongToPlaylist(song, NULL);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:48:24 +02:00
|
|
|
struct add_data {
|
|
|
|
const char *path;
|
|
|
|
};
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
directoryAddSongToStoredPlaylist(struct song *song, void *_data)
|
2006-11-20 16:37:58 +01:00
|
|
|
{
|
2008-09-07 13:48:24 +02:00
|
|
|
struct add_data *data = _data;
|
|
|
|
|
|
|
|
if (appendSongToStoredPlaylistByPath(data->path, song) != 0)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
2006-11-20 16:37:58 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:48:37 +02:00
|
|
|
int addAllIn(const char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-08 11:07:55 +02:00
|
|
|
return db_walk(name, directoryAddSongToPlaylist, NULL, NULL);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:48:37 +02:00
|
|
|
int addAllInToStoredPlaylist(const char *name, const char *utf8file)
|
2006-11-20 16:37:58 +01:00
|
|
|
{
|
2008-09-07 13:48:24 +02:00
|
|
|
struct add_data data = {
|
|
|
|
.path = utf8file,
|
|
|
|
};
|
|
|
|
|
2008-10-08 11:07:55 +02:00
|
|
|
return db_walk(name, directoryAddSongToStoredPlaylist, NULL, &data);
|
2006-11-20 16:37:58 +01:00
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
directoryPrintSongInfo(struct song *song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-07 13:53:55 +02:00
|
|
|
struct client *client = data;
|
2008-10-07 22:06:59 +02:00
|
|
|
song_print_info(client, song);
|
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
sumSongTime(struct song *song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-01-26 13:46:21 +01:00
|
|
|
unsigned long *sum_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)
|
2008-01-26 13:46:21 +01:00
|
|
|
*sum_time += song->tag->time;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
int printInfoForAllIn(struct client *client, const char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-08 11:07:55 +02:00
|
|
|
return db_walk(name, directoryPrintSongInfo,
|
2008-09-07 13:53:55 +02:00
|
|
|
printDirectoryInDirectory, client);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:48:37 +02:00
|
|
|
int countSongsIn(const 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;
|
|
|
|
|
2008-10-08 11:07:55 +02:00
|
|
|
db_walk(name, NULL, countSongsInDirectory, ptr);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2008-09-07 13:48:37 +02:00
|
|
|
unsigned long sumSongTimesIn(const 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;
|
|
|
|
|
2008-10-08 11:07:55 +02:00
|
|
|
db_walk(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);
|
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static void
|
|
|
|
visitTag(struct client *client, struct strset *set,
|
|
|
|
struct song *song, enum tag_type tagType)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
2008-08-29 09:38:11 +02:00
|
|
|
struct tag *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) {
|
2008-10-07 22:06:59 +02:00
|
|
|
song_print_url(client, 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++) {
|
2008-08-29 09:38:29 +02:00
|
|
|
if (tag->items[i]->type == tagType) {
|
2008-09-08 11:47:57 +02:00
|
|
|
strset_add(set, tag->items[i]->value);
|
2008-09-29 13:18:49 +02:00
|
|
|
return;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
}
|
2008-09-29 13:18:49 +02:00
|
|
|
strset_add(set, "");
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:48:24 +02:00
|
|
|
struct list_tags_data {
|
2008-09-07 13:53:55 +02:00
|
|
|
struct client *client;
|
2008-09-07 13:48:24 +02:00
|
|
|
ListCommandItem *item;
|
2008-09-08 11:47:57 +02:00
|
|
|
struct strset *set;
|
2008-09-07 13:48:24 +02:00
|
|
|
};
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
listUniqueTagsInDirectory(struct song *song, void *_data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-07 13:48:24 +02:00
|
|
|
struct list_tags_data *data = _data;
|
|
|
|
ListCommandItem *item = data->item;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2007-02-24 01:54:54 +01:00
|
|
|
if (tagItemsFoundAndMatches(song, item->numConditionals,
|
|
|
|
item->conditionals)) {
|
2008-09-08 11:47:57 +02:00
|
|
|
visitTag(data->client, data->set, song, item->tagType);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
int listAllUniqueTags(struct client *client, 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);
|
2008-09-07 13:48:24 +02:00
|
|
|
struct list_tags_data data = {
|
2008-09-07 13:53:55 +02:00
|
|
|
.client = client,
|
2008-09-07 13:48:24 +02:00
|
|
|
.item = item,
|
|
|
|
};
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
|
2008-09-08 11:47:57 +02:00
|
|
|
data.set = strset_new();
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-10-08 11:07:55 +02:00
|
|
|
ret = db_walk(NULL, listUniqueTagsInDirectory, NULL, &data);
|
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) {
|
2008-09-08 11:47:57 +02:00
|
|
|
const char *value;
|
|
|
|
|
|
|
|
strset_rewind(data.set);
|
|
|
|
|
|
|
|
while ((value = strset_next(data.set)) != NULL)
|
|
|
|
client_printf(client, "%s: %s\n",
|
|
|
|
mpdTagItemKeys[type],
|
|
|
|
value);
|
|
|
|
|
|
|
|
strset_free(data.set);
|
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
|
|
|
|
2008-10-08 10:49:05 +02:00
|
|
|
static int
|
|
|
|
sumSavedFilenameMemoryInDirectory(struct directory *dir, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
int *sum = data;
|
2004-11-11 03:36:25 +01:00
|
|
|
|
2008-10-08 11:55:52 +02:00
|
|
|
if (isRootDirectory(dir->path))
|
2006-07-20 18:02:40 +02:00
|
|
|
return 0;
|
2004-11-11 03:36:25 +01:00
|
|
|
|
2008-10-08 11:07:58 +02:00
|
|
|
*sum += (strlen(directory_get_path(dir)) + 1
|
2008-10-08 10:49:05 +02:00
|
|
|
- sizeof(struct directory *)) * dir->songs.nr;
|
2004-11-11 03:59:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
sumSavedFilenameMemoryInSong(struct 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
|
|
|
|
2008-10-08 11:07:55 +02:00
|
|
|
db_walk(NULL, sumSavedFilenameMemoryInSong,
|
|
|
|
sumSavedFilenameMemoryInDirectory, (void *)&sum);
|
2006-07-13 21:40:14 +02:00
|
|
|
|
|
|
|
DEBUG("saved memory from filenames: %i\n", sum);
|
|
|
|
}
|