2009-10-13 18:53:33 +02:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2009-10-13 18:53:33 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2014-01-23 23:30:12 +01:00
|
|
|
#include "Print.hxx"
|
2013-01-02 18:38:32 +01:00
|
|
|
#include "PlaylistAny.hxx"
|
|
|
|
#include "PlaylistSong.hxx"
|
2013-09-05 09:37:54 +02:00
|
|
|
#include "SongEnumerator.hxx"
|
2014-01-23 23:30:12 +01:00
|
|
|
#include "SongPrint.hxx"
|
2014-01-07 21:39:47 +01:00
|
|
|
#include "DetachedSong.hxx"
|
2013-10-21 10:26:53 +02:00
|
|
|
#include "fs/Traits.hxx"
|
2014-02-07 20:27:24 +01:00
|
|
|
#include "thread/Mutex.hxx"
|
2014-01-23 23:30:12 +01:00
|
|
|
#include "thread/Cond.hxx"
|
2015-08-06 22:10:25 +02:00
|
|
|
#include "Partition.hxx"
|
|
|
|
#include "Instance.hxx"
|
2013-10-17 09:43:55 +02:00
|
|
|
|
2014-01-23 23:30:12 +01:00
|
|
|
static void
|
2017-02-24 13:56:13 +01:00
|
|
|
playlist_provider_print(Response &r,
|
2015-08-06 22:10:25 +02:00
|
|
|
const SongLoader &loader,
|
|
|
|
const char *uri,
|
2014-01-23 23:30:12 +01:00
|
|
|
SongEnumerator &e, bool detail)
|
2009-10-13 18:53:33 +02:00
|
|
|
{
|
2013-10-21 10:26:53 +02:00
|
|
|
const std::string base_uri = uri != nullptr
|
2013-12-04 22:53:43 +01:00
|
|
|
? PathTraitsUTF8::GetParent(uri)
|
2013-10-21 10:26:53 +02:00
|
|
|
: std::string(".");
|
2009-10-13 18:53:33 +02:00
|
|
|
|
2016-02-07 08:23:30 +01:00
|
|
|
std::unique_ptr<DetachedSong> song;
|
2014-01-23 23:30:12 +01:00
|
|
|
while ((song = e.NextSong()) != nullptr) {
|
|
|
|
if (playlist_check_translate_song(*song, base_uri.c_str(),
|
2014-12-09 13:36:48 +01:00
|
|
|
loader) &&
|
|
|
|
detail)
|
2017-02-24 13:56:13 +01:00
|
|
|
song_print_info(r, *song);
|
2014-12-09 13:36:48 +01:00
|
|
|
else
|
|
|
|
/* fallback if no detail was requested or no
|
|
|
|
detail was available */
|
2017-02-24 13:56:13 +01:00
|
|
|
song_print_uri(r, *song);
|
2009-10-13 18:53:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-23 23:30:12 +01:00
|
|
|
bool
|
2015-08-06 22:10:25 +02:00
|
|
|
playlist_file_print(Response &r, Partition &partition,
|
|
|
|
const SongLoader &loader,
|
|
|
|
const char *uri, bool detail)
|
2009-11-06 01:07:42 +01:00
|
|
|
{
|
2013-01-27 17:20:50 +01:00
|
|
|
Mutex mutex;
|
|
|
|
Cond cond;
|
2011-09-14 21:46:41 +02:00
|
|
|
|
2017-02-24 13:56:13 +01:00
|
|
|
#ifndef ENABLE_DATABASE
|
|
|
|
(void)partition;
|
|
|
|
#endif
|
|
|
|
|
2014-02-07 20:22:26 +01:00
|
|
|
SongEnumerator *playlist = playlist_open_any(uri,
|
|
|
|
#ifdef ENABLE_DATABASE
|
2015-08-06 22:10:25 +02:00
|
|
|
partition.instance.storage,
|
2014-02-07 20:22:26 +01:00
|
|
|
#endif
|
|
|
|
mutex, cond);
|
2013-10-02 08:13:28 +02:00
|
|
|
if (playlist == nullptr)
|
2014-01-23 23:30:12 +01:00
|
|
|
return false;
|
2010-06-01 09:10:58 +02:00
|
|
|
|
2017-02-24 13:56:13 +01:00
|
|
|
playlist_provider_print(r, loader, uri, *playlist, detail);
|
2013-09-05 09:37:54 +02:00
|
|
|
delete playlist;
|
2014-01-23 23:30:12 +01:00
|
|
|
return true;
|
2009-11-06 01:07:42 +01:00
|
|
|
}
|