Print.cxx 2.12 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 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"
Max Kellermann's avatar
Max Kellermann committed
27
#include "fs/Traits.hxx"
28
#include "thread/Mutex.hxx"
29
#include "thread/Cond.hxx"
30 31
#include "Partition.hxx"
#include "Instance.hxx"
32

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

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

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

64 65 66 67
#ifndef ENABLE_DATABASE
	(void)partition;
#endif

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

76
	playlist_provider_print(r, loader, uri, *playlist, detail);
77
	delete playlist;
78
	return true;
79
}