Commit c6dfb13b authored by Stan Seibert's avatar Stan Seibert

Full playlist support reading from disk. Playlist files can contain files,

directories, URLs, and small animals.

svn path=/trunk/vorbis-tools/; revision=3542
parent 76a9b0f9
......@@ -11,7 +11,7 @@
* *
********************************************************************
last mod: $Id: cmdline_options.c,v 1.11 2002/07/03 03:18:31 volsung Exp $
last mod: $Id: cmdline_options.c,v 1.12 2002/07/06 19:12:17 volsung Exp $
********************************************************************/
......@@ -45,6 +45,7 @@ struct option long_options[] = {
{"nth", required_argument, 0, 'x'},
{"ntimes", required_argument, 0, 'y'},
{"shuffle", no_argument, 0, 'z'},
{"list", required_argument, 0, '@'},
{0, 0, 0, 0}
};
......@@ -61,7 +62,7 @@ int parse_cmdline_options (int argc, char **argv,
audio_device_t *current;
int ret;
while (-1 != (ret = getopt_long(argc, argv, "b:c::d:f:hl:k:o:p:qvVx:y:z",
while (-1 != (ret = getopt_long(argc, argv, "b:c::d:f:hl:k:o:p:qvVx:y:z@:",
long_options, &option_index))) {
switch (ret) {
......@@ -194,7 +195,13 @@ int parse_cmdline_options (int argc, char **argv,
case 'z':
ogg123_opts->shuffle = 1;
break;
case '@':
if (playlist_append_from_file(ogg123_opts->playlist, optarg) == 0)
status_error(_("--- Cannot open playlist file %s. Skipped.\n"),
optarg);
break;
case '?':
break;
......
......@@ -14,7 +14,7 @@
* *
********************************************************************
last mod: $Id: ogg123.c,v 1.64 2002/07/06 16:18:31 volsung Exp $
last mod: $Id: ogg123.c,v 1.65 2002/07/06 19:12:18 volsung Exp $
********************************************************************/
......@@ -147,6 +147,8 @@ void options_init (ogg123_options_t *opts)
opts->default_device = NULL;
opts->status_freq = 10.0;
opts->playlist = NULL;
}
......@@ -275,7 +277,6 @@ int main(int argc, char **argv)
{
int optind;
char **playlist_array;
playlist_t *list = playlist_create();
int items;
struct stat stat_buf;
int i;
......@@ -290,6 +291,7 @@ int main(int argc, char **argv)
file_options_init(file_opts);
parse_std_configs(file_opts);
options.playlist = playlist_create();
optind = parse_cmdline_options(argc, argv, &options, file_opts);
audio_play_arg.devices = options.devices;
......@@ -300,27 +302,27 @@ int main(int argc, char **argv)
if (stat(argv[i], &stat_buf) == 0) {
if (S_ISDIR(stat_buf.st_mode)) {
if (playlist_append_directory(list, argv[i]) == 0)
if (playlist_append_directory(options.playlist, argv[i]) == 0)
fprintf(stderr,
_("Warning: Could not read directory %s.\n"), argv[i]);
} else {
playlist_append_file(list, argv[i]);
playlist_append_file(options.playlist, argv[i]);
}
} else /* If we can't stat it, it might be a non-disk source */
playlist_append_file(list, argv[i]);
playlist_append_file(options.playlist, argv[i]);
}
/* Do we have anything left to play? */
if (playlist_length(list) == 0) {
if (playlist_length(options.playlist) == 0) {
cmdline_usage();
exit(1);
} else {
playlist_array = playlist_to_array(list, &items);
playlist_destroy(list);
list = NULL;
playlist_array = playlist_to_array(options.playlist, &items);
playlist_destroy(options.playlist);
options.playlist = NULL;
}
/* Don't use status_message until after this point! */
......@@ -443,7 +445,7 @@ void play (char *source_string)
&decoder_callbacks,
decoder_callbacks_arg)) == NULL ) {
// We may have failed because of user command
/* We may have failed because of user command */
if (!sig_request.cancel)
status_error(_("Error opening %s using the %s module."
" The file may be corrupted.\n"), source_string,
......
......@@ -11,7 +11,7 @@
* *
********************************************************************
last mod: $Id: ogg123.h,v 1.13 2002/06/02 03:07:11 volsung Exp $
last mod: $Id: ogg123.h,v 1.14 2002/07/06 19:12:18 volsung Exp $
********************************************************************/
......@@ -20,6 +20,7 @@
#include <ogg/os_types.h>
#include "audio.h"
#include "playlist.h"
typedef struct ogg123_options_t {
long int verbosity; /* Verbose output if > 1, quiet if 0 */
......@@ -40,6 +41,8 @@ typedef struct ogg123_options_t {
audio_device_t *devices; /* Audio devices to use */
double status_freq; /* Number of status updates per second */
playlist_t *playlist; /* List of files to play */
} ogg123_options_t;
typedef struct signal_request_t {
......
......@@ -11,7 +11,7 @@
* *
********************************************************************
last mod: $Id: playlist.c,v 1.1 2002/07/06 03:23:13 volsung Exp $
last mod: $Id: playlist.c,v 1.2 2002/07/06 19:12:18 volsung Exp $
********************************************************************/
......@@ -172,29 +172,48 @@ int playlist_append_from_file(playlist_t *list, char *playlist_filename)
{
FILE *fp;
char filename[NAME_MAX+1];
struct stat stat_buf;
int length;
int i;
fp = fopen(playlist_filename, "r");
if (strcmp(playlist_filename, "-") == 0)
fp = stdin;
else
fp = fopen(playlist_filename, "r");
if (fp == NULL)
return 0;
while (!feof(fp)) {
fgets(filename, NAME_MAX+1 /* no, really! */, fp);
if ( fgets(filename, NAME_MAX+1 /* no, really! */, fp) == NULL )
continue;
filename[NAME_MAX] = '\0'; /* Just to make sure */
length = strlen(filename);
// Skip blank lines
/* Skip blank lines */
for (i = 0; i < length && isspace(filename[i]); i++);
if (i == length)
continue;
// Crop off last \n if present
/* Crop off last \n if present */
if (filename[length - 1] == '\n')
filename[length - 1] = '\0';
playlist_append_file(list, filename);
if (stat(filename, &stat_buf) == 0) {
if (S_ISDIR(stat_buf.st_mode)) {
if (playlist_append_directory(list, filename) == 0)
fprintf(stderr,
_("Warning from playlist %s: "
"Could not read directory %s.\n"), filename);
} else {
playlist_append_file(list, filename);
}
} else /* If we can't stat it, it might be a non-disk source */
playlist_append_file(list, filename);
}
return 1;
......@@ -208,7 +227,7 @@ int playlist_length(playlist_t *list)
playlist_element_t *element;
element = list->head;
length = 0; // don't count head node
length = 0; /* don't count head node */
while (element->next != NULL) {
length++;
element = element->next;
......
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