Make ID3v2 output take less vertical space From: Petr Baudis The tags are collapsed to two-column output where possible, and blank lines and tabs indentation is removed. --- src/id3.c | 46 +++++++++++++++++++++++++++++++++++++--------- 1 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/id3.c b/src/id3.c index b7f2bc6..13cbc22 100644 --- a/src/id3.c +++ b/src/id3.c @@ -649,16 +649,44 @@ void print_id3_tag(unsigned char *id3v1b if(id3.version > 1) { - fprintf(stderr,"\n"); /* print id3v2 */ - /* dammed, I use pointers as bool again! It's so convenient... */ - fprintf(stderr,"\tTitle: %s\n", id3.title.fill ? id3.title.p : ""); - fprintf(stderr,"\tArtist: %s\n", id3.artist.fill ? id3.artist.p : ""); - fprintf(stderr,"\tAlbum: %s\n", id3.album.fill ? id3.album.p : ""); - fprintf(stderr,"\tYear: %s\n", id3.year.fill ? id3.year.p : ""); - fprintf(stderr,"\tGenre: %s\n", id3.genre.fill ? id3.genre.p : ""); - fprintf(stderr,"\tComment: %s\n", id3.comment.fill ? id3.comment.p : ""); - fprintf(stderr,"\n"); + /* We are trying to be smart here and conserve vertical space. + * So we will skip tags not set, and try to show them in two + * parallel columns if they are short, which is by far the + * most common case. */ + if (id3.title.fill && id3.artist.fill && strlen(id3.title.p) <= 30 && strlen(id3.title.p) <= 30) + { + fprintf(stderr,"Title : %-30s Artist: %s\n",id3.title.p,id3.artist.p); + } + else + { + if (id3.title.fill) + fprintf(stderr,"Title : %s\n", id3.title.p); + if (id3.artist.fill) + fprintf(stderr,"Artist : %s\n", id3.artist.p); + } + if (id3.comment.fill && id3.album.fill && strlen(id3.comment.p) <= 30 && strlen(id3.album.p) <= 30) + { + fprintf(stderr,"Comment: %-30s Album : %s\n",id3.comment.p,id3.album.p); + } + else + { + if (id3.comment.fill) + fprintf(stderr,"Comment: %s\n", id3.comment.p); + if (id3.album.fill) + fprintf(stderr,"Album : %s\n", id3.album.p); + } + if (id3.year.fill && id3.genre.fill && strlen(id3.year.p) <= 30 && strlen(id3.genre.p) <= 30) + { + fprintf(stderr,"Year : %-30s Genre : %s\n",id3.year.p,id3.genre.p); + } + else + { + if (id3.year.fill) + fprintf(stderr,"Year : %s\n", id3.year.p); + if (id3.genre.fill) + fprintf(stderr,"Genre : %s\n", id3.genre.p); + } } else if(id3v1buf != NULL) {