libnjb: playlists.c

libnjb 2.2.7

playlists.c
#include "common.h"
#include <string.h>
static void playlist_dump (njb_playlist_t *pl, FILE *fp)
{
njb_playlist_track_t *track;
unsigned int i = 1;
fprintf(fp, "Playlist: %s\n", pl->name);
fprintf(fp, "ID: %u\n", pl->plid);
fprintf(fp, "Tracks: %u\n", pl->ntracks);
fprintf(fp, "State: %d\n", pl->_state);
NJB_Playlist_Reset_Gettrack(pl);
while ( (track = NJB_Playlist_Gettrack(pl)) ) {
fprintf(fp, "%5u - track ID %u\n", i, track->trackid);
i++;
}
}
int main (int argc, char **argv)
{
njb_t njbs[NJB_MAX_DEVICES], *njb;
int n, debug;
njb_playlist_t *playlist;
extern char *optarg;
int opt;
char *lang;
debug = 0;
while ( (opt= getopt(argc, argv, "D:")) != -1 ) {
switch (opt) {
case 'D':
debug= atoi(optarg);
break;
default:
fprintf(stderr, "usage: playlists [ -D debuglvl ]\n");
return 1;
}
}
if ( debug ) NJB_Set_Debug(debug);
/*
* Check environment variables $LANG and $LC_CTYPE
* to see if we want to support UTF-8 unicode
* $LANG = "xx_XX.UTF-8" or $LC_CTYPE = "?"
* trigger unicode support.
*/
lang = getenv("LANG");
if (lang != NULL) {
if (strlen(lang) > 5) {
if (!strcmp(&lang[strlen(lang)-5], "UTF-8")) {
NJB_Set_Unicode(NJB_UC_UTF8);
}
}
}
if (NJB_Discover(njbs, 0, &n) == -1) {
fprintf(stderr, "could not locate any jukeboxes\n");
return 1;
}
if ( n == 0 ) {
fprintf(stderr, "no NJB devices found\n");
return 0;
}
njb = njbs;
if ( NJB_Open(njb) == -1 ) {
NJB_Error_Dump(njb,stderr);
return 1;
}
if ( NJB_Capture(njb) == -1 ) {
NJB_Error_Dump(njb,stderr);
return 1;
}
NJB_Reset_Get_Playlist(njb);
n = 0;
while ( (playlist = NJB_Get_Playlist(njb)) ) {
playlist_dump(playlist, stdout);
printf("----------------------------------\n");
n ++;
}
/* Dump any pending errors */
if (NJB_Error_Pending(njb)) {
NJB_Error_Dump(njb,stderr);
}
printf("Total: %d playlists\n", n);
NJB_Release(njb);
NJB_Close(njb);
return 0;
}
NJB_Discover
int NJB_Discover(njb_t *njbs, int limit, int *n)
Definition: procedure.c:108
njb_playlist_struct::plid
u_int32_t plid
Definition: libnjb.h:255
njb_playlist_struct::ntracks
u_int32_t ntracks
Definition: libnjb.h:254
NJB_UC_UTF8
#define NJB_UC_UTF8
Definition: libnjb.h:147
NJB_Error_Pending
int NJB_Error_Pending(njb_t *njb)
Definition: njb_error.c:303
NJB_Open
int NJB_Open(njb_t *njb)
Definition: procedure.c:130
NJB_Close
void NJB_Close(njb_t *njb)
Definition: procedure.c:184
NJB_Playlist_Gettrack
njb_playlist_track_t * NJB_Playlist_Gettrack(njb_playlist_t *pl)
Definition: playlist.c:377
njb_struct
Definition: libnjb.h:182
NJB_Playlist_Reset_Gettrack
void NJB_Playlist_Reset_Gettrack(njb_playlist_t *pl)
Definition: playlist.c:354
NJB_Set_Unicode
void NJB_Set_Unicode(int unicode_flag)
Definition: procedure.c:2833
NJB_Capture
int NJB_Capture(njb_t *njb)
Definition: procedure.c:223
NJB_Reset_Get_Playlist
void NJB_Reset_Get_Playlist(njb_t *njb)
Definition: procedure.c:556
njb_playlist_track_struct::trackid
u_int32_t trackid
Definition: libnjb.h:238
NJB_Get_Playlist
njb_playlist_t * NJB_Get_Playlist(njb_t *njb)
Definition: procedure.c:592
njb_playlist_struct
Definition: libnjb.h:247
NJB_MAX_DEVICES
#define NJB_MAX_DEVICES
Definition: libnjb.h:60
njb_playlist_track_struct
Definition: libnjb.h:237
NJB_Set_Debug
void NJB_Set_Debug(int debug_flags)
Definition: procedure.c:2819
NJB_Error_Dump
void NJB_Error_Dump(njb_t *njb, FILE *fp)
Definition: njb_error.c:418
NJB_Release
int NJB_Release(njb_t *njb)
Definition: procedure.c:266
njb_playlist_struct::name
char * name
Definition: libnjb.h:248
njb_playlist_struct::_state
int _state
Definition: libnjb.h:249