2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "playlist_song.h"
33 merge_song_metadata(struct song
*dest
, const struct song
*base
,
34 const struct song
*add
)
36 dest
->tag
= base
->tag
!= NULL
38 ? tag_merge(base
->tag
, add
->tag
)
44 dest
->mtime
= base
->mtime
;
45 dest
->start_ms
= add
->start_ms
;
46 dest
->end_ms
= add
->end_ms
;
50 apply_song_metadata(struct song
*dest
, const struct song
*src
)
57 if (src
->tag
== NULL
&& src
->start_ms
== 0 && src
->end_ms
== 0)
60 if (song_in_database(dest
)) {
61 char *path_fs
= map_song_fs(dest
);
65 tmp
= song_file_new(path_fs
, NULL
);
66 merge_song_metadata(tmp
, dest
, src
);
68 tmp
= song_file_new(dest
->uri
, NULL
);
69 merge_song_metadata(tmp
, dest
, src
);
77 playlist_check_translate_song(struct song
*song
, const char *base_uri
)
81 if (song_in_database(song
))
85 char *uri
= song
->uri
;
87 if (uri_has_scheme(uri
)) {
88 if (uri_supported_scheme(uri
))
89 /* valid remote song */
92 /* unsupported remote song */
98 if (g_path_is_absolute(uri
)) {
99 /* XXX fs_charset vs utf8? */
100 char *prefix
= base_uri
!= NULL
101 ? map_uri_fs(base_uri
)
102 : map_directory_fs(db_get_root());
104 if (prefix
== NULL
|| !g_str_has_prefix(uri
, prefix
) ||
105 uri
[strlen(prefix
)] != '/') {
106 /* local files must be relative to the music
113 uri
+= strlen(prefix
) + 1;
117 if (base_uri
!= NULL
)
118 uri
= g_build_filename(base_uri
, uri
, NULL
);
122 if (uri_has_scheme(base_uri
)) {
123 dest
= song_remote_new(uri
);
126 dest
= db_get_song(uri
);
129 /* not found in database */
135 dest
= apply_song_metadata(dest
, song
);