Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playlist parser writer improvements #7163

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
18 changes: 12 additions & 6 deletions src/playlistparsers/asxparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,32 @@ 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.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);
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());
}
}
}
writer.writeEndDocument();
writer.writeEndElement();
}

bool ASXParser::TryMagic(const QByteArray& data) const {
Expand Down
6 changes: 4 additions & 2 deletions src/playlistparsers/m3uparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 13 additions & 4 deletions src/playlistparsers/plsparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,26 @@ 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);
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;
}

s << "NumberOfEntries=" << songs.count() << endl;
s << "Version=2" << endl;
}

bool PLSParser::TryMagic(const QByteArray& data) const {
Expand Down
9 changes: 7 additions & 2 deletions src/playlistparsers/wplparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ 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.writeProcessingInstruction("wpl", "version=\"1.0\"");
writer.setAutoFormatting(true);
writer.setAutoFormattingIndent(2);
writer.writeProcessingInstruction("wpl", "version=\"1.0\"");

StreamElement smil("smil", &writer);

{
if (writeMetadata) {
StreamElement head("head", &writer);
WriteMeta("Generator", "Clementine -- " CLEMENTINE_VERSION_DISPLAY,
&writer);
Expand Down