From 51d8ea12bd2ba4a1580baa0c38b975f65132c7bc Mon Sep 17 00:00:00 2001 From: Fatih Emre YILDIZ Date: Wed, 11 May 2022 01:55:27 +0300 Subject: [PATCH 1/6] parserm3u: url location add for missing characters --- src/library/parserm3u.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/library/parserm3u.cpp b/src/library/parserm3u.cpp index 336b9a12550..e54a608a887 100644 --- a/src/library/parserm3u.cpp +++ b/src/library/parserm3u.cpp @@ -107,10 +107,12 @@ bool ParserM3u::writeM3UFile(const QString &file_str, const QList &item QString fileContents(QStringLiteral("#EXTM3U\n")); for (const QString& item : items) { fileContents += QStringLiteral("#EXTINF\n"); + QUrl itemUrl = QUrl::fromLocalFile(item); + QString itemUrlEncoded = itemUrl.toEncoded(); if (useRelativePath) { fileContents += baseDirectory.relativeFilePath(item) + QStringLiteral("\n"); } else { - fileContents += item + QStringLiteral("\n"); + fileContents += itemUrlEncoded + QStringLiteral("\n"); } } From 380d672e12edfcc4daac09b4377982e18a725757 Mon Sep 17 00:00:00 2001 From: Fatih Emre YILDIZ Date: Wed, 11 May 2022 02:14:56 +0300 Subject: [PATCH 2/6] parserm3u: fix to m3u8 export url location --- src/library/parserm3u.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/library/parserm3u.cpp b/src/library/parserm3u.cpp index e54a608a887..36ecc326630 100644 --- a/src/library/parserm3u.cpp +++ b/src/library/parserm3u.cpp @@ -112,7 +112,11 @@ bool ParserM3u::writeM3UFile(const QString &file_str, const QList &item if (useRelativePath) { fileContents += baseDirectory.relativeFilePath(item) + QStringLiteral("\n"); } else { - fileContents += itemUrlEncoded + QStringLiteral("\n"); + if (!useUtf8) { + fileContents += itemUrlEncoded + QStringLiteral("\n"); + } else { + fileContents += item + QStringLiteral("\n"); + } } } From 378124d600d20ed017a3ca34095d1676291e3cd5 Mon Sep 17 00:00:00 2001 From: Fatih Emre YILDIZ Date: Thu, 12 May 2022 23:16:12 +0300 Subject: [PATCH 3/6] parserm3u: fix url encoding add to missing tracks --- src/library/parserm3u.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/library/parserm3u.cpp b/src/library/parserm3u.cpp index 36ecc326630..414774bf441 100644 --- a/src/library/parserm3u.cpp +++ b/src/library/parserm3u.cpp @@ -107,16 +107,24 @@ bool ParserM3u::writeM3UFile(const QString &file_str, const QList &item QString fileContents(QStringLiteral("#EXTM3U\n")); for (const QString& item : items) { fileContents += QStringLiteral("#EXTINF\n"); - QUrl itemUrl = QUrl::fromLocalFile(item); - QString itemUrlEncoded = itemUrl.toEncoded(); - if (useRelativePath) { - fileContents += baseDirectory.relativeFilePath(item) + QStringLiteral("\n"); - } else { - if (!useUtf8) { - fileContents += itemUrlEncoded + QStringLiteral("\n"); + QByteArray trackByteArray = QTextCodec::codecForName(kStandardM3uTextEncoding) + ->fromUnicode(item); + if ((trackByteArray == item) || useUtf8) { + if (useRelativePath) { + fileContents += baseDirectory.relativeFilePath(item) + QStringLiteral("\n"); } else { fileContents += item + QStringLiteral("\n"); } + } else { + if (useRelativePath) { + QUrl itemRelativeUrl = QUrl::fromLocalFile(baseDirectory.relativeFilePath(item)); + QString itemRelativeUrlEncoded = itemRelativeUrl.toEncoded(); + fileContents += itemRelativeUrlEncoded + QStringLiteral("\n"); + } else { + QUrl itemUrl = QUrl::fromLocalFile(item); + QString itemUrlEncoded = itemUrl.toEncoded(); + fileContents += itemUrlEncoded + QStringLiteral("\n"); + } } } From 93a786fec6974ee245417951e961205509b7d239 Mon Sep 17 00:00:00 2001 From: Fatih Emre YILDIZ Date: Fri, 13 May 2022 11:51:24 +0300 Subject: [PATCH 4/6] parserm3u: fix QTextCodec::toUnicode compare added --- src/library/parserm3u.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/library/parserm3u.cpp b/src/library/parserm3u.cpp index 414774bf441..49ef2f010ad 100644 --- a/src/library/parserm3u.cpp +++ b/src/library/parserm3u.cpp @@ -103,23 +103,22 @@ bool ParserM3u::writeM3UFile(const QString &file_str, const QList &item // On Linux and OS X \n is (which remains \n) QDir baseDirectory(QFileInfo(file_str).canonicalPath()); - + QTextCodec* codec = QTextCodec::codecForName(kStandardM3uTextEncoding); QString fileContents(QStringLiteral("#EXTM3U\n")); for (const QString& item : items) { fileContents += QStringLiteral("#EXTINF\n"); - QByteArray trackByteArray = QTextCodec::codecForName(kStandardM3uTextEncoding) - ->fromUnicode(item); - if ((trackByteArray == item) || useUtf8) { + if (useUtf8 || + useRelativePath) { //Issue: URL Location is not working properly for Relative Paths if (useRelativePath) { fileContents += baseDirectory.relativeFilePath(item) + QStringLiteral("\n"); } else { fileContents += item + QStringLiteral("\n"); } } else { - if (useRelativePath) { - QUrl itemRelativeUrl = QUrl::fromLocalFile(baseDirectory.relativeFilePath(item)); - QString itemRelativeUrlEncoded = itemRelativeUrl.toEncoded(); - fileContents += itemRelativeUrlEncoded + QStringLiteral("\n"); + QByteArray trackByteArray = codec->fromUnicode(item); + QString trackName = codec->toUnicode(trackByteArray); + if (trackName == item) { + fileContents += item + QStringLiteral("\n"); } else { QUrl itemUrl = QUrl::fromLocalFile(item); QString itemUrlEncoded = itemUrl.toEncoded(); From 1d21ca25fa3417238e4c150224e59cdae5193216 Mon Sep 17 00:00:00 2001 From: Fatih Emre YILDIZ Date: Sat, 14 May 2022 13:50:30 +0300 Subject: [PATCH 5/6] parserm3u: fallback implemented for both paths. --- src/library/parserm3u.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/library/parserm3u.cpp b/src/library/parserm3u.cpp index 49ef2f010ad..9bd0333f9d0 100644 --- a/src/library/parserm3u.cpp +++ b/src/library/parserm3u.cpp @@ -107,8 +107,7 @@ bool ParserM3u::writeM3UFile(const QString &file_str, const QList &item QString fileContents(QStringLiteral("#EXTM3U\n")); for (const QString& item : items) { fileContents += QStringLiteral("#EXTINF\n"); - if (useUtf8 || - useRelativePath) { //Issue: URL Location is not working properly for Relative Paths + if (useUtf8) { if (useRelativePath) { fileContents += baseDirectory.relativeFilePath(item) + QStringLiteral("\n"); } else { @@ -118,7 +117,11 @@ bool ParserM3u::writeM3UFile(const QString &file_str, const QList &item QByteArray trackByteArray = codec->fromUnicode(item); QString trackName = codec->toUnicode(trackByteArray); if (trackName == item) { - fileContents += item + QStringLiteral("\n"); + if (useRelativePath) { //Issue: URL Location is not working properly for Relative Paths + fileContents += baseDirectory.relativeFilePath(item) + QStringLiteral("\n"); + } else { + fileContents += item + QStringLiteral("\n"); + } } else { QUrl itemUrl = QUrl::fromLocalFile(item); QString itemUrlEncoded = itemUrl.toEncoded(); From 214dbbcb1a5fd9494bed9dca1479c822fb876347 Mon Sep 17 00:00:00 2001 From: Fatih Emre YILDIZ Date: Sat, 14 May 2022 13:53:19 +0300 Subject: [PATCH 6/6] parserm3u: info box added --- src/library/parserm3u.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/library/parserm3u.cpp b/src/library/parserm3u.cpp index 9bd0333f9d0..e42042081fe 100644 --- a/src/library/parserm3u.cpp +++ b/src/library/parserm3u.cpp @@ -101,7 +101,7 @@ bool ParserM3u::writeM3UFile(const QString &file_str, const QList &item // Important note: // On Windows \n will produce a (=\r\n) // On Linux and OS X \n is (which remains \n) - + bool urlEncodingUsed = false; QDir baseDirectory(QFileInfo(file_str).canonicalPath()); QTextCodec* codec = QTextCodec::codecForName(kStandardM3uTextEncoding); QString fileContents(QStringLiteral("#EXTM3U\n")); @@ -126,6 +126,7 @@ bool ParserM3u::writeM3UFile(const QString &file_str, const QList &item QUrl itemUrl = QUrl::fromLocalFile(item); QString itemUrlEncoded = itemUrl.toEncoded(); fileContents += itemUrlEncoded + QStringLiteral("\n"); + urlEncodingUsed = true; } } } @@ -146,6 +147,13 @@ bool ParserM3u::writeM3UFile(const QString &file_str, const QList &item QObject::tr("Could not create file") + " " + file_str); return false; } + if (urlEncodingUsed) { + QMessageBox::information(nullptr, + QObject::tr("Playlist Export Has Special Characters"), + QObject::tr("Some file paths in the playlist have special characters. " + "These file paths will be encoded as absolute path URLs. " + "Please select the m3u8 format for better and lossless exporting.")); + } file.write(outputByteArray); file.close();