Save support for M3U.
This commit is contained in:
parent
1b76ead951
commit
07b2c38690
@ -95,5 +95,18 @@ bool M3UParser::ParseMetadata(const QString& line, M3UParser::Metadata* metadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
void M3UParser::Save(const SongList &songs, QIODevice *device, const QDir &dir) const {
|
void M3UParser::Save(const SongList &songs, QIODevice *device, const QDir &dir) const {
|
||||||
// TODO
|
device->write("#EXTM3U\n");
|
||||||
|
foreach (const Song& song, songs) {
|
||||||
|
if (song.filename().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QString meta = QString("#EXTINF:%1,%2 - %3\n").arg(song.length()).arg(song.artist()).arg(song.title());
|
||||||
|
device->write(meta.toLatin1());
|
||||||
|
if (song.filetype() == Song::Type_Stream) {
|
||||||
|
device->write(song.filename().toLatin1());
|
||||||
|
} else {
|
||||||
|
device->write(MakeRelativeTo(song.filename(), dir).toLatin1());
|
||||||
|
}
|
||||||
|
device->write("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "gmock/gmock-matchers.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "test_utils.h"
|
#include "test_utils.h"
|
||||||
#include "mock_taglib.h"
|
#include "mock_taglib.h"
|
||||||
@ -23,6 +24,8 @@
|
|||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
|
|
||||||
|
using ::testing::HasSubstr;
|
||||||
|
|
||||||
class M3UParserTest : public ::testing::Test {
|
class M3UParserTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
static void SetUpTestCase() {
|
static void SetUpTestCase() {
|
||||||
@ -124,3 +127,22 @@ TEST_F(M3UParserTest, ParsesActualM3U) {
|
|||||||
EXPECT_EQ("ほっぴンちょっぴン", songs.back().title());
|
EXPECT_EQ("ほっぴンちょっぴン", songs.back().title());
|
||||||
EXPECT_EQ(85, songs.back().length());
|
EXPECT_EQ(85, songs.back().length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(M3UParserTest, SavesSong) {
|
||||||
|
QByteArray data;
|
||||||
|
QBuffer buffer(&data);
|
||||||
|
buffer.open(QIODevice::WriteOnly);
|
||||||
|
Song one;
|
||||||
|
one.set_filetype(Song::Type_Stream);
|
||||||
|
one.set_title("foo");
|
||||||
|
one.set_artist("bar");
|
||||||
|
one.set_length(123);
|
||||||
|
one.set_filename("http://www.example.com/foo.mp3");
|
||||||
|
SongList songs;
|
||||||
|
songs << one;
|
||||||
|
M3UParser parser;
|
||||||
|
parser.Save(songs, &buffer);
|
||||||
|
EXPECT_THAT(data.constData(), HasSubstr("#EXTM3U"));
|
||||||
|
EXPECT_THAT(data.constData(), HasSubstr("#EXTINF:123,bar - foo"));
|
||||||
|
EXPECT_THAT(data.constData(), HasSubstr("http://www.example.com/foo.mp3"));
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user