From d1a2e263d9ec0571615fcabde93ff8ca33c16d62 Mon Sep 17 00:00:00 2001 From: hackbard Date: Thu, 17 Apr 2003 14:51:32 +0000 Subject: [PATCH] initial check in of TAG info c source and shell wrapper --- INSTALL | 4 ++- Makefile | 13 +++++++++ mp3read.c | 84 +++++++++++++++++++++++++++++++----------------------- readtag.sh | 8 ++++++ 4 files changed, 72 insertions(+), 37 deletions(-) create mode 100644 Makefile create mode 100755 readtag.sh diff --git a/INSTALL b/INSTALL index 76861c2..a430f17 100644 --- a/INSTALL +++ b/INSTALL @@ -7,6 +7,8 @@ include main.shtml in your existing webpage. it needs physical contact to the mp3 data. exchange all entries in main.shtml reading index.shtml to the file sourcing this main.shtml file. +build mp3read executing a simple "make". +copy readtag.sh and mp3read in your $PATH location. 2) @@ -20,7 +22,7 @@ adjust the examples !! important, defaults won't work !! 4) -make your mp3 data is mp3db compatible. +make sure your mp3 data is mp3db compatible. that means, no special character and small letters. you may test ./make_mp3dbcompat script to do so. this will definetly fuck your system, i mean it :) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1cc1c80 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +# Makefile of mp3read.c + +INCLUDEDIR = /usr/include + +CFLAGS = -O3 -Wall +LIBS = + +OBJS = mp3read + +all: mp3read + +clean: + rm $(OBJS) diff --git a/mp3read.c b/mp3read.c index 0236f31..b8c527f 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,9 +9,17 @@ #include #include -#define MAX_READ 1024 +#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 -#define MAX_VER_ID 64 + /* info: @@ -19,51 +28,54 @@ http://www.dv.co.yu/mpgscript/mpeghdr.htm int main (int argc,char **argv) { - int file_fd,exit,count; - unsigned char buf; - unsigned char header[3]; - char mpeg_ver_id[MAX_VER_ID]; + int file_fd; + int file_size; + unsigned char buf[MAX_BUF_SIZE]; char filename[MAX_FILENAME]; strcpy(filename,argv[1]); + file_size=atoi(argv[2]); if((file_fd=open(filename,O_RDONLY))<=0) { puts("open failed"); return -23; } - count=0; - exit=0; - while(!exit) { - printf("count=%d\n",count++); - read(file_fd,&buf,1); - if(buf==0xff) { - read(file_fd,&buf,1); - if(buf>=0xe0) { - puts("got frame header:"); - exit=1; - header[0]=buf; - read(file_fd,header+1,2); - - printf("debug: %x%x%x \n",header[0],header[1],header[2]); - - if(((header[0]&0x18)>>3)==0x00) strcpy(mpeg_ver_id,"MPEG Version 2.5"); - else if(((header[0]&0x18)>>3)==0x10) strcpy(mpeg_ver_id,"MPEG Version 2 (ISO/IEC 13818-3)"); - else if(((header[0]&0x18)>>3)==0x11) strcpy(mpeg_ver_id,"MPEG Version 1 (ISO/IEC 11172-3)"); - else strcpy(mpeg_ver_id,"unknown"); - - printf("version: %s\n",mpeg_ver_id); - } - } + 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 (1)"); + 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: %c\n",*buf); + close(file_fd); - puts(""); - puts("done"); - return 23; } - - - diff --git a/readtag.sh b/readtag.sh new file mode 100755 index 0000000..972ae5d --- /dev/null +++ b/readtag.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# read the tag using mp3read + +size=`ls -al $1 | awk '{ printf $5 }'` + +./mp3read $1 $size + -- 2.20.1