X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=mp3read.c;h=b8c527f1988e9b9d364e65e8f775e21f636a2e43;hb=9c00ad2aa1bc641e9d390e6121b2807e6f851ab3;hp=dd61d86f175bf87f909fdcfa3f68ccefe2790635;hpb=86da6d4566b8433c0d628545e4551ce500ce67c8;p=my-code%2Fmp3db.git diff --git a/mp3read.c b/mp3read.c index dd61d86..b8c527f 100644 --- a/mp3read.c +++ b/mp3read.c @@ -1,40 +1,81 @@ -/* read mp3 info, hackbard */ +/* read mp3 header & tag, author: hackbard */ #include +#include #include #include #include #include #include +#include -#define MAX_READ 1024 -#define MAX_FILENAME 256 +#define ID_TAG_SIZE 128 +#define MAX_BUF_SIZE 32 +#define MAX_TITLE 30 +#define MAX_ARTIST 30 +#define MAX_ALBUM 30 +#define MAX_YEAR 4 +#define MAX_COMMENT 30 +#define MAX_GENRE 1 + +#define MAX_FILENAME 32 + + +/* +info: +http://www.dv.co.yu/mpgscript/mpeghdr.htm +*/ int main (int argc,char **argv) { - int file_fd; /* desc fir file */ - char buf[MAX_READ]; /* buffer for the actual info */ + int file_fd; + int file_size; + unsigned char buf[MAX_BUF_SIZE]; char filename[MAX_FILENAME]; - strcpy(argv[1],filename); + strcpy(filename,argv[1]); + file_size=atoi(argv[2]); if((file_fd=open(filename,O_RDONLY))<=0) { puts("open failed"); return -23; } - if((read(file_fd,&buf,MAX_READ))<=MAX_READ) { - puts("read failed"); + if((lseek(file_fd,file_size-ID_TAG_SIZE,SEEK_SET))<0) { + puts("cannot seek to id tag"); return -23; } - printf(" -> %s",buf); - - puts(""); - puts("done"); - - return 23; -} + /* verify TAG now */ + if((read(file_fd,&buf,3))<3) { + puts("read failed (1)"); + return -23; + } + if(strncmp(buf,"TAG",3)) { + puts("TAG not found"); + return -23; + } + + read(file_fd,&buf,MAX_TITLE); + printf("title: %s\n",buf); + + read(file_fd,&buf,MAX_ARTIST); + printf("artist: %s\n",buf); + + read(file_fd,&buf,MAX_ALBUM); + printf("album: %s\n",buf); + + read(file_fd,&buf,MAX_YEAR); + printf("year: %s\n",buf); + read(file_fd,&buf,MAX_COMMENT); + printf("comment: %s\n",buf); + read(file_fd,&buf,MAX_GENRE); + printf("genre: %c\n",*buf); + + close(file_fd); + + return 23; +}