tracks.c

00001 
00023 #include "common.h"
00024 
00025 static void dump_trackinfo(LIBMTP_track_t *track)
00026 {
00027   printf("Track ID: %u\n", track->item_id);
00028   if (track->title != NULL)
00029     printf("   Title: %s\n", track->title);
00030   if (track->artist != NULL)
00031     printf("   Artist: %s\n", track->artist);
00032   if (track->genre != NULL)
00033     printf("   Genre: %s\n", track->genre);
00034   if (track->album != NULL)
00035     printf("   Album: %s\n", track->album);
00036   if (track->date != NULL)
00037     printf("   Date: %s\n", track->date);
00038   if (track->filename != NULL)
00039     printf("   Origfilename: %s\n", track->filename);
00040   printf("   Track number: %d\n", track->tracknumber);
00041   printf("   Duration: %d milliseconds\n", track->duration);
00042 #ifdef __WIN32__
00043   printf("   File size %I64u bytes\n", track->filesize);
00044 #else
00045   printf("   File size %llu bytes\n", track->filesize);
00046 #endif
00047   printf("   Filetype: %s\n", LIBMTP_Get_Filetype_Description(track->filetype));
00048   if (track->samplerate != 0) {
00049     printf("   Sample rate: %u Hz\n", track->samplerate);
00050   }
00051   if (track->nochannels != 0) {
00052     printf("   Number of channels: %u\n", track->nochannels);
00053   }
00054   if (track->wavecodec != 0) {
00055     printf("   WAVE fourCC code: 0x%08X\n", track->wavecodec);
00056   }
00057   if (track->bitrate != 0) {
00058     printf("   Bitrate: %u bits/s\n", track->bitrate);
00059   }
00060   if (track->bitratetype != 0) {
00061     if (track->bitratetype == 1) {
00062       printf("   Bitrate type: Constant\n");
00063     } else if (track->bitratetype == 2) {
00064       printf("   Bitrate type: Variable (VBR)\n");
00065     } else if (track->bitratetype == 3) {
00066       printf("   Bitrate type: Free\n");
00067     } else {
00068       printf("   Bitrate type: Unknown/Erroneous value\n");
00069     }
00070   }
00071   if (track->rating != 0) {
00072     printf("   User rating: %u (out of 100)\n", track->rating);
00073   }
00074   if (track->usecount != 0) {
00075     printf("   Use count: %u times\n", track->usecount);
00076   }
00077 }
00078 
00079 int main (int argc, char **argv)
00080 {
00081   LIBMTP_mtpdevice_t *device_list, *iter;
00082   LIBMTP_track_t *tracks;
00083 
00084   LIBMTP_Init();
00085   fprintf(stdout, "Attempting to connect device(s)\n");
00086 
00087   switch(LIBMTP_Get_Connected_Devices(&device_list))
00088   {
00089   case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
00090     fprintf(stdout, "mtp-folders: No Devices have been found\n");
00091     return 0;
00092   case LIBMTP_ERROR_CONNECTING:
00093     fprintf(stderr, "mtp-folders: There has been an error connecting. Exit\n");
00094     return 1;
00095   case LIBMTP_ERROR_MEMORY_ALLOCATION:
00096     fprintf(stderr, "mtp-folders: Memory Allocation Error. Exit\n");
00097     return 1;
00098  
00099   /* Unknown general errors - This should never execute */
00100   case LIBMTP_ERROR_GENERAL:
00101   default:
00102     fprintf(stderr, "mtp-folders: Unknown error, please report "
00103                     "this to the libmtp developers\n");
00104   return 1;
00105 
00106   /* Successfully connected at least one device, so continue */
00107   case LIBMTP_ERROR_NONE:
00108     fprintf(stdout, "mtp-folders: Successfully connected\n");
00109     fflush(stdout);
00110   }
00111   
00112   /* iterate through connected MTP devices */
00113   for(iter = device_list; iter != NULL; iter = iter->next)
00114   {
00115         char *friendlyname;
00116     /* Echo the friendly name so we know which device we are working with */
00117     friendlyname = LIBMTP_Get_Friendlyname(iter);
00118     if (friendlyname == NULL) {
00119       printf("Friendly name: (NULL)\n");
00120     } else {
00121       printf("Friendly name: %s\n", friendlyname);
00122       free(friendlyname);
00123     }
00124   
00125           // Get track listing.
00126           tracks = LIBMTP_Get_Tracklisting_With_Callback(iter, NULL, NULL);
00127           if (tracks == NULL) {
00128             printf("No tracks.\n");
00129           } else {
00130             LIBMTP_track_t *track, *tmp;
00131             track = tracks;
00132             while (track != NULL) {
00133               dump_trackinfo(track);
00134               tmp = track;
00135               track = track->next;
00136               LIBMTP_destroy_track_t(tmp);
00137             }
00138           }
00139   }
00140     
00141   LIBMTP_Release_Device_List(device_list);
00142   printf("OK.\n");
00143   exit (0);
00144 }
00145 

Generated on Mon Aug 27 14:50:26 2007 for libmtp by  doxygen 1.5.3