c - Read Tags for few MP3 files -
this code work read 1 mp3 file id3v1 tags. have directory few mp3 files. add allow program read mp3 files in directory. , have export id3v1 tags csv file.
i don't know how that, appreciated.
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct{ char tag[3]; char title[30]; char artist[30]; char album[30]; char year[4]; char comment[30]; unsigned char genre; }mp3info; int main (int argc, char *argv[]) { if ( argc != 1 ) { printf( "please choose 1 file: %s <song.mp3> \n", argv[0] ); } type file, file = fopen("song.mp3", "rb"); if (file == null) { printf("i couldn't open: %s reading.\n"); exit(0); } else { mp3info tag_in; fseek(file, -sizeof(mp3info), seek_end); if (fread(&tag_in, sizeof(mp3info), 1, file) != 1) { printf("could not read tag\n"); exit (0); } if (memcmp(tag_in.tag, "tag", 3) == 0) { printf("title: %.30s\n", tag_in.title); printf("artist: %.30s\n", tag_in.artist); printf("album: %.30s\n", tag_in.album); printf("year: %.4s\n", tag_in.year); if (tag_in.comment[28] == '\0') { printf("comment: %.28s\n", tag_in.comment); printf("track: %d\n", tag_in.comment[29]); } else { printf("comment: %.30s\n", tag_in.comment); } printf("genre: %d\n", tag_in.genre); } else { fprintf(stderr, "the program has failed tags\n"); return exit_failure; } fclose(file); return 0; } } }
in order keep things short i'll link relevant answers can combine solve problem.
the first thing should list files in directory, shown here how can list of files in directory using c or c++?
once got that, should loop through files (which explained on previous link), check ones mp3 files. simple way (although not best one) check extension, shown here getting file extension in c each mp3 file find, use code parse it, , instead of using printf
write csv file.
as csv file, format simple enough can use fprintf
or fwrite
write everything. if planning read data microsoft excel not forget put sep=,
@ top of file or won't read correctly, happened me once (it work fine on libreoffice without it)
Comments
Post a Comment