M3uPlaylistPlugin.cxx 1.89 KB
Newer Older
1
/*
2
 * Copyright 2003-2016 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 33
	M3uPlaylist(InputStreamPtr &&is)
		:tis(std::move(is)) {
34
	}
35

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

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

45
std::unique_ptr<DetachedSong>
46
M3uPlaylist::NextSong()
47
{
48
	char *line_s;
49 50

	do {
51 52
		line_s = tis.ReadLine();
		if (line_s == nullptr)
53
			return nullptr;
54

55
		line_s = Strip(line_s);
56
	} while (line_s[0] == '#' || *line_s == 0);
57

58
	return std::unique_ptr<DetachedSong>(new DetachedSong(line_s));
59 60 61 62
}

static const char *const m3u_suffixes[] = {
	"m3u",
63
	"m3u8",
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
};