WIP. Convert to UTF-8 before DB inserts
This commit is contained in:
+12
-7
@@ -240,14 +240,19 @@ Database::refreshAudioDirectory( const boost::filesystem::path& p)
|
||||
|
||||
BOOST_FOREACH(const boost::filesystem::path& file, files) {
|
||||
|
||||
if (boost::filesystem::is_directory(file)) {
|
||||
refreshAudioDirectory( file );
|
||||
try {
|
||||
if (boost::filesystem::is_directory(file)) {
|
||||
refreshAudioDirectory( file );
|
||||
}
|
||||
else if (boost::filesystem::is_regular(file)) {
|
||||
processAudioFile( file );
|
||||
}
|
||||
else {
|
||||
std::cout << "Skipped '" << file << "' (not regular)" << std::endl;
|
||||
}
|
||||
}
|
||||
else if (boost::filesystem::is_regular(file)) {
|
||||
processAudioFile( file );
|
||||
}
|
||||
else {
|
||||
std::cout << "Skipped '" << file << "' (not regular)" << std::endl;
|
||||
catch(std::exception& e) {
|
||||
std::cerr << "Exception while accessing '" << file << ": " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,15 +44,16 @@ AvFormat::parse(const boost::filesystem::path& p, Items& items)
|
||||
|
||||
items.insert( std::make_pair(MetaData::Duration, boost::posix_time::time_duration( boost::posix_time::seconds( input.getDurationSecs() )) ));
|
||||
|
||||
// Make sure to convert strings into UTF-8
|
||||
std::map<std::string, std::string>::const_iterator it;
|
||||
for (it = metadata.begin(); it != metadata.end(); ++it)
|
||||
{
|
||||
if (boost::iequals(it->first, "artist"))
|
||||
items.insert( std::make_pair(MetaData::Artist, it->second ));
|
||||
items.insert( std::make_pair(MetaData::Artist, string_to_utf8(it->second)) );
|
||||
else if (boost::iequals(it->first, "album"))
|
||||
items.insert( std::make_pair(MetaData::Album, it->second ));
|
||||
items.insert( std::make_pair(MetaData::Album, string_to_utf8(it->second) ));
|
||||
else if (boost::iequals(it->first, "title"))
|
||||
items.insert( std::make_pair(MetaData::Title, it->second ));
|
||||
items.insert( std::make_pair(MetaData::Title, string_to_utf8(it->second) ));
|
||||
else if (boost::iequals(it->first, "track")) {
|
||||
std::size_t number;
|
||||
if (readAs<std::size_t>(it->second, number))
|
||||
|
||||
+5
-3
@@ -40,8 +40,10 @@ bool readList(const std::string& str, const std::string& separators, std::list<s
|
||||
BOOST_FOREACH(char c, str) {
|
||||
|
||||
if (separators.find(c) != std::string::npos) {
|
||||
results.push_back(curStr);
|
||||
curStr.clear();
|
||||
if (!curStr.empty()) {
|
||||
results.push_back(string_to_utf8(curStr));
|
||||
curStr.clear();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (curStr.empty() && std::isspace(c))
|
||||
@@ -52,7 +54,7 @@ bool readList(const std::string& str, const std::string& separators, std::list<s
|
||||
}
|
||||
|
||||
if (!curStr.empty())
|
||||
results.push_back(curStr);
|
||||
results.push_back(string_to_utf8(curStr));
|
||||
|
||||
return !str.empty();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include <boost/locale.hpp>
|
||||
|
||||
namespace MetaData
|
||||
{
|
||||
|
||||
@@ -18,7 +20,13 @@ static inline bool readAs(const std::string& str, T& data)
|
||||
return iss >> data;
|
||||
}
|
||||
|
||||
std::string
|
||||
static inline string_to_utf8(const std::string& str)
|
||||
{
|
||||
return boost::locale::conv::to_utf<char>(str, "UTF-8");
|
||||
}
|
||||
|
||||
} // namespace MetaData
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user