2
* Copyright (C) 2003-2013 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
#include "ExtM3uPlaylistPlugin.hxx"
22
#include "PlaylistPlugin.hxx"
23
#include "SongEnumerator.hxx"
25
#include "tag/Tag.hxx"
26
#include "util/StringUtil.hxx"
27
#include "TextInputStream.hxx"
34
class ExtM3uPlaylist final : public SongEnumerator {
38
ExtM3uPlaylist(InputStream &is)
42
bool CheckFirstLine() {
44
return tis.ReadLine(line) &&
45
strcmp(line.c_str(), "#EXTM3U") == 0;
48
virtual Song *NextSong() override;
51
static SongEnumerator *
52
extm3u_open_stream(InputStream &is)
54
ExtM3uPlaylist *playlist = new ExtM3uPlaylist(is);
56
if (!playlist->CheckFirstLine()) {
57
/* no EXTM3U header: fall back to the plain m3u
67
* Parse a EXTINF line.
69
* @param line the rest of the input line after the colon
72
extm3u_parse_tag(const char *line)
79
duration = strtol(line, &endptr, 10);
85
/* 0 means unknown duration */
88
name = strchug_fast(endptr + 1);
89
if (*name == 0 && duration == 0)
90
/* no information available; don't allocate a tag
97
/* unfortunately, there is no real specification for the
98
EXTM3U format, so we must assume that the string after the
99
comma is opaque, and is just the song name*/
101
tag->AddItem(TAG_NAME, name);
107
ExtM3uPlaylist::NextSong()
115
if (!tis.ReadLine(line)) {
120
line_s = line.c_str();
122
if (g_str_has_prefix(line_s, "#EXTINF:")) {
124
tag = extm3u_parse_tag(line_s + 8);
128
line_s = strchug_fast(line_s);
129
} while (line_s[0] == '#' || *line_s == 0);
131
song = Song::NewRemote(line_s);
136
static const char *const extm3u_suffixes[] = {
141
static const char *const extm3u_mime_types[] = {
146
const struct playlist_plugin extm3u_playlist_plugin = {