2009-12-16 20:04:36 +01:00
|
|
|
/*
|
2013-01-27 17:38:09 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-12-16 20:04:36 +01:00
|
|
|
* 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"
|
2013-01-27 17:38:09 +01:00
|
|
|
#include "CuePlaylistPlugin.hxx"
|
|
|
|
#include "PlaylistPlugin.hxx"
|
2013-09-05 09:37:54 +02:00
|
|
|
#include "SongEnumerator.hxx"
|
2013-09-05 18:22:02 +02:00
|
|
|
#include "tag/Tag.hxx"
|
2013-07-28 13:25:12 +02:00
|
|
|
#include "Song.hxx"
|
2013-04-09 00:22:35 +02:00
|
|
|
#include "cue/CueParser.hxx"
|
2013-05-12 16:02:27 +02:00
|
|
|
#include "TextInputStream.hxx"
|
2009-12-16 20:04:36 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-09-05 09:37:54 +02:00
|
|
|
class CuePlaylist final : public SongEnumerator {
|
2012-02-10 00:12:29 +01:00
|
|
|
struct input_stream *is;
|
2013-05-12 16:02:27 +02:00
|
|
|
TextInputStream tis;
|
2013-04-09 00:22:35 +02:00
|
|
|
CueParser parser;
|
2013-04-09 00:34:48 +02:00
|
|
|
|
2013-09-05 09:37:54 +02:00
|
|
|
public:
|
2013-04-09 00:34:48 +02:00
|
|
|
CuePlaylist(struct input_stream *_is)
|
2013-05-12 16:02:27 +02:00
|
|
|
:is(_is), tis(is) {
|
2013-04-09 00:34:48 +02:00
|
|
|
}
|
|
|
|
|
2013-09-05 09:37:54 +02:00
|
|
|
virtual Song *NextSong() override;
|
2009-12-16 20:04:36 +01:00
|
|
|
};
|
|
|
|
|
2013-09-05 09:37:54 +02:00
|
|
|
static SongEnumerator *
|
2012-02-10 00:12:29 +01:00
|
|
|
cue_playlist_open_stream(struct input_stream *is)
|
2009-12-16 20:04:36 +01:00
|
|
|
{
|
2013-09-05 09:37:54 +02:00
|
|
|
return new CuePlaylist(is);
|
2009-12-16 20:04:36 +01:00
|
|
|
}
|
|
|
|
|
2013-09-05 09:37:54 +02:00
|
|
|
Song *
|
|
|
|
CuePlaylist::NextSong()
|
2009-12-16 20:04:36 +01:00
|
|
|
{
|
2013-09-05 09:37:54 +02:00
|
|
|
Song *song = parser.Get();
|
2012-02-10 00:12:29 +01:00
|
|
|
if (song != NULL)
|
|
|
|
return song;
|
|
|
|
|
2013-05-12 16:02:27 +02:00
|
|
|
std::string line;
|
2013-09-05 09:37:54 +02:00
|
|
|
while (tis.ReadLine(line)) {
|
|
|
|
parser.Feed(line.c_str());
|
|
|
|
song = parser.Get();
|
2012-02-10 00:12:29 +01:00
|
|
|
if (song != NULL)
|
|
|
|
return song;
|
2009-12-16 20:04:36 +01:00
|
|
|
}
|
|
|
|
|
2013-09-05 09:37:54 +02:00
|
|
|
parser.Finish();
|
|
|
|
return parser.Get();
|
2009-12-16 20:04:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *const cue_playlist_suffixes[] = {
|
|
|
|
"cue",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *const cue_playlist_mime_types[] = {
|
|
|
|
"application/x-cue",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct playlist_plugin cue_playlist_plugin = {
|
2013-01-27 17:38:09 +01:00
|
|
|
"cue",
|
2009-12-16 20:04:36 +01:00
|
|
|
|
2013-01-27 17:38:09 +01:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
cue_playlist_open_stream,
|
2009-12-16 20:04:36 +01:00
|
|
|
|
2013-01-27 17:38:09 +01:00
|
|
|
nullptr,
|
|
|
|
cue_playlist_suffixes,
|
|
|
|
cue_playlist_mime_types,
|
2009-12-16 20:04:36 +01:00
|
|
|
};
|