From dc51176437924b83deef1c39afd83058958c688b Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Tue, 15 Mar 2022 23:23:34 -0600 Subject: [PATCH 1/7] M3U Parser: Remove the #EXTM3U header from no-metadata playlists. --- src/playlistparsers/m3uparser.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/playlistparsers/m3uparser.cpp b/src/playlistparsers/m3uparser.cpp index 20ef07250a..885b119048 100644 --- a/src/playlistparsers/m3uparser.cpp +++ b/src/playlistparsers/m3uparser.cpp @@ -103,13 +103,15 @@ bool M3UParser::ParseMetadata(const QString& line, void M3UParser::Save(const SongList& songs, QIODevice* device, const QDir& dir, Playlist::Path path_type) const { - device->write("#EXTM3U\n"); - QSettings s; s.beginGroup(Playlist::kSettingsGroup); bool writeMetadata = s.value(Playlist::kWriteMetadata, true).toBool(); s.endGroup(); + if (writeMetadata) { + device->write("#EXTM3U\n"); + } + for (const Song& song : songs) { if (song.url().isEmpty()) { continue; From ec103561c5f515a7f641a129f9c169576179c3f7 Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Tue, 15 Mar 2022 23:27:29 -0600 Subject: [PATCH 2/7] PLS Parser: Implement no-metadata playlist saving. --- src/playlistparsers/plsparser.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/playlistparsers/plsparser.cpp b/src/playlistparsers/plsparser.cpp index e7a3bdd1f9..ad7b69a748 100644 --- a/src/playlistparsers/plsparser.cpp +++ b/src/playlistparsers/plsparser.cpp @@ -69,12 +69,20 @@ void PLSParser::Save(const SongList& songs, QIODevice* device, const QDir& dir, s << "Version=2" << endl; s << "NumberOfEntries=" << songs.count() << endl; + QSettings settings; + settings.beginGroup(Playlist::kSettingsGroup); + bool writeMetadata = settings.value(Playlist::kWriteMetadata, true).toBool(); + settings.endGroup(); + int n = 1; for (const Song& song : songs) { s << "File" << n << "=" << URLOrFilename(song.url(), dir, path_type) << endl; - s << "Title" << n << "=" << song.title() << endl; - s << "Length" << n << "=" << song.length_nanosec() / kNsecPerSec << endl; + if (writeMetadata) { + s << "Title" << n << "=" << song.title() << endl; + s << "Length" << n << "=" << song.length_nanosec() / kNsecPerSec << endl; + } + ++n; } } From ae4a9e6bba8d969c0c0e254236af8e7c6e271bf9 Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Thu, 17 Mar 2022 16:32:23 -0600 Subject: [PATCH 3/7] WPL Parser: Implement no-metadata playlist saving. --- src/playlistparsers/wplparser.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/playlistparsers/wplparser.cpp b/src/playlistparsers/wplparser.cpp index ec6fcd539c..d8229c3247 100644 --- a/src/playlistparsers/wplparser.cpp +++ b/src/playlistparsers/wplparser.cpp @@ -79,6 +79,11 @@ void WplParser::ParseSeq(const QDir& dir, QXmlStreamReader* reader, void WplParser::Save(const SongList& songs, QIODevice* device, const QDir& dir, Playlist::Path path_type) const { + QSettings s; + s.beginGroup(Playlist::kSettingsGroup); + bool writeMetadata = s.value(Playlist::kWriteMetadata, true).toBool(); + s.endGroup(); + QXmlStreamWriter writer(device); writer.setAutoFormatting(true); writer.setAutoFormattingIndent(2); @@ -86,7 +91,7 @@ void WplParser::Save(const SongList& songs, QIODevice* device, const QDir& dir, StreamElement smil("smil", &writer); - { + if (writeMetadata) { StreamElement head("head", &writer); WriteMeta("Generator", "Clementine -- " CLEMENTINE_VERSION_DISPLAY, &writer); From edfc2666ab40a0406cdcfc45328367e0b07df945 Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Thu, 17 Mar 2022 16:32:42 -0600 Subject: [PATCH 4/7] ASX Parser: Implement no-metadata playlist saving. --- src/playlistparsers/asxparser.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/playlistparsers/asxparser.cpp b/src/playlistparsers/asxparser.cpp index 9f31568b35..4685adbb95 100644 --- a/src/playlistparsers/asxparser.cpp +++ b/src/playlistparsers/asxparser.cpp @@ -120,6 +120,11 @@ Song ASXParser::ParseTrack(QXmlStreamReader* reader, const QDir& dir) const { void ASXParser::Save(const SongList& songs, QIODevice* device, const QDir&, Playlist::Path path_type) const { + QSettings s; + s.beginGroup(Playlist::kSettingsGroup); + bool writeMetadata = s.value(Playlist::kWriteMetadata, true).toBool(); + s.endGroup(); + QXmlStreamWriter writer(device); writer.setAutoFormatting(true); writer.setAutoFormattingIndent(2); @@ -129,12 +134,14 @@ void ASXParser::Save(const SongList& songs, QIODevice* device, const QDir&, writer.writeAttribute("version", "3.0"); for (const Song& song : songs) { StreamElement entry("entry", &writer); - writer.writeTextElement("title", song.title()); + if (!song.title().isEmpty() && writeMetadata) { + writer.writeTextElement("title", song.title()); + } { StreamElement ref("ref", &writer); writer.writeAttribute("href", song.url().toString()); } - if (!song.artist().isEmpty()) { + if (!song.artist().isEmpty() && writeMetadata) { writer.writeTextElement("author", song.artist()); } } From f1c6377cfae07ce7d4ffdda9cba61ab85b16b503 Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Fri, 18 Mar 2022 16:38:36 -0600 Subject: [PATCH 5/7] ASX Parser: Remove out XML declaration and starting whitespace. --- src/playlistparsers/asxparser.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/playlistparsers/asxparser.cpp b/src/playlistparsers/asxparser.cpp index 4685adbb95..21cd45e3d0 100644 --- a/src/playlistparsers/asxparser.cpp +++ b/src/playlistparsers/asxparser.cpp @@ -126,12 +126,11 @@ void ASXParser::Save(const SongList& songs, QIODevice* device, const QDir&, s.endGroup(); QXmlStreamWriter writer(device); + writer.writeStartElement("asx"); + writer.writeAttribute("version", "3.0"); writer.setAutoFormatting(true); writer.setAutoFormattingIndent(2); - writer.writeStartDocument(); { - StreamElement asx("asx", &writer); - writer.writeAttribute("version", "3.0"); for (const Song& song : songs) { StreamElement entry("entry", &writer); if (!song.title().isEmpty() && writeMetadata) { @@ -146,7 +145,7 @@ void ASXParser::Save(const SongList& songs, QIODevice* device, const QDir&, } } } - writer.writeEndDocument(); + writer.writeEndElement(); } bool ASXParser::TryMagic(const QByteArray& data) const { From ed5dbb436a79533e711a170bb91335c9ea7b0b4b Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Fri, 18 Mar 2022 16:39:02 -0600 Subject: [PATCH 6/7] WPL Parser: Remove out starting whitespace. --- src/playlistparsers/wplparser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/playlistparsers/wplparser.cpp b/src/playlistparsers/wplparser.cpp index d8229c3247..6bdb61b0d7 100644 --- a/src/playlistparsers/wplparser.cpp +++ b/src/playlistparsers/wplparser.cpp @@ -85,9 +85,9 @@ void WplParser::Save(const SongList& songs, QIODevice* device, const QDir& dir, s.endGroup(); QXmlStreamWriter writer(device); + writer.writeProcessingInstruction("wpl", "version=\"1.0\""); writer.setAutoFormatting(true); writer.setAutoFormattingIndent(2); - writer.writeProcessingInstruction("wpl", "version=\"1.0\""); StreamElement smil("smil", &writer); From 351f0c2d7516cb83abb830510cbbfeff432f07b1 Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Sat, 19 Nov 2022 16:22:23 -0700 Subject: [PATCH 7/7] PLS Parser: Correctly write specification required structures. --- src/playlistparsers/plsparser.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/playlistparsers/plsparser.cpp b/src/playlistparsers/plsparser.cpp index ad7b69a748..f39e7964e5 100644 --- a/src/playlistparsers/plsparser.cpp +++ b/src/playlistparsers/plsparser.cpp @@ -66,8 +66,6 @@ void PLSParser::Save(const SongList& songs, QIODevice* device, const QDir& dir, Playlist::Path path_type) const { QTextStream s(device); s << "[playlist]" << endl; - s << "Version=2" << endl; - s << "NumberOfEntries=" << songs.count() << endl; QSettings settings; settings.beginGroup(Playlist::kSettingsGroup); @@ -85,6 +83,9 @@ void PLSParser::Save(const SongList& songs, QIODevice* device, const QDir& dir, ++n; } + + s << "NumberOfEntries=" << songs.count() << endl; + s << "Version=2" << endl; } bool PLSParser::TryMagic(const QByteArray& data) const {