Do not use exceptions when scan file error occurs
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
- handle access rights problems (instead of aborting)
|
- handle access rights problems (instead of aborting)
|
||||||
- add a global play counter for tracks. This will help people to spot most popular files
|
- add a global play counter for tracks. This will help people to spot most popular files
|
||||||
- rework the exception process in av/metadata/updater in case of bad files
|
- rework the exception process in av/metadata/updater in case of bad files
|
||||||
|
- Use the WServer::post method to notify the end of the database scan? (with results?)
|
||||||
|
|
||||||
[Metadata]
|
[Metadata]
|
||||||
- OGG metadata -> properly handle metadata nested in the audio stream
|
- OGG metadata -> properly handle metadata nested in the audio stream
|
||||||
|
|||||||
@@ -87,14 +87,17 @@ InputFormatContext::getBestStreamIdx(AVMediaType type, Stream::Idx& index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
InputFormatContext::findStreamInfo(void)
|
InputFormatContext::findStreamInfo(void)
|
||||||
{
|
{
|
||||||
AvError err = avformat_find_stream_info(native(), NULL);
|
AvError err = avformat_find_stream_info(native(), NULL);
|
||||||
if (err) {
|
if (err)
|
||||||
|
{
|
||||||
LMS_LOG(MOD_AV, SEV_ERROR) << "Couldn't find stream information: " << err;
|
LMS_LOG(MOD_AV, SEV_ERROR) << "Couldn't find stream information: " << err;
|
||||||
throw std::runtime_error("av_find_stream_info failed!");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class InputFormatContext : public FormatContext
|
|||||||
Dictionary getMetadata(void); // metadata access
|
Dictionary getMetadata(void); // metadata access
|
||||||
|
|
||||||
// Scan file
|
// Scan file
|
||||||
void findStreamInfo();
|
bool findStreamInfo();
|
||||||
|
|
||||||
|
|
||||||
// Get attached pictures
|
// Get attached pictures
|
||||||
|
|||||||
@@ -386,7 +386,9 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MetaData::Items items;
|
MetaData::Items items;
|
||||||
_metadataParser.parse(file, items);
|
|
||||||
|
if (!_metadataParser.parse(file, items))
|
||||||
|
return;
|
||||||
|
|
||||||
// We estimate this is a audio file if:
|
// We estimate this is a audio file if:
|
||||||
// - we found a least one audio stream
|
// - we found a least one audio stream
|
||||||
|
|||||||
@@ -32,14 +32,14 @@
|
|||||||
namespace MetaData
|
namespace MetaData
|
||||||
{
|
{
|
||||||
|
|
||||||
void
|
bool
|
||||||
AvFormat::parse(const boost::filesystem::path& p, Items& items)
|
AvFormat::parse(const boost::filesystem::path& p, Items& items)
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
Av::InputFormatContext input(p);
|
Av::InputFormatContext input(p);
|
||||||
input.findStreamInfo(); // needed by input.getDurationSecs
|
|
||||||
|
if (!input.findStreamInfo())
|
||||||
|
return false;
|
||||||
|
|
||||||
std::map<std::string, std::string> metadata;
|
std::map<std::string, std::string> metadata;
|
||||||
input.getMetadata().get(metadata);
|
input.getMetadata().get(metadata);
|
||||||
@@ -169,17 +169,9 @@ AvFormat::parse(const boost::filesystem::path& p, Items& items)
|
|||||||
{
|
{
|
||||||
items.insert( std::make_pair(MetaData::Type::MusicBrainzAlbumID, string_trim( string_to_utf8(it->second)) ));
|
items.insert( std::make_pair(MetaData::Type::MusicBrainzAlbumID, string_trim( string_to_utf8(it->second)) ));
|
||||||
}
|
}
|
||||||
/* else
|
|
||||||
LMS_LOG(MOD_METADATA, SEV_DEBUG) << "key = " << it->first << ", value = " << it->second;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
LMS_LOG(MOD_METADATA, SEV_ERROR) << "Parsing of '" << p << "' failed!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace MetaData
|
} // namespace MetaData
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class AvFormat : public Parser
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void parse(const boost::filesystem::path& p, Items& items);
|
bool parse(const boost::filesystem::path& p, Items& items);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace MetaData
|
|||||||
|
|
||||||
typedef std::shared_ptr<Parser> pointer;
|
typedef std::shared_ptr<Parser> pointer;
|
||||||
|
|
||||||
virtual void parse(const boost::filesystem::path& p, Items& items) = 0;
|
virtual bool parse(const boost::filesystem::path& p, Items& items) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
|
|
||||||
#include "logger/Logger.hpp"
|
#include "logger/Logger.hpp"
|
||||||
|
|
||||||
@@ -47,7 +46,9 @@ InputMediaFile::InputMediaFile(const boost::filesystem::path& p)
|
|||||||
: _path(p)
|
: _path(p)
|
||||||
{
|
{
|
||||||
Av::InputFormatContext input(_path);
|
Av::InputFormatContext input(_path);
|
||||||
input.findStreamInfo();
|
|
||||||
|
if (!input.findStreamInfo())
|
||||||
|
throw std::runtime_error("Cannot find stream info in file: " + p.string());
|
||||||
|
|
||||||
// Calculate estimated duration
|
// Calculate estimated duration
|
||||||
if (input.getDurationSecs())
|
if (input.getDurationSecs())
|
||||||
@@ -83,7 +84,7 @@ InputMediaFile::InputMediaFile(const boost::filesystem::path& p)
|
|||||||
|
|
||||||
avMediaTypes.unique();
|
avMediaTypes.unique();
|
||||||
// Scan for best streams
|
// Scan for best streams
|
||||||
BOOST_FOREACH(enum AVMediaType type, avMediaTypes)
|
for (enum AVMediaType type : avMediaTypes)
|
||||||
{
|
{
|
||||||
Av::Stream::Idx index;
|
Av::Stream::Idx index;
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ std::vector<Stream>
|
|||||||
InputMediaFile::getStreams(Stream::Type type) const
|
InputMediaFile::getStreams(Stream::Type type) const
|
||||||
{
|
{
|
||||||
std::vector<Stream> res;
|
std::vector<Stream> res;
|
||||||
BOOST_FOREACH(const Stream& stream, _streams)
|
for (const Stream& stream : _streams)
|
||||||
{
|
{
|
||||||
if (stream.getType() == type)
|
if (stream.getType() == type)
|
||||||
res.push_back(stream);
|
res.push_back(stream);
|
||||||
@@ -113,7 +114,7 @@ InputMediaFile::getStreams(Stream::Type type) const
|
|||||||
const Stream&
|
const Stream&
|
||||||
InputMediaFile::getStream(Stream::Id index) const
|
InputMediaFile::getStream(Stream::Id index) const
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const Stream& stream, _streams)
|
for (const Stream& stream : _streams)
|
||||||
{
|
{
|
||||||
if (stream.getId() == index)
|
if (stream.getId() == index)
|
||||||
return stream;
|
return stream;
|
||||||
|
|||||||
Reference in New Issue
Block a user