mpg123 logo
download : svn :: features :: sf.net project - bug tracker :: news archive
libmpg123 API :: hacking :: testing :: benchmarking :: FAQ :: links :: contact
Note: This API doc is automatically generated from the current development version that you can get via Subversion or as a daily snapshot from http://mpg123.org/snapshot. There may be differences (additions) compared to the latest stable release. See NEWS.libmpg123 and the overall NEWS file on libmpg123 versions and important changes between them.
Let me emphasize that the policy for libmpg123 is to always stay backwards compatible -- only additions are planned (and it's not yet planned to change the plans;-).

id3dump.c

Go to the documentation of this file.
00001 /*
00002         id3dump: Print ID3 tags of files, scanned using libmpg123.
00003 
00004         copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1
00005         see COPYING and AUTHORS files in distribution or http://mpg123.org
00006         initially written by Thomas Orgis
00007 */
00008 
00009 #include "mpg123.h"
00010 #include <string.h>
00011 #include "stdio.h"
00012 #include "sys/types.h"
00013 
00014 /* Helper for v1 printing, get these strings their zero byte. */
00015 void safe_print(char* name, char *data, size_t size)
00016 {
00017         char safe[31];
00018         if(size>30) return;
00019 
00020         memcpy(safe, data, size);
00021         safe[size] = 0;
00022         printf("%s: %s\n", name, safe);
00023 }
00024 
00025 /* Print out ID3v1 info. */
00026 void print_v1(mpg123_id3v1 *v1)
00027 {
00028         safe_print("Title",   v1->title,   sizeof(v1->title));
00029         safe_print("Artist",  v1->artist,  sizeof(v1->artist));
00030         safe_print("Album",   v1->album,   sizeof(v1->album));
00031         safe_print("Year",    v1->year,    sizeof(v1->year));
00032         safe_print("Comment", v1->comment, sizeof(v1->comment));
00033         printf("Genre: %i", v1->genre);
00034 }
00035 
00036 /* Split up a number of lines separated by \n, \r, both or just zero byte
00037    and print out each line with specified prefix. */
00038 void print_lines(const char* prefix, mpg123_string *inlines)
00039 {
00040         size_t i;
00041         int hadcr = 0, hadlf = 0;
00042         char *lines = NULL;
00043         char *line  = NULL;
00044         size_t len = 0;
00045 
00046         if(inlines != NULL && inlines->fill)
00047         {
00048                 lines = inlines->p;
00049                 len   = inlines->fill;
00050         }
00051         else return;
00052 
00053         line = lines;
00054         for(i=0; i<len; ++i)
00055         {
00056                 if(lines[i] == '\n' || lines[i] == '\r' || lines[i] == 0)
00057                 {
00058                         char save = lines[i]; /* saving, changing, restoring a byte in the data */
00059                         if(save == '\n') ++hadlf;
00060                         if(save == '\r') ++hadcr;
00061                         if((hadcr || hadlf) && hadlf % 2 == 0 && hadcr % 2 == 0) line = "";
00062 
00063                         if(line)
00064                         {
00065                                 lines[i] = 0;
00066                                 printf("%s%s\n", prefix, line);
00067                                 line = NULL;
00068                                 lines[i] = save;
00069                         }
00070                 }
00071                 else
00072                 {
00073                         hadlf = hadcr = 0;
00074                         if(line == NULL) line = lines+i;
00075                 }
00076         }
00077 }
00078 
00079 /* Print out the named ID3v2  fields. */
00080 void print_v2(mpg123_id3v2 *v2)
00081 {
00082         print_lines("Title: ",   v2->title);
00083         print_lines("Artist: ",  v2->artist);
00084         print_lines("Album: ",   v2->album);
00085         print_lines("Year: ",    v2->year);
00086         print_lines("Comment: ", v2->comment);
00087         print_lines("Genre: ",   v2->genre);
00088 }
00089 
00090 /* Print out all stored ID3v2 fields with their 4-character IDs. */
00091 void print_raw_v2(mpg123_id3v2 *v2)
00092 {
00093         size_t i;
00094         for(i=0; i<v2->texts; ++i)
00095         {
00096                 char id[5];
00097                 memcpy(id, v2->text[i].id, 4);
00098                 id[4] = 0;
00099                 printf("%s\n", id);
00100                 print_lines(" ", &v2->text[i].text);
00101         }
00102         for(i=0; i<v2->extras; ++i)
00103         {
00104                 char id[5];
00105                 memcpy(id, v2->extra[i].id, 4);
00106                 id[4] = 0;
00107                 printf( "%s description(%s)\n",
00108                         id,
00109                         v2->extra[i].description.fill ? v2->extra[i].description.p : "" );
00110                 print_lines(" ", &v2->extra[i].text);
00111         }
00112         for(i=0; i<v2->comments; ++i)
00113         {
00114                 char id[5];
00115                 char lang[4];
00116                 memcpy(id, v2->comment_list[i].id, 4);
00117                 id[4] = 0;
00118                 memcpy(lang, v2->comment_list[i].lang, 3);
00119                 lang[3] = 0;
00120                 printf( "%s description(%s) language(%s): \n",
00121                         id,
00122                         v2->comment_list[i].description.fill ? v2->comment_list[i].description.p : "",
00123                         lang );
00124                 print_lines(" ", &v2->comment_list[i].text);
00125         }
00126 }
00127 
00128 int main(int argc, char **argv)
00129 {
00130         int i;
00131         mpg123_handle* m;
00132         if(argc < 2)
00133         {
00134                 fprintf(stderr, "\nI will print some ID3 tag fields of MPEG audio files.\n");
00135                 fprintf(stderr, "\nUsage: %s <mpeg audio file list>\n\n", argv[0]);
00136                 return -1;
00137         }
00138         mpg123_init();
00139         m = mpg123_new(NULL, NULL);
00140 
00141         for(i=1; i < argc; ++i)
00142         {
00143                 mpg123_id3v1 *v1;
00144                 mpg123_id3v2 *v2;
00145                 int meta;
00146                 if(mpg123_open(m, argv[i]) != MPG123_OK)
00147                 {
00148                         fprintf(stderr, "Cannot open %s: %s\n", argv[i], mpg123_strerror(m));
00149                         continue;
00150                 }
00151                 mpg123_scan(m);
00152                 meta = mpg123_meta_check(m);
00153                 if(meta & MPG123_ID3 && mpg123_id3(m, &v1, &v2) == MPG123_OK)
00154                 {
00155                         printf("Tag data on %s:\n", argv[i]);
00156                         printf("\n====      ID3v1       ====\n");
00157                         if(v1 != NULL) print_v1(v1);
00158 
00159                         printf("\n====      ID3v2       ====\n");
00160                         if(v2 != NULL) print_v2(v2);
00161 
00162                         printf("\n==== ID3v2 Raw frames ====\n");
00163                         if(v2 != NULL) print_raw_v2(v2);
00164                 }
00165                 else printf("Nothing found for %s.\n", argv[i]);
00166 
00167                 mpg123_close(m);
00168         }
00169         mpg123_delete(m);
00170         mpg123_exit();
00171         return 0;
00172 }

Generated on Mon Feb 6 01:07:20 2012 for libmpg123 by  doxygen 1.5.6