initial check in of TAG info c source and shell wrapper
[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 32
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  strcpy(filename,argv[1]);
37  file_size=atoi(argv[2]);
38
39  if((file_fd=open(filename,O_RDONLY))<=0) {
40   puts("open failed");
41   return -23;
42  }
43
44  if((lseek(file_fd,file_size-ID_TAG_SIZE,SEEK_SET))<0) {
45   puts("cannot seek to id tag");
46   return -23;
47  }
48
49  /* verify TAG now */
50  if((read(file_fd,&buf,3))<3) {
51   puts("read failed (1)");
52   return -23;
53  }
54
55  if(strncmp(buf,"TAG",3)) {
56   puts("TAG not found");
57   return -23;
58  }
59
60  read(file_fd,&buf,MAX_TITLE);
61  printf("title: %s\n",buf);
62
63  read(file_fd,&buf,MAX_ARTIST);
64  printf("artist: %s\n",buf);
65
66  read(file_fd,&buf,MAX_ALBUM);
67  printf("album: %s\n",buf);
68
69  read(file_fd,&buf,MAX_YEAR);
70  printf("year: %s\n",buf);
71
72  read(file_fd,&buf,MAX_COMMENT);
73  printf("comment: %s\n",buf);
74
75  read(file_fd,&buf,MAX_GENRE);
76  printf("genre: %c\n",*buf);
77
78  close(file_fd);
79  
80  return 23;
81 }