From 545b9b49678263eca722c911c73c45a074d891e9 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Fri, 9 Dec 2011 00:34:07 +0100 Subject: [PATCH] Improved handling of different character encodings for M3U(8) and PLS playlist import. --- doc/Changelog.html | 1 + src/Config.h | 2 +- src/PlaylistImporter.cpp | 93 ++++++++++++++++++++-------------------- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/doc/Changelog.html b/doc/Changelog.html index 627750ea..fcd78011 100644 --- a/doc/Changelog.html +++ b/doc/Changelog.html @@ -22,6 +22,7 @@ a:visited { color: #0000EE; }
  • Updated MediaInfo to v0.7.51+ (2011-11-19), compiled with ICL 12.1.6 and MSVC 10.0
  • Implemented coalescing of update signals to reduce the CPU usage of the LameXP process (details)
  • Run more than four instances in parallel on systems with more than four CPU cores (details) +
  • Improved handling of different character encodings for Playlist and Cue Sheet import
  • Workaround for a bug that causes MediaInfo to not detect the duration of Wave files (64-Bit only)
    diff --git a/src/Config.h b/src/Config.h index d80df787..444465b4 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 4 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 7 -#define VER_LAMEXP_BUILD 802 +#define VER_LAMEXP_BUILD 803 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/PlaylistImporter.cpp b/src/PlaylistImporter.cpp index 359f6638..9b58405d 100644 --- a/src/PlaylistImporter.cpp +++ b/src/PlaylistImporter.cpp @@ -132,32 +132,40 @@ PlaylistImporter::playlist_t PlaylistImporter::isPlaylist(const QString &fileNam bool PlaylistImporter::parsePlaylist_m3u(QFile &data, QStringList &fileList, const QDir &baseDir, const QDir &rootDir) { QByteArray line = data.readLine(); - + const bool preferUTF8 = data.fileName().endsWith(".m3u8", Qt::CaseInsensitive); + while(line.size() > 0) { - QFileInfo filename1(QDir::fromNativeSeparators(QString::fromUtf8(line.constData(), line.size()).trimmed())); - QFileInfo filename2(QDir::fromNativeSeparators(QString::fromLatin1(line.constData(), line.size()).trimmed())); + QString filePath[3]; - filename1.setCaching(false); - filename2.setCaching(false); - - if(!(filename1.filePath().startsWith("#") || filename2.filePath().startsWith("#"))) + if(preferUTF8) { - fixFilePath(filename1, baseDir, rootDir); - fixFilePath(filename2, baseDir, rootDir); + filePath[0] = QString(QDir::fromNativeSeparators(QString::fromUtf8(line.constData(), line.size()).trimmed())); + filePath[1] = QString(QDir::fromNativeSeparators(QString::fromLocal8Bit(line.constData(), line.size()).trimmed())); + filePath[2] = QString(QDir::fromNativeSeparators(QString::fromLatin1(line.constData(), line.size()).trimmed())); + } + else + { + filePath[0] = QString(QDir::fromNativeSeparators(QString::fromLocal8Bit(line.constData(), line.size()).trimmed())); + filePath[1] = QString(QDir::fromNativeSeparators(QString::fromLatin1(line.constData(), line.size()).trimmed())); + filePath[2] = QString(QDir::fromNativeSeparators(QString::fromUtf8(line.constData(), line.size()).trimmed())); + } - if(filename1.exists()) + for(size_t i = 0; i < 3; i++) + { + if(!(filePath[i].startsWith("#") || filePath[i].contains(QChar(QChar::ReplacementCharacter)))) { - if(isPlaylist(filename1.canonicalFilePath()) == notPlaylist) + QFileInfo filename(filePath[i]); + filename.setCaching(false); + fixFilePath(filename, baseDir, rootDir); + + if(filename.exists()) { - fileList << filename1.canonicalFilePath(); - } - } - else if(filename2.exists()) - { - if(isPlaylist(filename2.canonicalFilePath()) == notPlaylist) - { - fileList << filename2.canonicalFilePath(); + if(isPlaylist(filename.canonicalFilePath()) == notPlaylist) + { + fileList << filename.canonicalFilePath(); + } + break; } } } @@ -175,40 +183,31 @@ bool PlaylistImporter::parsePlaylist_pls(QFile &data, QStringList &fileList, con while(line.size() > 0) { - bool flag = false; - - QString temp1(QDir::fromNativeSeparators(QString::fromUtf8(line.constData(), line.size()).trimmed())); - QString temp2(QDir::fromNativeSeparators(QString::fromLatin1(line.constData(), line.size()).trimmed())); + QString filePath[3]; - if(!flag && plsEntry.indexIn(temp1) >= 0) + filePath[0] = QString(QDir::fromNativeSeparators(QString::fromLocal8Bit(line.constData(), line.size()).trimmed())); + filePath[2] = QString(QDir::fromNativeSeparators(QString::fromLatin1(line.constData(), line.size()).trimmed())); + filePath[1] = QString(QDir::fromNativeSeparators(QString::fromUtf8(line.constData(), line.size()).trimmed())); + + for(size_t i = 0; i < 3; i++) { - QFileInfo filename(QDir::fromNativeSeparators(plsEntry.cap(2)).trimmed()); - filename.setCaching(false); - fixFilePath(filename, baseDir, rootDir); - - if(filename.exists()) + if(!filePath[i].contains(QChar(QChar::ReplacementCharacter))) { - if(isPlaylist(filename.canonicalFilePath()) == notPlaylist) + if(plsEntry.indexIn(filePath[i]) >= 0) { - fileList << filename.canonicalFilePath(); - } - flag = true; - } - } - - if(!flag && plsEntry.indexIn(temp2) >= 0) - { - QFileInfo filename(QDir::fromNativeSeparators(plsEntry.cap(2)).trimmed()); - filename.setCaching(false); - fixFilePath(filename, baseDir, rootDir); + QFileInfo filename(QDir::fromNativeSeparators(plsEntry.cap(2)).trimmed()); + filename.setCaching(false); + fixFilePath(filename, baseDir, rootDir); - if(filename.exists()) - { - if(isPlaylist(filename.canonicalFilePath()) == notPlaylist) - { - fileList << filename.canonicalFilePath(); + if(filename.exists()) + { + if(isPlaylist(filename.canonicalFilePath()) == notPlaylist) + { + fileList << filename.canonicalFilePath(); + } + break; + } } - flag = true; } }