CuePlaylistPlugin.cxx 1.96 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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.
 */

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

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

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

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

39
static SongEnumerator *
40
cue_playlist_open_stream(InputStreamPtr &&is)
41
{
42
	return new CuePlaylist(std::move(is));
43 44
}

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

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

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

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

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

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

77 78 79 80
	nullptr,
	nullptr,
	nullptr,
	cue_playlist_open_stream,
81

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