2010-02-08 10:28:12 +01:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2010-02-08 10:28:12 +01: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2013-01-02 18:38:32 +01:00
|
|
|
#include "PlaylistSong.hxx"
|
2014-02-02 14:37:52 +01:00
|
|
|
#include "SongLoader.hxx"
|
2013-09-05 18:22:02 +02:00
|
|
|
#include "tag/Tag.hxx"
|
2017-02-08 08:26:58 +01:00
|
|
|
#include "tag/Builder.hxx"
|
2013-10-17 23:23:25 +02:00
|
|
|
#include "fs/Traits.hxx"
|
2013-04-08 23:30:21 +02:00
|
|
|
#include "util/UriUtil.hxx"
|
2014-01-07 21:39:47 +01:00
|
|
|
#include "DetachedSong.hxx"
|
2010-02-08 10:28:12 +01:00
|
|
|
|
2016-04-12 21:09:53 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2010-02-08 10:28:12 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static void
|
2014-01-20 23:48:46 +01:00
|
|
|
merge_song_metadata(DetachedSong &add, const DetachedSong &base)
|
2010-02-08 10:28:12 +01:00
|
|
|
{
|
2014-07-12 19:41:04 +02:00
|
|
|
if (base.GetTag().IsDefined()) {
|
2014-01-20 19:50:19 +01:00
|
|
|
TagBuilder builder(add.GetTag());
|
|
|
|
builder.Complement(base.GetTag());
|
2014-01-20 23:48:46 +01:00
|
|
|
add.SetTag(builder.Commit());
|
2014-01-07 21:39:47 +01:00
|
|
|
}
|
|
|
|
|
2014-01-20 23:48:46 +01:00
|
|
|
add.SetLastModified(base.GetLastModified());
|
2010-02-08 10:28:12 +01:00
|
|
|
}
|
|
|
|
|
2014-01-20 23:48:46 +01:00
|
|
|
static bool
|
2014-02-02 14:37:52 +01:00
|
|
|
playlist_check_load_song(DetachedSong &song, const SongLoader &loader)
|
2017-02-08 10:02:08 +01:00
|
|
|
try {
|
|
|
|
DetachedSong tmp = loader.LoadSong(song.GetURI());
|
2014-02-02 14:37:52 +01:00
|
|
|
|
2017-02-08 10:02:08 +01:00
|
|
|
song.SetURI(tmp.GetURI());
|
|
|
|
if (!song.HasRealURI() && tmp.HasRealURI())
|
|
|
|
song.SetRealURI(tmp.GetRealURI());
|
2014-02-10 11:00:49 +01:00
|
|
|
|
2017-02-08 10:02:08 +01:00
|
|
|
merge_song_metadata(song, tmp);
|
2014-02-02 14:37:52 +01:00
|
|
|
return true;
|
2017-02-08 10:02:08 +01:00
|
|
|
} catch (const std::runtime_error &) {
|
|
|
|
return false;
|
2012-08-14 02:17:20 +02:00
|
|
|
}
|
|
|
|
|
2014-01-20 23:48:46 +01:00
|
|
|
bool
|
|
|
|
playlist_check_translate_song(DetachedSong &song, const char *base_uri,
|
2014-02-02 14:37:52 +01:00
|
|
|
const SongLoader &loader)
|
2010-02-08 10:28:12 +01:00
|
|
|
{
|
2013-10-02 08:13:28 +02:00
|
|
|
if (base_uri != nullptr && strcmp(base_uri, ".") == 0)
|
2013-12-04 22:53:43 +01:00
|
|
|
/* PathTraitsUTF8::GetParent() returns "." when there
|
2013-10-21 10:26:53 +02:00
|
|
|
is no directory name in the given path; clear that
|
|
|
|
now, because it would break the database lookup
|
2011-05-09 18:00:41 +02:00
|
|
|
functions */
|
2013-10-02 08:13:28 +02:00
|
|
|
base_uri = nullptr;
|
2011-05-09 18:00:41 +02:00
|
|
|
|
2014-02-02 14:37:52 +01:00
|
|
|
const char *uri = song.GetURI();
|
|
|
|
if (base_uri != nullptr && !uri_has_scheme(uri) &&
|
|
|
|
!PathTraitsUTF8::IsAbsolute(uri))
|
2014-01-20 23:48:46 +01:00
|
|
|
song.SetURI(PathTraitsUTF8::Build(base_uri, uri));
|
2010-02-08 10:28:12 +01:00
|
|
|
|
2014-02-02 14:37:52 +01:00
|
|
|
return playlist_check_load_song(song, loader);
|
2010-02-08 10:28:12 +01:00
|
|
|
}
|