X-Git-Url: https://www.hackdaworld.org/gitweb/?a=blobdiff_plain;f=mp3read.c;h=4bfc290b7da65ffd7b50b82a649ce0011df3778b;hb=0f5e4be79b8be5bc756b7267156d0db5ec705419;hp=52d08f1e06f94b96c07be8cdb9e2d436e1ef5b41;hpb=69e5e4016a673ba184eaabb1a20c1b516717cd6a;p=my-code%2Fmp3db.git diff --git a/mp3read.c b/mp3read.c index 52d08f1..4bfc290 100644 --- a/mp3read.c +++ b/mp3read.c @@ -1,6 +1,7 @@ -/* read mp3 info, hackbard */ +/* read mp3 header & tag, author: hackbard */ #include +#include #include #include #include @@ -8,44 +9,72 @@ #include #include -#define MAX_READ 1024 -#define MAX_FILENAME 30 +#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,n_exit,count; - char buf; + int file_fd; + int file_size; + unsigned char buf[MAX_BUF_SIZE]; char filename[MAX_FILENAME]; strcpy(filename,argv[1]); - printf("test: %s\n",filename); + file_size=atoi(argv[2]); if((file_fd=open(filename,O_RDONLY))<=0) { puts("open failed"); return -23; } - if((lseek(file_fd,atoi(argv[2])-MAX_READ,SEEK_SET))<0) { - perror("lseek"); + if((lseek(file_fd,file_size-ID_TAG_SIZE,SEEK_SET))<0) { + puts("cannot seek to id tag"); return -23; } - count=1; - n_exit=1; - while(n_exit) { - n_exit=read(file_fd,&buf,1); - count++; - putchar(buf); - if(count==MAX_READ) break; + /* 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; + } + + 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: %d
\n",(int)*buf); close(file_fd); - puts(""); - puts("done"); - return 23; } - - -