2009-03-13 18:43:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2009 The Music Player Daemon Project
|
|
|
|
* http://www.musicpd.org
|
2008-09-07 13:35:01 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-09-07 13:35:01 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "song_print.h"
|
2008-10-08 10:49:11 +02:00
|
|
|
#include "song.h"
|
2008-09-23 20:48:39 +02:00
|
|
|
#include "songvec.h"
|
2008-09-07 13:35:01 +02:00
|
|
|
#include "directory.h"
|
|
|
|
#include "tag_print.h"
|
2008-09-07 13:53:55 +02:00
|
|
|
#include "client.h"
|
2009-02-27 19:20:11 +01:00
|
|
|
#include "uri.h"
|
2008-09-07 13:35:01 +02:00
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
void
|
2009-10-13 18:01:06 +02:00
|
|
|
song_print_uri(struct client *client, struct song *song)
|
2008-09-07 13:35:01 +02:00
|
|
|
{
|
2009-01-04 19:08:52 +01:00
|
|
|
if (song_in_database(song) && !directory_is_root(song->parent)) {
|
2008-09-07 13:53:55 +02:00
|
|
|
client_printf(client, "%s%s/%s\n", SONG_FILE,
|
2009-10-13 18:01:06 +02:00
|
|
|
directory_get_path(song->parent), song->uri);
|
2008-09-07 13:35:01 +02:00
|
|
|
} else {
|
2009-02-27 19:20:11 +01:00
|
|
|
char *allocated;
|
|
|
|
const char *uri;
|
|
|
|
|
2009-10-13 18:01:06 +02:00
|
|
|
uri = allocated = uri_remove_auth(song->uri);
|
2009-02-27 19:20:11 +01:00
|
|
|
if (uri == NULL)
|
2009-10-13 18:01:06 +02:00
|
|
|
uri = song->uri;
|
2009-02-27 19:20:11 +01:00
|
|
|
|
|
|
|
client_printf(client, "%s%s\n", SONG_FILE, uri);
|
|
|
|
|
|
|
|
g_free(allocated);
|
2008-09-07 13:35:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
int
|
|
|
|
song_print_info(struct client *client, struct song *song)
|
2008-09-07 13:35:01 +02:00
|
|
|
{
|
2009-10-13 18:01:06 +02:00
|
|
|
song_print_uri(client, song);
|
2008-09-07 13:35:01 +02:00
|
|
|
|
2009-07-05 08:40:29 +02:00
|
|
|
if (song->mtime > 0) {
|
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
struct tm tm;
|
|
|
|
#endif
|
2009-07-06 11:48:21 +02:00
|
|
|
const struct tm *tm2;
|
2009-07-05 08:40:29 +02:00
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
2009-07-06 11:48:21 +02:00
|
|
|
tm2 = gmtime(&song->mtime);
|
2009-07-05 08:40:29 +02:00
|
|
|
#else
|
2009-07-06 11:48:21 +02:00
|
|
|
tm2 = gmtime_r(&song->mtime, &tm);
|
2009-07-05 08:40:29 +02:00
|
|
|
#endif
|
2009-07-06 11:48:21 +02:00
|
|
|
|
|
|
|
if (tm2 != NULL) {
|
|
|
|
char timestamp[32];
|
|
|
|
|
|
|
|
strftime(timestamp, sizeof(timestamp), "%FT%TZ", tm2);
|
|
|
|
client_printf(client, "Last-Modified: %s\n",
|
|
|
|
timestamp);
|
|
|
|
}
|
2009-07-05 08:40:29 +02:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:35:01 +02:00
|
|
|
if (song->tag)
|
2008-09-07 13:53:55 +02:00
|
|
|
tag_print(client, song->tag);
|
2008-09-07 13:35:01 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-07 22:10:42 +02:00
|
|
|
static int
|
2008-10-08 10:49:11 +02:00
|
|
|
song_print_info_x(struct song *song, void *data)
|
2008-09-07 13:35:01 +02:00
|
|
|
{
|
2008-10-07 22:10:42 +02:00
|
|
|
struct client *client = data;
|
|
|
|
return song_print_info(client, song);
|
|
|
|
}
|
2008-09-07 13:35:01 +02:00
|
|
|
|
2008-10-07 22:10:42 +02:00
|
|
|
int songvec_print(struct client *client, const struct songvec *sv)
|
|
|
|
{
|
|
|
|
return songvec_for_each(sv, song_print_info_x, client);
|
2008-09-07 13:35:01 +02:00
|
|
|
}
|