projects
/
my-code
/
mp3db.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
do not print year/comment/genre (commented out)
[my-code/mp3db.git]
/
mp3read.c
diff --git
a/mp3read.c
b/mp3read.c
index
dd61d86
..
4bfc290
100644
(file)
--- a/
mp3read.c
+++ b/
mp3read.c
@@
-1,40
+1,80
@@
-/* read mp3
info,
hackbard */
+/* read mp3
header & tag, author:
hackbard */
#include <stdio.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
+#include <errno.h>
-#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 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];
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((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;
}
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);
+ printf("title: %s<br>\n",buf);
+
+ read(file_fd,&buf,MAX_ARTIST);
+ printf("artist: %s<br>\n",buf);
+
+ read(file_fd,&buf,MAX_ALBUM);
+ printf("album: %s<br>\n",buf);
+ // read(file_fd,&buf,MAX_YEAR);
+ // printf("year: %s<br>\n",buf);
+ // read(file_fd,&buf,MAX_COMMENT);
+ // printf("comment: %s<br>\n",buf);
+ // read(file_fd,&buf,MAX_GENRE);
+ // printf("genre: %d<br>\n",(int)*buf);
+
+ close(file_fd);
+
+ return 23;
+}