libnjb: playlists.c

- Main Page
- Modules
- Data Structures
- Files
- Directories
- Examples

# playlists.c

    00001 #include "common.h"
    00002 #include <string.h>
    00003
    00004 static void playlist_dump (njb_playlist_t *pl, FILE *fp)
    00005 {
    00006   njb_playlist_track_t *track;
    00007   unsigned int i = 1;
    00008
    00009   fprintf(fp, "Playlist: %s\n", pl->name);
    00010   fprintf(fp, "ID:       %u\n", pl->plid);
    00011   fprintf(fp, "Tracks:   %u\n", pl->ntracks);
    00012   fprintf(fp, "State:    %d\n", pl->_state);
    00013
    00014   NJB_Playlist_Reset_Gettrack(pl);
    00015   while ( (track = NJB_Playlist_Gettrack(pl)) ) {
    00016     fprintf(fp, "%5u - track ID %u\n", i, track->trackid);
    00017     i++;
    00018   }
    00019 }
    00020
    00021 int main (int argc, char **argv)
    00022 {
    00023   njb_t njbs[NJB_MAX_DEVICES], *njb;
    00024   int n, debug;
    00025   njb_playlist_t *playlist;
    00026   extern char *optarg;
    00027   int opt;
    00028   char *lang;
    00029
    00030   debug = 0;
    00031   while ( (opt= getopt(argc, argv, "D:")) != -1 ) {
    00032     switch (opt) {
    00033     case 'D':
    00034       debug= atoi(optarg);
    00035       break;
    00036     default:
    00037       fprintf(stderr, "usage: playlists [ -D debuglvl ]\n");
    00038       return 1;
    00039     }
    00040   }
    00041
    00042   if ( debug ) NJB_Set_Debug(debug);
    00043
    00044   /*
    00045    * Check environment variables $LANG and $LC_CTYPE
    00046    * to see if we want to support UTF-8 unicode
    00047    * $LANG = "xx_XX.UTF-8" or $LC_CTYPE = "?"
    00048    * trigger unicode support.
    00049    */
    00050   lang = getenv("LANG");
    00051   if (lang != NULL) {
    00052     if (strlen(lang) > 5) {
    00053       if (!strcmp(&lang[strlen(lang)-5], "UTF-8")) {
    00054         NJB_Set_Unicode(NJB_UC_UTF8);
    00055       }
    00056     }
    00057   }
    00058
    00059   if (NJB_Discover(njbs, 0, &n) == -1) {
    00060     fprintf(stderr, "could not locate any jukeboxes\n");
    00061     return 1;
    00062   }
    00063
    00064   if ( n == 0 ) {
    00065     fprintf(stderr, "no NJB devices found\n");
    00066     return 0;
    00067   }
    00068
    00069   njb = njbs;
    00070
    00071   if ( NJB_Open(njb) == -1 ) {
    00072     NJB_Error_Dump(njb,stderr);
    00073     return 1;
    00074   }
    00075
    00076   if ( NJB_Capture(njb) == -1 ) {
    00077     NJB_Error_Dump(njb,stderr);
    00078     return 1;
    00079   }
    00080
    00081   NJB_Reset_Get_Playlist(njb);
    00082   n = 0;
    00083   while ( (playlist = NJB_Get_Playlist(njb)) ) {
    00084     playlist_dump(playlist, stdout);
    00085     printf("----------------------------------\n");
    00086     n ++;
    00087   }
    00088
    00089   /* Dump any pending errors */
    00090   if (NJB_Error_Pending(njb)) {
    00091     NJB_Error_Dump(njb,stderr);
    00092   }
    00093
    00094   printf("Total: %d playlists\n", n);
    00095
    00096   NJB_Release(njb);
    00097
    00098   NJB_Close(njb);
    00099   return 0;
    00100 }
    00101