2
* Copyright (C) 2003-2011 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.
20
#include "config.h" /* must be first for large file support */
23
#include "directory.h"
25
#include "decoder_list.h"
26
#include "decoder_plugin.h"
30
#include "tag_handler.h"
31
#include "input_stream.h"
36
#include <sys/types.h>
41
song_file_load(const char *path, struct directory *parent)
46
assert((parent == NULL) == g_path_is_absolute(path));
47
assert(!uri_has_scheme(path));
48
assert(strchr(path, '\n') == NULL);
50
song = song_file_new(path, parent);
53
if (parent != NULL && parent->device == DEVICE_INARCHIVE) {
54
ret = song_file_update_inarchive(song);
56
ret = song_file_update(song);
67
* Attempts to load APE or ID3 tags from the specified file.
70
tag_scan_fallback(const char *path,
71
const struct tag_handler *handler, void *handler_ctx)
73
return tag_ape_scan2(path, handler, handler_ctx) ||
74
tag_id3_scan(path, handler, handler_ctx);
78
song_file_update(struct song *song)
82
const struct decoder_plugin *plugin;
84
struct input_stream *is = NULL;
86
assert(song_is_file(song));
88
/* check if there's a suffix and a plugin */
90
suffix = uri_get_suffix(song->uri);
94
plugin = decoder_plugin_from_suffix(suffix, NULL);
98
path_fs = map_song_fs(song);
102
if (song->tag != NULL) {
107
if (stat(path_fs, &st) < 0 || !S_ISREG(st.st_mode)) {
112
song->mtime = st.st_mtime;
114
GMutex *mutex = NULL;
116
#if !GCC_CHECK_VERSION(4, 2)
117
/* work around "may be used uninitialized in this function"
124
song->tag = tag_new();
125
if (decoder_plugin_scan_file(plugin, path_fs,
126
&full_tag_handler, song->tag))
132
/* fall back to stream tag */
133
if (plugin->scan_stream != NULL) {
134
/* open the input_stream (if not already
137
mutex = g_mutex_new();
139
is = input_stream_open(path_fs, mutex, cond,
143
/* now try the stream_tag() method */
145
song->tag = tag_new();
146
if (decoder_plugin_scan_stream(plugin, is,
154
input_stream_lock_seek(is, 0, SEEK_SET, NULL);
158
plugin = decoder_plugin_from_suffix(suffix, plugin);
159
} while (plugin != NULL);
162
input_stream_close(is);
169
if (song->tag != NULL && tag_is_empty(song->tag))
170
tag_scan_fallback(path_fs, &full_tag_handler, song->tag);
173
return song->tag != NULL;
177
song_file_update_inarchive(struct song *song)
180
const struct decoder_plugin *plugin;
182
assert(song_is_file(song));
184
/* check if there's a suffix and a plugin */
186
suffix = uri_get_suffix(song->uri);
190
plugin = decoder_plugin_from_suffix(suffix, false);
194
if (song->tag != NULL)
197
//accept every file that has music suffix
198
//because we don't support tag reading through
200
song->tag = tag_new();