Song.cxx 1.7 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2020 The Music Player Daemon Project
3
 * http://www.musicpd.org
Warren Dukes's avatar
Warren Dukes committed
4 5 6 7 8 9 10 11 12 13
 *
 * 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.
14 15 16 17
 *
 * 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.
Warren Dukes's avatar
Warren Dukes committed
18 19
 */

20
#include "Song.hxx"
21
#include "Directory.hxx"
22
#include "tag/Tag.hxx"
23 24
#include "song/DetachedSong.hxx"
#include "song/LightSong.hxx"
25
#include "fs/Traits.hxx"
26

27 28 29 30 31 32
Song::Song(DetachedSong &&other, Directory &_parent) noexcept
	:tag(std::move(other.WritableTag())),
	 parent(_parent),
	 mtime(other.GetLastModified()),
	 start_time(other.GetStartTime()),
	 end_time(other.GetEndTime()),
33
	 filename(other.GetURI())
34
{
35 36
}

37
std::string
38
Song::GetURI() const noexcept
Avuton Olrich's avatar
Avuton Olrich committed
39
{
40
	if (parent.IsRoot())
41
		return filename;
42
	else {
43
		const char *path = parent.GetPath();
44
		return PathTraitsUTF8::Build(path, filename.c_str());
45
	}
46
}
47

48
LightSong
49
Song::Export() const noexcept
50
{
51
	LightSong dest(filename.c_str(), tag);
52 53
	if (!parent.IsRoot())
		dest.directory = parent.GetPath();
54 55
	if (!target.empty())
		dest.real_uri = target.c_str();
56
	dest.mtime = mtime;
57 58
	dest.start_time = start_time;
	dest.end_time = end_time;
59
	dest.audio_format = audio_format;
60
	return dest;
61
}