Commit bf404e3a authored by Urs Fleisch's avatar Urs Fleisch
Browse files

Fixed bug in gnudb.org import: non-ascii characters were not imported...

Fixed bug in gnudb.org import: non-ascii characters were not imported correctly because UTF-8 encoding was assumed but ISO-8859-1 encoding received. Now check charset in HTML header and use CDDB Protocol Level 6.
parent 6bed6d3e
......@@ -121,7 +121,7 @@ void FreedbClient::constructTrackListQuery(
m_request += "+";
m_request += id;
m_request += "&hello=noname+localhost+";
m_request += "Kid3+" VERSION "&proto=1 HTTP/1.1\r\nHost: ";
m_request += "Kid3+" VERSION "&proto=6 HTTP/1.1\r\nHost: ";
m_request += serverName;
m_request += "\r\nConnection: close\r\n\r\n";
}
......@@ -30,6 +30,9 @@
#include "freedbdialog.h"
#include "genres.h"
#include "importparser.h"
#if QT_VERSION < 0x040000
#include <cstring>
#endif
static const char* serverList[] = {
"www.gnudb.org:80",
......@@ -109,7 +112,25 @@ void FreedbDialog::parseFindResults(const QByteArray& searchStr)
Tracks: 12, total time: 49:07, year: 2002, genre: Metal<br>
<a href="http://www.gnudb.org/gnudb/rock/920b810c" target=_blank>Discid: rock / 920b810c</a><br>
*/
QString str = QString::fromUtf8(searchStr);
bool isUtf8 = false;
#if QT_VERSION >= 0x040000
int charSetPos = searchStr.indexOf("charset=");
if (charSetPos != -1) {
charSetPos += 8;
QByteArray charset(searchStr.mid(charSetPos, 5));
isUtf8 = charset == "utf-8" || charset == "UTF-8";
}
#else
const char* searchStrData = searchStr.data();
char* charSetPtr = std::strstr(searchStrData, "charset=");
if (charSetPtr) {
charSetPtr += 8;
isUtf8 = std::strncmp(charSetPtr, "utf-8", 5) == 0 ||
std::strncmp(charSetPtr, "UTF-8", 5) == 0;
}
#endif
QString str = isUtf8 ? QString::fromUtf8(searchStr) :
QString::fromLatin1(searchStr);
QRegExp titleRe("<a href=\"[^\"]+/cd/[^\"]+\"><b>([^<]+)</b></a>");
QRegExp catIdRe("Discid: ([a-z]+)[\\s/]+([0-9a-f]+)");
QStringList lines = QCM_split(QRegExp("[\\r\\n]+"), str);
......
......@@ -84,7 +84,7 @@ void TrackTypeClient::constructFindQuery(
m_request += "?cmd=cddb+album+";
m_request += what;
m_request += "&hello=noname+localhost+";
m_request += "Kid3+" VERSION "&proto=1 HTTP/1.1\r\nHost: ";
m_request += "Kid3+" VERSION "&proto=6 HTTP/1.1\r\nHost: ";
m_request += serverName;
m_request += "\r\nConnection: close\r\n\r\n";
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment