【发布时间】:2016-11-05 15:38:26
【问题描述】:
此代码用于读取一个 mp3 文件 ID3V1 标签。但我有一个包含几个 MP3 文件的目录。我想添加一些东西,允许我的程序读取目录中的所有 MP3 文件。 然后我必须将所有 ID3V1 标签导出到 CSV 文件中。
我不知道该怎么做,任何帮助将不胜感激。
#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 one file: %s <song.mp3> \n", argv[0] );
} type FILE,
file = fopen("song.mp3", "rb");
if (file == NULL) {
printf("I couldn't open: %s for 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 the 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 to get the Tags\n");
return EXIT_FAILURE;
}
fclose(file);
return 0;
}
}
}
【问题讨论】:
标签: c