1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-31 03:27:40 +01:00

Quick try to get metadata working on XSPF and M3U.

This commit is contained in:
Gavin Howard 2014-08-12 21:41:00 -06:00
parent 0efb23994d
commit a0bbe2cfaf
4 changed files with 48 additions and 38 deletions

View File

@ -109,11 +109,13 @@ void M3UParser::Save(const SongList& songs, QIODevice* device,
if (song.url().isEmpty()) {
continue;
}
QString meta = QString("#EXTINF:%1,%2 - %3\n")
.arg(song.length_nanosec() / kNsecPerSec)
.arg(song.artist())
.arg(song.title());
device->write(meta.toUtf8());
if (writeMetadata) {
QString meta = QString("#EXTINF:%1,%2 - %3\n")
.arg(song.length_nanosec() / kNsecPerSec)
.arg(song.artist())
.arg(song.title());
device->write(meta.toUtf8());
}
device->write(URLOrRelativeFilename(song.url(), dir).toUtf8());
device->write("\n");
}

View File

@ -25,7 +25,10 @@
#include <QUrl>
ParserBase::ParserBase(LibraryBackendInterface* library, QSettings *settings, QObject* parent)
: QObject(parent), settings_(settings), library_(library) {}
: QObject(parent), library_(library) {
path = settings->value("path_type", Playlist::Path_Automatic);
writeMetadata = settings->value("write_metadata", true).toBool();
}
void ParserBase::LoadSong(const QString& filename_or_url, qint64 beginning,
const QDir& dir, Song* song) const {
@ -91,7 +94,6 @@ QString ParserBase::URLOrRelativeFilename(const QUrl& url,
if (url.scheme() != "file") return url.toString();
const QString filename = url.toLocalFile();
const Playlist::Path path = settings->value("path_type", Playlist::Path_Automatic);
if (path != Playlist::Path_Absolute && QDir::isAbsolutePath(filename)) {
const QString relative = dir.relativeFilePath(filename);

View File

@ -71,9 +71,11 @@ class ParserBase : public QObject {
// This function should always be used when saving a playlist.
QString URLOrRelativeFilename(const QUrl& url, const QDir& dir) const;
Playlist::Path path;
bool writeMetadata;
private:
LibraryBackendInterface* library_;
QSettings* settings_;
};
#endif // PARSERBASE_H

View File

@ -124,41 +124,45 @@ void XSPFParser::Save(const SongList& songs, QIODevice* device,
StreamElement track("track", &writer);
writer.writeTextElement("location", filename_or_url);
writer.writeTextElement("title", song.title());
if (!song.artist().isEmpty()) {
writer.writeTextElement("creator", song.artist());
}
if (!song.album().isEmpty()) {
writer.writeTextElement("album", song.album());
}
if (song.length_nanosec() != -1) {
writer.writeTextElement(
"duration", QString::number(song.length_nanosec() / kNsecPerMsec));
}
QString art =
song.art_manual().isEmpty() ? song.art_automatic() : song.art_manual();
// Ignore images that are in our resource bundle.
if (!art.startsWith(":") && !art.isEmpty()) {
QString art_filename;
if (!art.contains("://")) {
art_filename = art;
} else if (QUrl(art).scheme() == "file") {
art_filename = QUrl(art).toLocalFile();
if (writeMetadata) {
writer.writeTextElement("title", song.title());
if (!song.artist().isEmpty()) {
writer.writeTextElement("creator", song.artist());
}
if (!song.album().isEmpty()) {
writer.writeTextElement("album", song.album());
}
if (song.length_nanosec() != -1) {
writer.writeTextElement(
"duration", QString::number(song.length_nanosec() / kNsecPerMsec));
}
if (!art_filename.isEmpty()) {
// Make this filename relative to the directory we're saving the
// playlist.
art_filename = dir.relativeFilePath(
QFileInfo(art_filename).absoluteFilePath());
} else {
// Just use whatever URL was in the Song.
art_filename = art;
}
QString art =
song.art_manual().isEmpty() ? song.art_automatic() : song.art_manual();
// Ignore images that are in our resource bundle.
if (!art.startsWith(":") && !art.isEmpty()) {
QString art_filename;
if (!art.contains("://")) {
art_filename = art;
} else if (QUrl(art).scheme() == "file") {
art_filename = QUrl(art).toLocalFile();
}
writer.writeTextElement("image", art_filename);
if (!art_filename.isEmpty()) {
// Make this filename relative to the directory we're saving the
// playlist.
art_filename = dir.relativeFilePath(
QFileInfo(art_filename).absoluteFilePath());
} else {
// Just use whatever URL was in the Song.
art_filename = art;
}
writer.writeTextElement("image", art_filename);
}
}
}
writer.writeEndDocument();
}