TagFile: allow ScanFileTags*() to throw

This commit is contained in:
Max Kellermann 2019-05-21 23:24:44 +02:00
parent 6f1d5105ee
commit 92f7421715
2 changed files with 12 additions and 15 deletions

View File

@ -51,36 +51,29 @@ public:
return plugin.ScanFile(path_fs, handler); return plugin.ScanFile(path_fs, handler);
} }
bool ScanStream(const DecoderPlugin &plugin) noexcept { bool ScanStream(const DecoderPlugin &plugin) {
if (plugin.scan_stream == nullptr) if (plugin.scan_stream == nullptr)
return false; return false;
/* open the InputStream (if not already open) */ /* open the InputStream (if not already open) */
if (is == nullptr) { if (is == nullptr) {
try { is = OpenLocalInputStream(path_fs, mutex);
is = OpenLocalInputStream(path_fs, mutex);
} catch (...) {
return false;
}
} else { } else {
try { is->LockRewind();
is->LockRewind();
} catch (...) {
}
} }
/* now try the stream_tag() method */ /* now try the stream_tag() method */
return plugin.ScanStream(*is, handler); return plugin.ScanStream(*is, handler);
} }
bool Scan(const DecoderPlugin &plugin) noexcept { bool Scan(const DecoderPlugin &plugin) {
return plugin.SupportsSuffix(suffix) && return plugin.SupportsSuffix(suffix) &&
(ScanFile(plugin) || ScanStream(plugin)); (ScanFile(plugin) || ScanStream(plugin));
} }
}; };
bool bool
ScanFileTagsNoGeneric(Path path_fs, TagHandler &handler) noexcept ScanFileTagsNoGeneric(Path path_fs, TagHandler &handler)
{ {
assert(!path_fs.IsNull()); assert(!path_fs.IsNull());
@ -100,7 +93,7 @@ ScanFileTagsNoGeneric(Path path_fs, TagHandler &handler) noexcept
bool bool
ScanFileTagsWithGeneric(Path path, TagBuilder &builder, ScanFileTagsWithGeneric(Path path, TagBuilder &builder,
AudioFormat *audio_format) noexcept AudioFormat *audio_format)
{ {
FullTagHandler h(builder, audio_format); FullTagHandler h(builder, audio_format);

View File

@ -30,22 +30,26 @@ class TagBuilder;
* but does not fall back to generic scanners (APE and ID3) if no tags * but does not fall back to generic scanners (APE and ID3) if no tags
* were found (but the file was recognized). * were found (but the file was recognized).
* *
* Throws on error.
*
* @return true if the file was recognized (even if no metadata was * @return true if the file was recognized (even if no metadata was
* found) * found)
*/ */
bool bool
ScanFileTagsNoGeneric(Path path, TagHandler &handler) noexcept; ScanFileTagsNoGeneric(Path path, TagHandler &handler);
/** /**
* Scan the tags of a song file. Invokes matching decoder plugins, * Scan the tags of a song file. Invokes matching decoder plugins,
* and falls back to generic scanners (APE and ID3) if no tags were * and falls back to generic scanners (APE and ID3) if no tags were
* found (but the file was recognized). * found (but the file was recognized).
* *
* Throws on error.
*
* @return true if the file was recognized (even if no metadata was * @return true if the file was recognized (even if no metadata was
* found) * found)
*/ */
bool bool
ScanFileTagsWithGeneric(Path path, TagBuilder &builder, ScanFileTagsWithGeneric(Path path, TagBuilder &builder,
AudioFormat *audio_format=nullptr) noexcept; AudioFormat *audio_format=nullptr);
#endif #endif