Sorry to bother you with a newbie question (I have no idea of C programming...): I'm running Litestream, an alternative lightweight Shoutcast streaming utility on my server, but I would like to modify it, so that it doesn't only write the file name that is currently played to regular server logs, but also to a single text file, so I can proccess it with PHP and display a "Now Playing" window on my website.
Here's the file that needs to be modified (playlist.c)
Thanks a lot for you help in advance!Code:#include <stdio.h> #include <string.h> #include <errno.h> #include "stream_std.h" #include "playlist.h" #include "textutils.h" extern int last_played; FILE* open_next_file(char* _files[], int _nfiles, int* _curfile) { int startfile = *_curfile; FILE* fp; char message[1024]; if (last_played) { stream_msg("finished playlist"); return(NULL); } do { fp = fopen(_files[*_curfile], "r"); if (!fp) { sprintf(message, "could not open %s", _files[*_curfile]); stream_err(message); } else { sprintf(message, "opened %s", _files[*_curfile]); stream_msg(message); } *_curfile = (*_curfile + 1) % _nfiles; /* check for playlist wrap-around */ if (0 == *_curfile) last_played = 1; if (fp) break; if (*_curfile == startfile) { stream_msg("no reasonable files found"); return(NULL); } } while (!fp); return(fp); } playlist* read_playlist(const char* _filename) { FILE* fp; playlist* list; char filename[1024]; char comparison[1024]; list = (playlist*) malloc(sizeof(playlist)); list->used = 0; list->size = 16; list->names = (char**) malloc(sizeof(char*) * list->size); /* test for filename of *.mp3 */ strncpy(filename, _filename, 1024); strncpy(comparison, stripspaces(filename, LEADING | TRAILING), 1024); if ((strlen(comparison) > 4) && !strncmp(comparison + (strlen(comparison)-4), ".mp3", 1020)) { /* found a simple mp3 file */ if (list->used == list->size) { list->size *= 2; list->names = (char**) realloc(list->names, sizeof(char*) * list->size); } list->names[list->used++] = strdup(stripspaces(filename, LEADING | TRAILING)); } else { if (!(fp = fopen(_filename, "r"))) return(NULL); while (!feof(fp) && !ferror(fp)) { if (!(fgets(filename, sizeof(filename), fp))) break; if (list->used == list->size) { list->size *= 2; list->names = (char**) realloc(list->names, sizeof(char*) * list->size); } list->names[list->used++] = strdup(stripspaces(filename, LEADING | TRAILING)); } fclose(fp); } return(list); }
Litestream Source Download



LinkBack URL
About LinkBacks



You saved me many time of trial and error work. It's working perfectly now.