Fix loading playlists correctly

This commit is contained in:
Jonas Kvinge 2019-03-22 23:23:22 +01:00
parent d427733bfc
commit 046c822604
2 changed files with 18 additions and 16 deletions

View File

@ -44,20 +44,23 @@ void ParserBase::LoadSong(const QString &filename_or_url, qint64 beginning, cons
if (filename_or_url.contains(QRegExp("^[a-z]{2,}:"))) { if (filename_or_url.contains(QRegExp("^[a-z]{2,}:"))) {
QUrl url(filename_or_url); QUrl url(filename_or_url);
if (url.scheme() == "file") { song->set_source(Song::SourceFromURL(url));
if (song->source() == Song::Source_LocalFile) {
filename = url.toLocalFile(); filename = url.toLocalFile();
} }
//else { else if (song->source() == Song::Source_Stream || song->source() == Song::Source_Tidal) {
// song->set_url(QUrl::fromUserInput(filename_or_url)); song->set_url(QUrl::fromUserInput(filename_or_url));
// song->set_filetype(Song::Type_Stream); song->set_filetype(Song::FileType_Stream);
// song->set_valid(true); song->set_valid(true);
// return; return;
// } }
else {
qLog(Error) << "Don't know how to handle" << url;
}
} }
// Strawberry always wants / separators internally. Using // Strawberry always wants / separators internally.
// QDir::fromNativeSeparators() only works on the same platform the playlist // Using QDir::fromNativeSeparators() only works on the same platform the playlist was created on/for, using replace() lets playlists work on any platform.
// was created on/for, using replace() lets playlists work on any platform.
filename = filename.replace('\\', '/'); filename = filename.replace('\\', '/');
// Make the path absolute // Make the path absolute
@ -74,6 +77,7 @@ void ParserBase::LoadSong(const QString &filename_or_url, qint64 beginning, cons
// Search in the collection // Search in the collection
Song collection_song; Song collection_song;
collection_song.set_source(Song::Source_Collection);
if (collection_) { if (collection_) {
collection_song = collection_->GetSongByUrl(url, beginning); collection_song = collection_->GetSongByUrl(url, beginning);
} }
@ -91,7 +95,6 @@ void ParserBase::LoadSong(const QString &filename_or_url, qint64 beginning, cons
Song ParserBase::LoadSong(const QString &filename_or_url, qint64 beginning, const QDir &dir) const { Song ParserBase::LoadSong(const QString &filename_or_url, qint64 beginning, const QDir &dir) const {
Song song; Song song;
song.set_source(Song::Source_LocalFile);
LoadSong(filename_or_url, beginning, dir, &song); LoadSong(filename_or_url, beginning, dir, &song);
return song; return song;

View File

@ -162,21 +162,20 @@ void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
writer.writeTextElement("album", song.album()); writer.writeTextElement("album", song.album());
} }
if (song.length_nanosec() != -1) { if (song.length_nanosec() != -1) {
writer.writeTextElement( writer.writeTextElement("duration", QString::number(song.length_nanosec() / kNsecPerMsec));
"duration", QString::number(song.length_nanosec() / kNsecPerMsec));
} }
if (song.track() > 0) { if (song.track() > 0) {
writer.writeTextElement("trackNum", QString::number(song.track())); writer.writeTextElement("trackNum", QString::number(song.track()));
} }
QString art = song.art_manual().isEmpty() ? song.art_automatic() QString art = song.art_manual().isEmpty() ? song.art_automatic() : song.art_manual();
: song.art_manual();
// Ignore images that are in our resource bundle. // Ignore images that are in our resource bundle.
if (!art.startsWith(":") && !art.isEmpty()) { if (!art.startsWith(":") && !art.isEmpty()) {
QString art_filename; QString art_filename;
if (!art.contains("://")) { if (!art.contains("://")) {
art_filename = art; art_filename = art;
} else if (QUrl(art).scheme() == "file") { }
else if (QUrl(art).scheme() == "file") {
art_filename = QUrl(art).toLocalFile(); art_filename = QUrl(art).toLocalFile();
} }