Generic.cxx 1.52 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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 "Generic.hxx"
21
#include "Id3Scan.hxx"
22 23
#include "ApeTag.hxx"
#include "fs/Path.hxx"
24
#include "thread/Mutex.hxx"
25
#include "input/InputStream.hxx"
26 27
#include "input/LocalOpen.hxx"
#include "Log.hxx"
28
#include "config.h"
29

30
#include <exception>
31

32
bool
33
ScanGenericTags(InputStream &is, TagHandler &handler) noexcept
34
{
35
	if (tag_ape_scan2(is, handler))
36 37
		return true;

38
#ifdef ENABLE_ID3TAG
39 40
	try {
		is.LockRewind();
41
	} catch (...) {
42
		return false;
43
	}
44

45
	return tag_id3_scan(is, handler);
46 47 48
#else
	return false;
#endif
49
}
50 51

bool
52
ScanGenericTags(Path path, TagHandler &handler) noexcept
53 54 55
try {
	Mutex mutex;

56
	auto is = OpenLocalInputStream(path, mutex);
57
	return ScanGenericTags(*is, handler);
58 59
} catch (...) {
	LogError(std::current_exception());
60
	return false;
61
}