/* * Dump the contents of the player. Takes a single parameter: the * mount-point of the player. */ #include #include #include #include #include #include #include #include #include #include #include #include int main( int argc, char *argv[] ) { GList *devs = NULL; gchar *mountpoint = NULL, *devicepath = NULL; guint8 verbose = 0; int val; nw_device_t *dev; nw_api_t api = NW_GUESS; while (( val = getopt( argc, argv, "12m:d:v" )) != -1 ) { switch( val ) { case '?': case ':': /* getopt will produce an error for me, thanks */ exit( 1 ); break; case 'm': mountpoint = optarg; break; case 'd': devicepath = optarg; break; case 'v': verbose++; break; case '1': api = NW_MPLE; break; case '2': api = NW_MPLE_V2; break; default: fprintf( stderr, "invalid option %c\n", val ); exit( 1 ); break; } } /* old usage: sole parameter is the mountpoint */ if ( optind == argc - 1 ) { mountpoint = argv[optind]; } if ( mountpoint == NULL && devicepath == NULL ) { /* Go for auto-probe */ guint32 d = 0; fprintf( stderr, "no device specified, auto-probing..." ); devs = nw_get_devs( NULL ); if ( g_list_length( devs ) == 0 ) { fprintf( stderr, "no device found\n" ); exit( 1 ); } else { fprintf( stderr, "done\n" ); } if ( g_list_length( devs ) > 1 ) { fprintf( stderr, "More than one device found, please be more specific : \n" ); while( g_list_nth( devs, d )) { nw_device_t *dv = g_list_nth_data( devs, d ); fprintf( stderr, " %s", (gchar *)nw_get_attr( dv, "device" )); if ( nw_get_attr( dv, "mountpoint" ) != NULL ) { fprintf( stderr, " (mounted at %s)", (gchar *)nw_get_attr( dv, "mountpoint" )); } fprintf( stderr, "\n" ); nw_dev_free( dv ); d++; } g_list_free( devs ); exit( 1 ); } else { dev = g_list_nth_data( devs, d ); fprintf( stderr, "Using device %s", (gchar *)nw_get_attr( dev, "device" )); if ( nw_get_attr( dev, "mountpoint" ) != NULL ) { fprintf( stderr, " (mounted at %s)", (gchar *)nw_get_attr( dev, "mountpoint" )); } fprintf( stderr, "\n" ); } } else { dev = nw_dev_init( mountpoint, api ); } if ( dev != NULL ) { guint32 folder = 0; nw_folder_t *fptr; /* XXX if ( nw_get_attr( dev, "media serial number" ) == NULL ) { if ( nw_get_attr( dev, "device" ) == NULL ) { fprintf( stderr, "unable to identify device %s\n", devicepath ); exit( 1 ); } } */ if ( nw_parse_directory( dev ) == NULL ) { if ( errno ) { fprintf( stderr, "error getting directory: %s\n", strerror( errno )); exit( 1 ); } /* otherwise it's just an empty device */ } /* print out header info */ if ( verbose ) { if ( nw_get_attr( dev, "device" )) { fprintf( stderr, "device: %s\n", (gchar *)nw_get_attr( dev, "device" )); } else { fprintf( stderr, "device: N/A\n" ); } #if 0 switch( dev->api ) { case NW_MPLE: fprintf( stderr, "serial: %08X\n", ((mple_device *)dev)->msn ); fprintf( stderr, "tstamp: %ld -> %s", ((mple_device *)dev)->timestamp, ctime( &(((mple_device *)dev)->timestamp ))); fprintf( stderr, "magic : %08x\n", ((mple_device *)dev)->magic ); fprintf( stderr, "\n" ); break; default: fprintf( stderr, "no aux data\n" ); break; } #endif } if ( nw_get_folderlist( dev ) == NULL ) { fprintf( stderr, "No files on device.\n" ); } else { while(( fptr = g_list_nth_data( nw_get_folderlist( dev ), folder++ )) != NULL ) { guint32 track = 0; nw_track_t *tptr; guint32 running = 0; fprintf( stdout, "Folder: %s\n", nw_get_folder_name( fptr )); if ( nw_get_folder_tracklist( fptr ) == NULL ) { fprintf( stdout, " empty folder\n" ); continue; } while (( tptr = g_list_nth_data( nw_get_folder_tracklist( fptr ), track++ )) != NULL ) { guint32 time; id3_utf8_t *filename = NULL; filename = nw_get_tag( tptr, NW_FILENAME ); fprintf( stdout, " Track %d: %s\n", nw_get_tracknum( tptr ), filename ? (gchar *)filename : "unset" ); if ( filename != NULL ) { g_free( filename ); } if ( verbose ) { id3_utf8_t *fullpath = NULL, *title = NULL, *artist = NULL; title = nw_get_tag( tptr, ID3_FRAME_TITLE ); artist = nw_get_tag( tptr, ID3_FRAME_ARTIST ); fprintf( stdout, " Title: %s\n", title ? (char *)title : "unset" ); fprintf( stdout, " Artist: %s\n", artist ? (char *)artist : "unset" ); fullpath = nw_get_tag( tptr, NW_FULLPATH ); if ( fullpath ) { fprintf( stdout, " Device file: %s\n", (char *)fullpath ); } if ( title ) { g_free( title ); } if ( artist ) { g_free( artist ); } /* now dig out the data from the file's header */ time = nw_track_time( tptr ); fprintf( stdout, " %ub / %02u:%02u.%03u / %u frames\n", nw_track_size( tptr ), time / ( 60 * 1000 ), ( time / 1000 ) % 60, time % 1000, nw_track_frames( tptr )); running += time; } } if ( verbose ) { fprintf( stdout, "\nTotal running time %02u:%02u.%03u\n", running / ( 60 * 1000 ), ( running / 1000 ) % 60, running % 1000 ); } } } nw_dev_free( dev ); dev = NULL; } if ( devs != NULL ) { g_list_free( devs ); } return 0; }