WIP. Convert to UTF-8 before DB inserts
This commit is contained in:
@@ -240,6 +240,7 @@ Database::refreshAudioDirectory( const boost::filesystem::path& p)
|
|||||||
|
|
||||||
BOOST_FOREACH(const boost::filesystem::path& file, files) {
|
BOOST_FOREACH(const boost::filesystem::path& file, files) {
|
||||||
|
|
||||||
|
try {
|
||||||
if (boost::filesystem::is_directory(file)) {
|
if (boost::filesystem::is_directory(file)) {
|
||||||
refreshAudioDirectory( file );
|
refreshAudioDirectory( file );
|
||||||
}
|
}
|
||||||
@@ -250,6 +251,10 @@ Database::refreshAudioDirectory( const boost::filesystem::path& p)
|
|||||||
std::cout << "Skipped '" << file << "' (not regular)" << std::endl;
|
std::cout << "Skipped '" << file << "' (not regular)" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(std::exception& e) {
|
||||||
|
std::cerr << "Exception while accessing '" << file << ": " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::cout << "Refreshing audio directory " << p << ": DONE" << std::endl;
|
std::cout << "Refreshing audio directory " << p << ": DONE" << 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() )) ));
|
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;
|
std::map<std::string, std::string>::const_iterator it;
|
||||||
for (it = metadata.begin(); it != metadata.end(); ++it)
|
for (it = metadata.begin(); it != metadata.end(); ++it)
|
||||||
{
|
{
|
||||||
if (boost::iequals(it->first, "artist"))
|
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"))
|
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"))
|
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")) {
|
else if (boost::iequals(it->first, "track")) {
|
||||||
std::size_t number;
|
std::size_t number;
|
||||||
if (readAs<std::size_t>(it->second, number))
|
if (readAs<std::size_t>(it->second, number))
|
||||||
|
|||||||
+4
-2
@@ -40,9 +40,11 @@ bool readList(const std::string& str, const std::string& separators, std::list<s
|
|||||||
BOOST_FOREACH(char c, str) {
|
BOOST_FOREACH(char c, str) {
|
||||||
|
|
||||||
if (separators.find(c) != std::string::npos) {
|
if (separators.find(c) != std::string::npos) {
|
||||||
results.push_back(curStr);
|
if (!curStr.empty()) {
|
||||||
|
results.push_back(string_to_utf8(curStr));
|
||||||
curStr.clear();
|
curStr.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if (curStr.empty() && std::isspace(c))
|
if (curStr.empty() && std::isspace(c))
|
||||||
continue;
|
continue;
|
||||||
@@ -52,7 +54,7 @@ bool readList(const std::string& str, const std::string& separators, std::list<s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!curStr.empty())
|
if (!curStr.empty())
|
||||||
results.push_back(curStr);
|
results.push_back(string_to_utf8(curStr));
|
||||||
|
|
||||||
return !str.empty();
|
return !str.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
#include <boost/locale.hpp>
|
||||||
|
|
||||||
namespace MetaData
|
namespace MetaData
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -18,7 +20,13 @@ static inline bool readAs(const std::string& str, T& data)
|
|||||||
return iss >> 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
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user