M3uPlaylistPlugin.cxx 1.83 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
 * 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 "config.h"
21
#include "M3uPlaylistPlugin.hxx"
22 23
#include "../PlaylistPlugin.hxx"
#include "../SongEnumerator.hxx"
24
#include "DetachedSong.hxx"
25
#include "util/StringUtil.hxx"
Max Kellermann's avatar
Max Kellermann committed
26
#include "input/TextInputStream.hxx"
27

28
class M3uPlaylist final : public SongEnumerator {
29 30
	TextInputStream tis;

31
public:
32
	M3uPlaylist(InputStream &is)
33 34
		:tis(is) {
	}
35

36
	virtual DetachedSong *NextSong() override;
37 38
};

39
static SongEnumerator *
40
m3u_open_stream(InputStream &is)
41
{
42
	return new M3uPlaylist(is);
43 44
}

45
DetachedSong *
46
M3uPlaylist::NextSong()
47
{
48 49
	std::string line;
	const char *line_s;
50 51

	do {
52
		if (!tis.ReadLine(line))
53
			return nullptr;
54

55
		line_s = line.c_str();
56
		line_s = strchug_fast(line_s);
57
	} while (line_s[0] == '#' || *line_s == 0);
58

59
	return new DetachedSong(line_s);
60 61 62 63
}

static const char *const m3u_suffixes[] = {
	"m3u",
64
	nullptr
65 66 67 68
};

static const char *const m3u_mime_types[] = {
	"audio/x-mpegurl",
69
	nullptr
70 71 72
};

const struct playlist_plugin m3u_playlist_plugin = {
73
	"m3u",
74

75 76 77 78
	nullptr,
	nullptr,
	nullptr,
	m3u_open_stream,
79

80 81 82
	nullptr,
	m3u_suffixes,
	m3u_mime_types,
83
};