increased filename length from 32 to 256, we need this.
[my-code/mp3db.git] / mp3read.c
1 /* read mp3 header & tag, author: hackbard */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include <string.h>
10 #include <errno.h>
11
12 #define ID_TAG_SIZE 128
13 #define MAX_BUF_SIZE 32
14 #define MAX_TITLE 30
15 #define MAX_ARTIST 30
16 #define MAX_ALBUM 30
17 #define MAX_YEAR 4
18 #define MAX_COMMENT 30
19 #define MAX_GENRE 1
20
21 #define MAX_FILENAME 256
22
23
24 /*
25 info:
26 http://www.dv.co.yu/mpgscript/mpeghdr.htm
27 */
28
29 int main (int argc,char **argv)
30 {
31  int file_fd;
32  int file_size;
33  unsigned char buf[MAX_BUF_SIZE];
34  char filename[MAX_FILENAME];
35
36  memset(buf,0,sizeof(buf));
37
38  strcpy(filename,argv[1]);
39  file_size=atoi(argv[2]);
40
41  if((file_fd=open(filename,O_RDONLY))<=0) {
42   puts("open failed");
43   return -23;
44  }
45
46  if((lseek(file_fd,file_size-ID_TAG_SIZE,SEEK_SET))<0) {
47   puts("cannot seek to id tag");
48   return -23;
49  }
50
51  /* verify TAG now */
52  if((read(file_fd,&buf,3))<3) {
53   puts("read failed");
54   return -23;
55  }
56  if(strncmp(buf,"TAG",3)) {
57   puts("TAG not found");
58   return -23;
59  }
60
61  read(file_fd,&buf,MAX_TITLE);
62  buf[MAX_TITLE-1]=0;
63  printf("title: %s<br>\n",buf);
64
65  read(file_fd,&buf,MAX_ARTIST);
66  buf[MAX_ARTIST-1]=0;
67  printf("artist: %s<br>\n",buf);
68
69  read(file_fd,&buf,MAX_ALBUM);
70  buf[MAX_ALBUM-1]=0;
71  printf("album: %s<br>\n",buf);
72
73  // read(file_fd,&buf,MAX_YEAR);
74  // printf("year: %s<br>\n",buf);
75
76  // read(file_fd,&buf,MAX_COMMENT);
77  // printf("comment: %s<br>\n",buf);
78
79  // read(file_fd,&buf,MAX_GENRE);
80  // printf("genre: %d<br>\n",(int)*buf);
81
82  close(file_fd);
83  
84  return 23;
85 }