CuePlaylistPlugin.cxx 1.96 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2014 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
#include <string>
28

29
class CuePlaylist final : public SongEnumerator {
30
	InputStream &is;
31
	TextInputStream tis;
32
	CueParser parser;
33

34
 public:
35
	CuePlaylist(InputStream &_is)
36
		:is(_is), tis(is) {
37 38
	}

39
	virtual DetachedSong *NextSong() override;
40 41
};

42
static SongEnumerator *
43
cue_playlist_open_stream(InputStream &is)
44
{
45
	return new CuePlaylist(is);
46 47
}

48
DetachedSong *
49
CuePlaylist::NextSong()
50
{
51
	DetachedSong *song = parser.Get();
52
	if (song != nullptr)
53 54
		return song;

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

63 64
	parser.Finish();
	return parser.Get();
65 66 67 68
}

static const char *const cue_playlist_suffixes[] = {
	"cue",
69
	nullptr
70 71 72 73
};

static const char *const cue_playlist_mime_types[] = {
	"application/x-cue",
74
	nullptr
75 76 77
};

const struct playlist_plugin cue_playlist_plugin = {
78
	"cue",
79

80 81 82 83
	nullptr,
	nullptr,
	nullptr,
	cue_playlist_open_stream,
84

85 86 87
	nullptr,
	cue_playlist_suffixes,
	cue_playlist_mime_types,
88
};