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"
|
2009-12-16 20:04:36 +01:00
|
|
|
#include "tag.h"
|
|
|
|
#include "song.h"
|
2012-02-10 00:12:29 +01:00
|
|
|
#include "input_stream.h"
|
2013-01-27 17:38:09 +01:00
|
|
|
|
|
|
|
extern "C" {
|
2012-02-10 00:12:29 +01:00
|
|
|
#include "text_input_stream.h"
|
2013-01-27 17:38:09 +01:00
|
|
|
#include "cue/cue_parser.h"
|
|
|
|
}
|
2009-12-16 20:04:36 +01:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "cue"
|
|
|
|
|
2013-01-27 17:38:09 +01:00
|
|
|
struct CuePlaylist {
|
2009-12-16 20:04:36 +01:00
|
|
|
struct playlist_provider base;
|
|
|
|
|
2012-02-10 00:12:29 +01:00
|
|
|
struct input_stream *is;
|
|
|
|
struct text_input_stream *tis;
|
|
|
|
struct cue_parser *parser;
|
2009-12-16 20:04:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct playlist_provider *
|
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-01-27 17:38:09 +01:00
|
|
|
CuePlaylist *playlist = g_new(CuePlaylist, 1);
|
2012-02-10 00:12:29 +01:00
|
|
|
playlist_provider_init(&playlist->base, &cue_playlist_plugin);
|
2009-12-16 20:04:36 +01:00
|
|
|
|
2012-02-10 00:12:29 +01:00
|
|
|
playlist->is = is;
|
|
|
|
playlist->tis = text_input_stream_new(is);
|
|
|
|
playlist->parser = cue_parser_new();
|
2009-12-16 20:04:36 +01:00
|
|
|
|
|
|
|
return &playlist->base;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cue_playlist_close(struct playlist_provider *_playlist)
|
|
|
|
{
|
2013-01-27 17:38:09 +01:00
|
|
|
CuePlaylist *playlist = (CuePlaylist *)_playlist;
|
2009-12-16 20:04:36 +01:00
|
|
|
|
2012-02-10 00:12:29 +01:00
|
|
|
cue_parser_free(playlist->parser);
|
|
|
|
text_input_stream_free(playlist->tis);
|
2009-12-16 20:04:36 +01:00
|
|
|
g_free(playlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct song *
|
|
|
|
cue_playlist_read(struct playlist_provider *_playlist)
|
|
|
|
{
|
2013-01-27 17:38:09 +01:00
|
|
|
CuePlaylist *playlist = (CuePlaylist *)_playlist;
|
2012-02-10 00:12:29 +01:00
|
|
|
|
|
|
|
struct song *song = cue_parser_get(playlist->parser);
|
|
|
|
if (song != NULL)
|
|
|
|
return song;
|
|
|
|
|
|
|
|
const char *line;
|
|
|
|
while ((line = text_input_stream_read(playlist->tis)) != NULL) {
|
|
|
|
cue_parser_feed(playlist->parser, line);
|
|
|
|
song = cue_parser_get(playlist->parser);
|
|
|
|
if (song != NULL)
|
|
|
|
return song;
|
2009-12-16 20:04:36 +01:00
|
|
|
}
|
|
|
|
|
2012-02-10 00:12:29 +01:00
|
|
|
cue_parser_finish(playlist->parser);
|
|
|
|
return cue_parser_get(playlist->parser);
|
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,
|
|
|
|
cue_playlist_close,
|
|
|
|
cue_playlist_read,
|
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
|
|
|
};
|