X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fmp3db.git;a=blobdiff_plain;f=mp3read.c;h=af6dfdd30494b55d8f9f88963e4edf3f65f6811f;hp=dd61d86f175bf87f909fdcfa3f68ccefe2790635;hb=HEAD;hpb=86da6d4566b8433c0d628545e4551ce500ce67c8 diff --git a/mp3read.c b/mp3read.c index dd61d86..af6dfdd 100644 --- a/mp3read.c +++ b/mp3read.c @@ -1,40 +1,85 @@ -/* read mp3 info, hackbard */ +/* read mp3 header & tag, author: hackbard */ #include +#include #include #include #include #include #include +#include + +#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_READ 1024 #define MAX_FILENAME 256 + +/* +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); + memset(buf,0,sizeof(buf)); + + 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) { + if((lseek(file_fd,file_size-ID_TAG_SIZE,SEEK_SET))<0) { + puts("cannot seek to id tag"); + return -23; + } + + /* verify TAG now */ + if((read(file_fd,&buf,3))<3) { puts("read failed"); return -23; } + if(strncmp(buf,"TAG",3)) { + puts("TAG not found"); + return -23; + } - printf(" -> %s",buf); - - puts(""); - puts("done"); - - return 23; -} + read(file_fd,&buf,MAX_TITLE); + buf[MAX_TITLE-1]=0; + printf("title: %s
\n",buf); + + read(file_fd,&buf,MAX_ARTIST); + buf[MAX_ARTIST-1]=0; + printf("artist: %s
\n",buf); + + read(file_fd,&buf,MAX_ALBUM); + buf[MAX_ALBUM-1]=0; + 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: %d
\n",(int)*buf); + + close(file_fd); + + return 23; +}