日期:2013-09-28  浏览次数:21030 次

<!--METADATA TYPE="typelib"
UUID="00000205-0000-0010-8000-00AA006D2EA4"
NAME="ADODB Type Library"
-->
<%
'Author: 小龙 zyvslxl,zyvslxl@163.com 请保留
'需指定的属性
'Path 文件的路径
'类头部分定义的属性为可以得到信息,当然不止这个,理论上可以返回任何标签值
'在Id3v2() 中的Select case FrameId(i)部分加入已知的标签,可以返回相应的内容
'因为个人知识有限,会的话请指教


'可用方法
'CreateStream 打开文件流
'pre 执行
'CloseStream 关闭文件流

Class mp3

Public Path
Public Flag
Public Title '标题
Public Artist '作者
Public Album '专集
Public IssueYear '出品年代
Public Comment '备注
Public Genre '类型
Public Tcon '流派
Public MpTime '时间
Public USLT '歌词
Private objStream


'[待扩展]
private Function Exitext()
Dim ext
ext = lcase(right(path,len(path)-inStrRev(".")))
Exitext = ext
End Function


'[转换函数,有些类型还是判断不了]
private Function bin2str(binstr,num)
on error resume next
Dim varlen,clow,ccc,skipflag ,i,biy
skipflag=0
ccc = ""
For i=1 To num
clow = MidB(binstr,i,1)
If ascb(clow)=0 then
skipflag=0
' ccc = null
Else
If skipflag=0 Then
If AscB(clow) > 127 Then
ccc =ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))
skipflag=1
Else
ccc = ccc & Chr(AscB(clow))
End If
Else
skipflag=0
End If

End If
Next
bin2str = ccc
End Function


'[载入文件]
Public Function CreateStream()
on error resume next
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open
Err.clear
objStream.LoadFromFile Path
If err<>0 Then
objStream.LoadFromFile server.mappath(Path)
End If
Err.clear
End Function

'[关闭文件流]
Public Function CloseStream()
objStream.close
Set objStream = nothing
End Function


'[标志信息]
Public Function id()
Dim Comm
objStream.position =0
Comm = objStream.Read(3)
id = bin2str(Comm)
End Function


'[ID3V2信息读取]
Private Function Id3v2()
Dim FrameID()
Dim FrameSize()
Dim FrameSize1()
Dim Flags()
Dim Frame()
Dim MaxSize
Dim i
i = 0

objStream.position = 6
MaxSize = TopSize(objStream.Read(4))
'response.write "<font color=red>"&MaxSize&"</font><br>"


Do While ObjStream.Position < MaxSize
ReDim Preserve FrameID(i),FrameSize(i),FrameSize1(i),Flags(i),Frame(i)
FrameID(i) = bin2str(objStream.Read(4),4)
If Isnull (FrameId(i)) or FrameId(i)="" Then Exit Do
FrameSize(i) = Size(objStream.Read(4))
If Isnull (FrameSize(i)) or FrameSize(i)= 0 Then Exit Do
objStream.Read(2) '[Flag]
'objStream.Read(1)
Frame(i) = bin2str(objStream.Read(FrameSize(i)),FrameSize(i))
i = i+1
Loop

'[依次赋值给属性]
Dim j
j = i-1
For i = 0 to j
'response.write i
Select case Ucase(FrameId(i))
Case "TIT2" : Title = cstr(Frame(i))
Case "COMM" : Comment = cstr(Frame(i))
Case "TPE1" : Artist = cstr(Frame(i))
Case "