2009-10-13 18:53:33 +02:00
|
|
|
/*
|
2019-06-17 11:17:30 +02:00
|
|
|
* Copyright 2003-2019 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"
|
2019-02-13 21:55:15 +01:00
|
|
|
#include "LocateUri.hxx"
|
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"
|
2018-08-02 13:45:43 +02:00
|
|
|
#include "song/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"
|
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,
|
2018-01-21 11:29:27 +01:00
|
|
|
SongEnumerator &e, bool detail) noexcept
|
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,
|
2019-02-13 21:55:15 +01:00
|
|
|
const LocatedUri &uri, bool detail)
|
2009-11-06 01:07:42 +01:00
|
|
|
{
|
2013-01-27 17:20:50 +01:00
|
|
|
Mutex mutex;
|
2011-09-14 21:46:41 +02:00
|
|
|
|
2017-02-24 13:56:13 +01:00
|
|
|
#ifndef ENABLE_DATABASE
|
|
|
|
(void)partition;
|
|
|
|
#endif
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
auto playlist = playlist_open_any(uri,
|
2014-02-07 20:22:26 +01:00
|
|
|
#ifdef ENABLE_DATABASE
|
2018-01-20 19:56:44 +01:00
|
|
|
partition.instance.storage,
|
2014-02-07 20:22:26 +01:00
|
|
|
#endif
|
2018-06-22 19:37:18 +02:00
|
|
|
mutex);
|
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
|
|
|
|
2019-02-13 21:55:15 +01:00
|
|
|
playlist_provider_print(r, loader, uri.canonical_uri, *playlist, detail);
|
2014-01-23 23:30:12 +01:00
|
|
|
return true;
|
2009-11-06 01:07:42 +01:00
|
|
|
}
|