You could access this page securely.

API documentation for libmpg123, libout123, and libsyn123

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, NEWS.libout123, NEWS.libsyn123, and the overall NEWS file on libmpg123 versions and important changes between them.
Let me emphasize that the policy for the lib*123 family 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.
1 /*
2  id3dump: Print ID3 tags of files, scanned using libmpg123.
3 
4  copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1
5  see COPYING and AUTHORS files in distribution or http://mpg123.org
6  initially written by Thomas Orgis
7 */
8 
9 #include "mpg123.h"
10 #include <string.h>
11 #include "stdio.h"
12 #include "sys/types.h"
13 
14 /* Helper for v1 printing, get these strings their zero byte. */
15 void safe_print(char* name, char *data, size_t size)
16 {
17  char safe[31];
18  if(size>30) return;
19 
20  memcpy(safe, data, size);
21  safe[size] = 0;
22  printf("%s: %s\n", name, safe);
23 }
24 
25 /* Print out ID3v1 info. */
26 void print_v1(mpg123_id3v1 *v1)
27 {
28  safe_print("Title", v1->title, sizeof(v1->title));
29  safe_print("Artist", v1->artist, sizeof(v1->artist));
30  safe_print("Album", v1->album, sizeof(v1->album));
31  safe_print("Year", v1->year, sizeof(v1->year));
32  safe_print("Comment", v1->comment, sizeof(v1->comment));
33  printf("Genre: %i", v1->genre);
34 }
35 
36 /* Split up a number of lines separated by \n, \r, both or just zero byte
37  and print out each line with specified prefix. */
38 void print_lines(const char* prefix, mpg123_string *inlines)
39 {
40  size_t i;
41  int hadcr = 0, hadlf = 0;
42  char *lines = NULL;
43  char *line = NULL;
44  size_t len = 0;
45 
46  if(inlines != NULL && inlines->fill)
47  {
48  lines = inlines->p;
49  len = inlines->fill;
50  }
51  else return;
52 
53  line = lines;
54  for(i=0; i<len; ++i)
55  {
56  if(lines[i] == '\n' || lines[i] == '\r' || lines[i] == 0)
57  {
58  char save = lines[i]; /* saving, changing, restoring a byte in the data */
59  if(save == '\n') ++hadlf;
60  if(save == '\r') ++hadcr;
61  if((hadcr || hadlf) && hadlf % 2 == 0 && hadcr % 2 == 0) line = "";
62 
63  if(line)
64  {
65  lines[i] = 0;
66  printf("%s%s\n", prefix, line);
67  line = NULL;
68  lines[i] = save;
69  }
70  }
71  else
72  {
73  hadlf = hadcr = 0;
74  if(line == NULL) line = lines+i;
75  }
76  }
77 }
78 
79 /* Print out the named ID3v2 fields. */
80 void print_v2(mpg123_id3v2 *v2)
81 {
82  print_lines("Title: ", v2->title);
83  print_lines("Artist: ", v2->artist);
84  print_lines("Album: ", v2->album);
85  print_lines("Year: ", v2->year);
86  print_lines("Comment: ", v2->comment);
87  print_lines("Genre: ", v2->genre);
88 }
89 
90 /* Print out all stored ID3v2 fields with their 4-character IDs. */
91 void print_raw_v2(mpg123_id3v2 *v2)
92 {
93  size_t i;
94  for(i=0; i<v2->texts; ++i)
95  {
96  char id[5];
97  char lang[4];
98  memcpy(id, v2->text[i].id, 4);
99  id[4] = 0;
100  memcpy(lang, v2->text[i].lang, 3);
101  lang[3] = 0;
102  if(v2->text[i].description.fill)
103  printf("%s language(%s) description(%s)\n", id, lang, v2->text[i].description.p);
104  else printf("%s language(%s)\n", id, lang);
105 
106  print_lines(" ", &v2->text[i].text);
107  }
108  for(i=0; i<v2->extras; ++i)
109  {
110  char id[5];
111  memcpy(id, v2->extra[i].id, 4);
112  id[4] = 0;
113  printf( "%s description(%s)\n",
114  id,
115  v2->extra[i].description.fill ? v2->extra[i].description.p : "" );
116  print_lines(" ", &v2->extra[i].text);
117  }
118  for(i=0; i<v2->comments; ++i)
119  {
120  char id[5];
121  char lang[4];
122  memcpy(id, v2->comment_list[i].id, 4);
123  id[4] = 0;
124  memcpy(lang, v2->comment_list[i].lang, 3);
125  lang[3] = 0;
126  printf( "%s description(%s) language(%s): \n",
127  id,
128  v2->comment_list[i].description.fill ? v2->comment_list[i].description.p : "",
129  lang );
130  print_lines(" ", &v2->comment_list[i].text);
131  }
132 }
133 
134 int main(int argc, char **argv)
135 {
136  int i;
137  mpg123_handle* m;
138  if(argc < 2)
139  {
140  fprintf(stderr, "\nI will print some ID3 tag fields of MPEG audio files.\n");
141  fprintf(stderr, "\nUsage: %s <mpeg audio file list>\n\n", argv[0]);
142  return -1;
143  }
144  mpg123_init();
145  m = mpg123_new(NULL, NULL);
146 
147  for(i=1; i < argc; ++i)
148  {
149  mpg123_id3v1 *v1;
150  mpg123_id3v2 *v2;
151  int meta;
152  if(mpg123_open(m, argv[i]) != MPG123_OK)
153  {
154  fprintf(stderr, "Cannot open %s: %s\n", argv[i], mpg123_strerror(m));
155  continue;
156  }
157  mpg123_scan(m);
158  meta = mpg123_meta_check(m);
159  if(meta & MPG123_ID3 && mpg123_id3(m, &v1, &v2) == MPG123_OK)
160  {
161  printf("Tag data on %s:\n", argv[i]);
162  printf("\n==== ID3v1 ====\n");
163  if(v1 != NULL) print_v1(v1);
164 
165  printf("\n==== ID3v2 ====\n");
166  if(v2 != NULL) print_v2(v2);
167 
168  printf("\n==== ID3v2 Raw frames ====\n");
169  if(v2 != NULL) print_raw_v2(v2);
170  }
171  else printf("Nothing found for %s.\n", argv[i]);
172 
173  mpg123_close(m);
174  }
175  mpg123_delete(m);
176  mpg123_exit();
177  return 0;
178 }
struct mpg123_handle_struct mpg123_handle
Definition: mpg123.h:132
size_t fill
Definition: mpg123.h:1211
size_t texts
Definition: mpg123.h:1457
char artist[30]
Definition: mpg123.h:1473
mpg123_string * comment
Definition: mpg123.h:1451
unsigned char genre
Definition: mpg123.h:1477
MPG123_EXPORT void mpg123_exit(void)
char year[4]
Definition: mpg123.h:1475
MPG123_EXPORT int mpg123_meta_check(mpg123_handle *mh)
MPG123_EXPORT int mpg123_id3(mpg123_handle *mh, mpg123_id3v1 **v1, mpg123_id3v2 **v2)
size_t extras
Definition: mpg123.h:1459
mpg123_string * artist
Definition: mpg123.h:1447
mpg123_string * genre
Definition: mpg123.h:1450
MPG123_EXPORT const char * mpg123_strerror(mpg123_handle *mh)
size_t comments
Definition: mpg123.h:1455
MPG123_EXPORT int mpg123_close(mpg123_handle *mh)
mpg123_string text
Definition: mpg123.h:1396
mpg123_text * extra
Definition: mpg123.h:1458
MPG123_EXPORT int mpg123_init(void)
char * p
Definition: mpg123.h:1209
mpg123_text * text
Definition: mpg123.h:1456
char comment[30]
Definition: mpg123.h:1476
mpg123_string * album
Definition: mpg123.h:1448
char title[30]
Definition: mpg123.h:1472
MPG123_EXPORT void mpg123_delete(mpg123_handle *mh)
mpg123_text * comment_list
Definition: mpg123.h:1454
mpg123_string description
Definition: mpg123.h:1395
char id[4]
Definition: mpg123.h:1394
mpg123_string * year
Definition: mpg123.h:1449
MPG123_EXPORT mpg123_handle * mpg123_new(const char *decoder, int *error)
MPG123_EXPORT int mpg123_scan(mpg123_handle *mh)
MPG123_EXPORT int mpg123_open(mpg123_handle *mh, const char *path)
char lang[3]
Definition: mpg123.h:1393
char album[30]
Definition: mpg123.h:1474
#define MPG123_ID3
Definition: mpg123.h:1480
mpg123_string * title
Definition: mpg123.h:1446
Hopefully valid HTML! Valid CSS!