Commit 306cbc59 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Added support for more playlist formats: m3u and VCLT.

This is the first patch of my multi-playlist format series.

svn path=/icecast/trunk/ices/; revision=18544
parent f6689737
......@@ -160,7 +160,7 @@
type. The current types are basic and script.
</p>
<h3>Basic</h3>
<h3>Basic / M3U / VCLT</h3>
<pre>
&lt;param name="type"&gt;basic&lt;/param&gt;
&lt;param name="file"&gt;/path/to/playlist&lt;/param&gt;
......@@ -168,10 +168,18 @@
&lt;param name="once"&gt;0&lt;/param&gt;
&lt;param name="restart-after-reread"&gt;1&lt;/param&gt;
</pre>
<h4>type</h4>
<div class=indentedbox>
This is the file format of the playlist.
Currently "basic", "m3u" and "vclt" are supported.
</div>
<h4>file</h4>
<div class=indentedbox>
State a path to a file which will contain a list of Ogg Vorbis filenames
to play. One per line with lines beginning with '#' being treated as
to play.
The format of this file depends on the setting of "type".
For type "basic" the format is
one filename per line with lines beginning with '#' being treated as
comments. If a line has a single '-' then standard input is read, which
provides a way of getting some external Ogg Vorbis stream into ices.
</div>
......
......@@ -46,6 +46,8 @@ typedef struct _module
static module modules[] = {
{ "basic", playlist_basic_initialise},
{ "m3u", playlist_basic_initialise},
{ "vclt", playlist_basic_initialise},
{ "script", playlist_script_initialise},
{NULL,NULL}
};
......
......@@ -54,6 +54,8 @@ static int load_playlist(basic_playlist *data)
FILE *file;
char buf[1024];
int buflen;
char *ret;
int is_next_entry = 1;
file = fopen(data->file, "rb");
......@@ -76,20 +78,37 @@ static int load_playlist(basic_playlist *data)
buflen = 0;
while (1)
{
if(fgets(buf,1024, file) == NULL) break;
if(buf[0]==0) break;
if((ret=fgets(buf, sizeof(buf), file)) == NULL) break;
if(ret[0]==0) break;
if(buf[0]=='\n' || (buf[0]=='\r' && buf[1]=='\n'))
if(ret[0]=='\n' || (ret[0]=='\r' && ret[1]=='\n'))
continue;
if(buf[0] == '#') /* Commented out entry */
if(ret[0] == '#') /* Commented out entry */
continue;
buf[strlen(buf)-1] = 0;
ret[strlen(ret)-1] = 0;
/* De-fuck windows files. */
if(strlen(buf) > 0 && buf[strlen(buf)-1] == '\r')
buf[strlen(buf)-1] = 0;
if(strlen(ret) > 0 && ret[strlen(ret)-1] == '\r')
ret[strlen(ret)-1] = 0;
if (data->type == PLAYLIST_VCLT)
{
if (!strcmp(ret, "=="))
{
is_next_entry = 1;
continue;
}
if (!is_next_entry)
continue;
if (!!strncasecmp(ret, "FILENAME=", 9))
continue;
ret += 9;
is_next_entry = 0;
}
if(buflen < data->len+1)
{
......@@ -97,7 +116,7 @@ static int load_playlist(basic_playlist *data)
data->pl = realloc(data->pl, buflen*sizeof(char *));
}
data->pl[data->len++] = strdup(buf);
data->pl[data->len++] = strdup(ret);
}
if (!data->len)
......@@ -186,6 +205,16 @@ void playlist_basic_free_filename(void *data, char *fn)
free (fn);
}
static basic_playlist_type _str2type(const char * type) {
if ( !strcmp(type, "basic") )
return PLAYLIST_BASIC;
if ( !strcmp(type, "m3u") )
return PLAYLIST_M3U;
if ( !strcmp(type, "vclt") )
return PLAYLIST_VCLT;
return PLAYLIST_INVALID;
}
int playlist_basic_initialise(module_param_t *params, playlist_state_t *pl)
{
basic_playlist *data;
......@@ -209,7 +238,7 @@ int playlist_basic_initialise(module_param_t *params, playlist_state_t *pl)
else if(!strcmp(params->name, "restart-after-reread"))
data->restartafterreread = atoi(params->value);
else if(!strcmp(params->name, "type"))
; /* We recognise this, but don't want to do anything with it */
data->type = _str2type(params->value);
else
{
LOG_WARN1("Unknown parameter to playlist input module: %s",
......@@ -225,6 +254,13 @@ int playlist_basic_initialise(module_param_t *params, playlist_state_t *pl)
return -1;
}
if (data->type == PLAYLIST_INVALID)
{
LOG_ERROR0("Playlist type invalid for playlist module");
free(data);
return -1;
}
return 0;
}
......@@ -14,6 +14,14 @@
#ifndef __PLAYLIST_BASIC_H__
#define __PLAYLIST_BASIC_H__
typedef enum
{
PLAYLIST_INVALID,
PLAYLIST_BASIC,
PLAYLIST_M3U,
PLAYLIST_VCLT,
} basic_playlist_type;
typedef struct
{
char **pl;
......@@ -24,6 +32,7 @@ typedef struct
int random;
int once;
int restartafterreread;
basic_playlist_type type; /* Playlist type */
} basic_playlist;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment