CuePlaylistPlugin.cxx 1.96 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

20
#include "CuePlaylistPlugin.hxx"
21 22
#include "../PlaylistPlugin.hxx"
#include "../SongEnumerator.hxx"
23
#include "../cue/CueParser.hxx"
Max Kellermann's avatar
Max Kellermann committed
24
#include "input/TextInputStream.hxx"
25

26
class CuePlaylist final : public SongEnumerator {
27
	TextInputStream tis;
28
	CueParser parser;
29

30
 public:
31 32
	CuePlaylist(InputStreamPtr &&is)
		:tis(std::move(is)) {
33 34
	}

35
	virtual std::unique_ptr<DetachedSong> NextSong() override;
36 37
};

38
static std::unique_ptr<SongEnumerator>
39
cue_playlist_open_stream(InputStreamPtr &&is)
40
{
41
	return std::make_unique<CuePlaylist>(std::move(is));
42 43
}

44
std::unique_ptr<DetachedSong>
45
CuePlaylist::NextSong()
46
{
47
	auto song = parser.Get();
48
	if (song != nullptr)
49
		return song;
50

51 52 53
	const char *line;
	while ((line = tis.ReadLine()) != nullptr) {
		parser.Feed(line);
54
		song = parser.Get();
55
		if (song != nullptr)
56
			return song;
57 58
	}

59
	parser.Finish();
60
	return parser.Get();
61 62 63 64
}

static const char *const cue_playlist_suffixes[] = {
	"cue",
65
	nullptr
66 67 68 69
};

static const char *const cue_playlist_mime_types[] = {
	"application/x-cue",
70
	nullptr
71 72 73
};

const struct playlist_plugin cue_playlist_plugin = {
74
	"cue",
75

76 77 78 79
	nullptr,
	nullptr,
	nullptr,
	cue_playlist_open_stream,
80

81 82 83
	nullptr,
	cue_playlist_suffixes,
	cue_playlist_mime_types,
84
};