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

Generated on Sat Dec 27 18:59:14 2008 for libmtp by  doxygen 1.5.3