song_print.c 2.61 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2010 The Music Player Daemon Project
3
 * http://www.musicpd.org
4 5 6 7 8 9 10 11 12 13
 *
 * 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.
14 15 16 17
 *
 * 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.
18 19
 */

20
#include "config.h"
21
#include "song_print.h"
22
#include "song.h"
23
#include "songvec.h"
24 25
#include "directory.h"
#include "tag_print.h"
26
#include "client.h"
27
#include "uri.h"
28
#include "mapper.h"
29

30
void
31
song_print_uri(struct client *client, struct song *song)
32
{
33
	if (song_in_database(song) && !directory_is_root(song->parent)) {
34
		client_printf(client, "%s%s/%s\n", SONG_FILE,
35
			      directory_get_path(song->parent), song->uri);
36
	} else {
37 38 39
		char *allocated;
		const char *uri;

40
		uri = allocated = uri_remove_auth(song->uri);
41
		if (uri == NULL)
42
			uri = song->uri;
43

44 45
		client_printf(client, "%s%s\n", SONG_FILE,
			      map_to_relative_path(uri));
46 47

		g_free(allocated);
48 49 50
	}
}

51
void
52
song_print_info(struct client *client, struct song *song)
53
{
54
	song_print_uri(client, song);
55

56 57 58 59 60 61 62 63 64 65
	if (song->end_ms > 0)
		client_printf(client, "Range: %u.%03u-%u.%03u\n",
			      song->start_ms / 1000,
			      song->start_ms % 1000,
			      song->end_ms / 1000,
			      song->end_ms % 1000);
	else if (song->start_ms > 0)
		client_printf(client, "Range: %u.%03u-\n",
			      song->start_ms / 1000,
			      song->start_ms % 1000);
66

67 68 69 70
	if (song->mtime > 0) {
#ifndef G_OS_WIN32
		struct tm tm;
#endif
71
		const struct tm *tm2;
72 73

#ifdef G_OS_WIN32
74
		tm2 = gmtime(&song->mtime);
75
#else
76
		tm2 = gmtime_r(&song->mtime, &tm);
77
#endif
78 79 80 81

		if (tm2 != NULL) {
			char timestamp[32];

82 83 84 85 86 87 88
			strftime(timestamp, sizeof(timestamp),
#ifdef G_OS_WIN32
				 "%Y-%m-%dT%H:%M:%SZ",
#else
				 "%FT%TZ",
#endif
				 tm2);
89 90 91
			client_printf(client, "Last-Modified: %s\n",
				      timestamp);
		}
92 93
	}

94
	if (song->tag)
95
		tag_print(client, song->tag);
96 97
}

98
static int
99
song_print_info_x(struct song *song, void *data)
100
{
101
	struct client *client = data;
102 103 104
	song_print_info(client, song);

	return 0;
105
}
106

107 108
void
songvec_print(struct client *client, const struct songvec *sv)
109
{
110
	songvec_for_each(sv, song_print_info_x, client);
111
}