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

Generated on Mon Aug 13 13:48:42 2007 for libmtp by  doxygen 1.5.2