Print.cxx 2.15 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2015 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

20
#include "config.h"
21
#include "Print.hxx"
22 23
#include "PlaylistAny.hxx"
#include "PlaylistSong.hxx"
24
#include "SongEnumerator.hxx"
25
#include "SongPrint.hxx"
26
#include "DetachedSong.hxx"
27
#include "SongLoader.hxx"
Max Kellermann's avatar
Max Kellermann committed
28
#include "fs/Traits.hxx"
29
#include "thread/Mutex.hxx"
30
#include "thread/Cond.hxx"
31 32
#include "Partition.hxx"
#include "Instance.hxx"
33

34
static void
35 36 37
playlist_provider_print(Response &r, Partition &partition,
			const SongLoader &loader,
			const char *uri,
38
			SongEnumerator &e, bool detail)
39
{
Max Kellermann's avatar
Max Kellermann committed
40
	const std::string base_uri = uri != nullptr
41
		? PathTraitsUTF8::GetParent(uri)
Max Kellermann's avatar
Max Kellermann committed
42
		: std::string(".");
43

44
	std::unique_ptr<DetachedSong> song;
45 46
	while ((song = e.NextSong()) != nullptr) {
		if (playlist_check_translate_song(*song, base_uri.c_str(),
47 48
						  loader) &&
		    detail)
49
			song_print_info(r, partition, *song);
50 51 52
		else
			/* fallback if no detail was requested or no
			   detail was available */
53
			song_print_uri(r, partition, *song);
54 55 56
	}
}

57
bool
58 59 60
playlist_file_print(Response &r, Partition &partition,
		    const SongLoader &loader,
		    const char *uri, bool detail)
61
{
62 63
	Mutex mutex;
	Cond cond;
64

65 66
	SongEnumerator *playlist = playlist_open_any(uri,
#ifdef ENABLE_DATABASE
67
						     partition.instance.storage,
68 69
#endif
						     mutex, cond);
70
	if (playlist == nullptr)
71
		return false;
72

73
	playlist_provider_print(r, partition, loader, uri, *playlist, detail);
74
	delete playlist;
75
	return true;
76
}