Look at the file extension as well as magic when loading a local playlist. Fixes issue #507

This commit is contained in:
David Sansome 2010-07-24 14:09:27 +00:00
parent 692e5715e3
commit 77b4ec54bd
2 changed files with 13 additions and 8 deletions

View File

@ -106,20 +106,26 @@ SongLoader::Result SongLoader::LoadLocal() {
QByteArray data(file.read(PlaylistParser::kMagicSize)); QByteArray data(file.read(PlaylistParser::kMagicSize));
ParserBase* parser = playlist_parser_->MaybeGetParserForMagic(data); ParserBase* parser = playlist_parser_->MaybeGetParserForMagic(data);
if (!parser) {
// Check the file extension as well, maybe the magic failed, or it was a
// basic M3U file which is just a plain list of filenames.
parser = playlist_parser_->ParserForExtension(QFileInfo(filename).suffix());
}
if (parser) { if (parser) {
qDebug() << "Parsing using" << parser->name(); qDebug() << "Parsing using" << parser->name();
// It's a playlist! // It's a playlist!
file.reset(); file.reset();
songs_ = parser->Load(&file, QFileInfo(filename).path()); songs_ = parser->Load(&file, QFileInfo(filename).path());
} else { return Success;
}
// Not a playlist, so just assume it's a song // Not a playlist, so just assume it's a song
Song song; Song song;
song.InitFromFile(filename, -1); song.InitFromFile(filename, -1);
if (song.is_valid()) if (song.is_valid())
songs_ << song; songs_ << song;
}
return Success; return Success;
} }

View File

@ -36,13 +36,12 @@ public:
ParserBase* MaybeGetParserForMagic(const QByteArray& data, ParserBase* MaybeGetParserForMagic(const QByteArray& data,
const QString& mime_type = QString()) const; const QString& mime_type = QString()) const;
ParserBase* ParserForExtension(const QString& suffix) const;
SongList Load(const QString& filename, ParserBase* parser = 0) const; SongList Load(const QString& filename, ParserBase* parser = 0) const;
void Save(const SongList& songs, const QString& filename) const; void Save(const SongList& songs, const QString& filename) const;
private: private:
ParserBase* ParserForExtension(const QString& suffix) const;
QList<ParserBase*> parsers_; QList<ParserBase*> parsers_;
}; };