| 1 |
/* Just printing out ID3 tags with plain data from libmpg123 and explicitly called conversion routine. */ |
| 2 |
|
| 3 |
#include "config.h" |
| 4 |
#include "../compat/compat.h" |
| 5 |
#include <mpg123.h> |
| 6 |
#include "../common/debug.h" |
| 7 |
|
| 8 |
int test_whence(const char* path, int scan_before) |
| 9 |
{ |
| 10 |
int err = MPG123_OK; |
| 11 |
mpg123_handle* mh = NULL; |
| 12 |
off_t length, pos; |
| 13 |
|
| 14 |
mh = mpg123_new(NULL, &err ); |
| 15 |
if(mh == NULL) return -1; |
| 16 |
|
| 17 |
err = mpg123_open(mh, path ); |
| 18 |
if(err != MPG123_OK) return -1; |
| 19 |
|
| 20 |
if(scan_before) mpg123_scan(mh); |
| 21 |
|
| 22 |
pos = mpg123_seek( mh, 0, SEEK_END); |
| 23 |
if(pos < 0){ error1("seek failed: %s", mpg123_strerror(mh)); return -1; } |
| 24 |
|
| 25 |
pos = mpg123_tell(mh); |
| 26 |
length = mpg123_length(mh); |
| 27 |
|
| 28 |
/* Later: Read samples and compare different whence values with identical seek positions. */ |
| 29 |
|
| 30 |
mpg123_close(mh); |
| 31 |
mpg123_delete(mh); |
| 32 |
|
| 33 |
fprintf(stdout, "length %" PRIiMAX " vs. pos %" PRIiMAX "\n", (intmax_t)length, (intmax_t)pos); |
| 34 |
|
| 35 |
return (pos == length) ? 0 : -1; |
| 36 |
} |
| 37 |
|
| 38 |
void print_field(const char *name, mpg123_string *sb) |
| 39 |
{ |
| 40 |
const unsigned char *sbp = (unsigned char*)sb->p; |
| 41 |
enum mpg123_text_encoding enc; |
| 42 |
mpg123_string printer; |
| 43 |
mpg123_init_string(&printer); |
| 44 |
printf("\n=== %s ===\n", name); |
| 45 |
if(sb->fill == 0) |
| 46 |
{ |
| 47 |
printf("Oh, empty. Totally.\n"); |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
enc = mpg123_enc_from_id3(sbp[0]); |
| 52 |
|
| 53 |
printf("From encoding: %i (in ID3: %i)\n", enc, (int)sbp[0]) ; |
| 54 |
if(mpg123_store_utf8(&printer, enc, sbp+1, sb->fill-1)) |
| 55 |
{ |
| 56 |
/* Not caring for multiple strings separated via null bytes here. */ |
| 57 |
printf("Value: %s\n", printer.p); |
| 58 |
} |
| 59 |
else error("Conversion failed!"); |
| 60 |
mpg123_free_string(&printer); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
int main(int argc, char **argv) |
| 65 |
{ |
| 66 |
int err; |
| 67 |
int ret = 0; |
| 68 |
mpg123_handle *mh; |
| 69 |
mpg123_id3v2 *id3; |
| 70 |
|
| 71 |
if(argc < 2) |
| 72 |
{ |
| 73 |
printf("Gimme a MPEG file name...\n"); |
| 74 |
return 0; |
| 75 |
} |
| 76 |
|
| 77 |
mpg123_init(); |
| 78 |
mh = mpg123_new(NULL, &err); |
| 79 |
if(err != MPG123_OK) goto badend; |
| 80 |
|
| 81 |
mpg123_param(mh, MPG123_ADD_FLAGS, MPG123_PLAIN_ID3TEXT, 0.); |
| 82 |
|
| 83 |
err = mpg123_open(mh, argv[1]); |
| 84 |
if(err != MPG123_OK) goto badend; |
| 85 |
|
| 86 |
err = mpg123_scan(mh); |
| 87 |
if(err != MPG123_OK) goto badend; |
| 88 |
|
| 89 |
err = mpg123_id3(mh, NULL, &id3); |
| 90 |
if(err != MPG123_OK) goto badend; |
| 91 |
|
| 92 |
if(id3 == NULL) |
| 93 |
{ |
| 94 |
error("No ID3 data found."); |
| 95 |
goto badend; |
| 96 |
} |
| 97 |
|
| 98 |
print_field("artist", id3->artist); |
| 99 |
print_field("title", id3->title); |
| 100 |
print_field("album", id3->album); |
| 101 |
print_field("comment", id3->comment); |
| 102 |
|
| 103 |
goto end; |
| 104 |
badend: |
| 105 |
ret = -1; |
| 106 |
end: |
| 107 |
mpg123_delete(mh); |
| 108 |
mpg123_exit(); |
| 109 |
return ret; |
| 110 |
} |