mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 03:27:40 +01:00
Always treat text/uri-list as M3U
This commit is contained in:
parent
987a918d90
commit
25ff2bca59
@ -48,7 +48,7 @@ SongLoader::Result SongLoader::Load(const QUrl& url, int timeout_msec) {
|
||||
return LoadLocal();
|
||||
}
|
||||
|
||||
timeout_timer_->start();
|
||||
timeout_timer_->start(timeout_msec);
|
||||
return LoadRemote();
|
||||
}
|
||||
|
||||
@ -153,9 +153,9 @@ void SongLoader::TypeFound(GstElement*, uint, GstCaps* caps, void* self) {
|
||||
return;
|
||||
|
||||
// Check the mimetype
|
||||
QString mimetype(gst_structure_get_name(gst_caps_get_structure(caps, 0)));
|
||||
if (mimetype == "text/plain" ||
|
||||
mimetype == "text/uri-list") {
|
||||
instance->mime_type_ = gst_structure_get_name(gst_caps_get_structure(caps, 0));
|
||||
if (instance->mime_type_ == "text/plain" ||
|
||||
instance->mime_type_ == "text/uri-list") {
|
||||
// Yeah it might be a playlist, let's get some data and have a better look
|
||||
instance->state_ = WaitingForMagic;
|
||||
return;
|
||||
@ -257,7 +257,7 @@ void SongLoader::EndOfStreamReached() {
|
||||
}
|
||||
|
||||
void SongLoader::MagicReady() {
|
||||
parser_ = playlist_parser_->MaybeGetParserForMagic(buffer_);
|
||||
parser_ = playlist_parser_->MaybeGetParserForMagic(buffer_, mime_type_);
|
||||
|
||||
if (!parser_) {
|
||||
// It doesn't look like a playlist, so just finish
|
||||
|
@ -86,6 +86,7 @@ private:
|
||||
bool success_;
|
||||
boost::shared_ptr<GstElement> pipeline_;
|
||||
ParserBase* parser_;
|
||||
QString mime_type_;
|
||||
QByteArray buffer_;
|
||||
};
|
||||
|
||||
|
@ -70,9 +70,11 @@ ParserBase* PlaylistParser::ParserForExtension(const QString& suffix) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ParserBase* PlaylistParser::MaybeGetParserForMagic(const QByteArray &data) const {
|
||||
ParserBase* PlaylistParser::MaybeGetParserForMagic(const QByteArray& data,
|
||||
const QString& mime_type) const {
|
||||
foreach (ParserBase* p, parsers_) {
|
||||
if (p->TryMagic(data))
|
||||
if ((!mime_type.isEmpty() && mime_type == p->mime_type()) ||
|
||||
p->TryMagic(data))
|
||||
return p;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -34,7 +34,8 @@ public:
|
||||
QStringList file_extensions() const;
|
||||
QString filters() const;
|
||||
|
||||
ParserBase* MaybeGetParserForMagic(const QByteArray& data) const;
|
||||
ParserBase* MaybeGetParserForMagic(const QByteArray& data,
|
||||
const QString& mime_type = QString()) const;
|
||||
|
||||
SongList Load(const QString& filename, ParserBase* parser = 0) const;
|
||||
void Save(const SongList& songs, const QString& filename) const;
|
||||
|
@ -180,6 +180,27 @@ TEST_F(SongLoaderTest, LoadRemotePlainText) {
|
||||
EXPECT_EQ(false, spy[0][0].toBool());
|
||||
}
|
||||
|
||||
TEST_F(SongLoaderTest, LoadRemotePlainM3U) {
|
||||
SongLoader::Result ret = loader_->Load(QString(kRemoteUrl) + "/plainm3u.m3u");
|
||||
ASSERT_EQ(SongLoader::WillLoadAsync, ret);
|
||||
|
||||
QSignalSpy spy(loader_.get(), SIGNAL(LoadFinished(bool)));
|
||||
|
||||
// Start an event loop to wait for gstreamer to do its thing
|
||||
QEventLoop loop;
|
||||
QObject::connect(loader_.get(), SIGNAL(LoadFinished(bool)),
|
||||
&loop, SLOT(quit()));
|
||||
loop.exec(QEventLoop::ExcludeUserInputEvents);
|
||||
|
||||
// Check the signal was emitted with Success
|
||||
ASSERT_EQ(1, spy.count());
|
||||
EXPECT_EQ(true, spy[0][0].toBool());
|
||||
|
||||
ASSERT_EQ(2, loader_->songs().count());
|
||||
EXPECT_EQ("http://www.example.com/one.mp3", loader_->songs()[0].filename());
|
||||
EXPECT_EQ("http://www.example.com/two.mp3", loader_->songs()[1].filename());
|
||||
}
|
||||
|
||||
TEST_F(SongLoaderTest, LoadLocalDirectory) {
|
||||
// Make a directory and shove some files in it
|
||||
QByteArray dir(QString(QDir::tempPath() + "/songloader_testdir-XXXXXX").toLocal8Bit());
|
||||
|
Loading…
x
Reference in New Issue
Block a user