MP3ID3Msg类

谢绝转载,违者必纠


<%
Dim MP3ID3Msg
' 建立类对象
Set MP3ID3Msg = New clsMP3ID3Msg
MP3ID3Msg.File="这些年来.mp3"
Call MP3ID3Msg.GetID3Msg
Response.write "TAG类型: " & MP3ID3Msg.ID3Type & "<br>"
Response.write "<hr>"
If MP3ID3Msg.ID3Type="ID3v1" Then
 Response.write "标题: " & MP3ID3Msg.Title & "<br>"
 Response.write "艺术家: " & MP3ID3Msg.Artist & "<br>"
 Response.write "专集: " & MP3ID3Msg.Album & "<br>"
 Response.write "出品年代: " & MP3ID3Msg.IssueYear & "<br>"
 Response.write "备注: " & MP3ID3Msg.Comment & "<br>"
 Response.write "类型: " & MP3ID3Msg.Genre & "<br>"
ElseIf MP3ID3Msg.ID3Type="ID3v2" Then
 Response.write "标题: " & MP3ID3Msg.Title & "<br>"
 Response.write "艺术家: " & MP3ID3Msg.Artist & "<br>"
 Response.write "专集: " & MP3ID3Msg.Album & "<br>"
 Response.write "出品年代: " & MP3ID3Msg.IssueYear & "<br>"
 Response.write "流派: " & MP3ID3Msg.Tcon & "<br>"
 Response.write "音轨号: " & MP3ID3Msg.Track & "<br>"
 Response.write "时间: " & MP3ID3Msg.MpTime & "<br>"
 Response.write "版权: " & MP3ID3Msg.CopyRight & "<br>"
 Response.write "歌词: " & Replace(MP3ID3Msg.USLT,vbCrLf,"<br>") & "<br>"
 Response.write "备注: " & MP3ID3Msg.Comment & "<br>"
End If
Set MP3ID3Msg = Nothing
%>
<Script RunAt="Server" Language="VBScript">
'==========================================================================
'名称:MP3ID3Msg类
'功能:MP3ID3 Tag信息读取
'运行环境:ADO 2.5以上
'作者:jimzhu 请保留
'版本:2.0
'日期:2004-12-08

'需指定的属性
'File 文件的路径
'类头部分定义的属性为可以得到信息,当然不止这个,理论上可以返回任何标签值

'可用方法
'GetID3Msg 执行
'==========================================================================
Class clsMP3ID3Msg
 Private objStream
 Private m_File,m_ID3Type
 Private m_Title,m_Artist,m_Album,m_IssueYear,m_Comment
 Private m_Genre,m_Tcon,m_MpTime,m_Track,m_USLT,m_CopyRight
 Private Sub Class_Initialize
  m_File = vbNullString
 End Sub

 Property Let File(ByVal value)
  If GetFileExt(value)=".mp3" Then m_File=value
    End Property
 'ID3Type
 Property Get ID3Type()
  ID3Type=m_ID3Type
    End Property
 '标题
 Property Get Title()
  Title=m_Title
    End Property
 '歌手/作者
 Property Get Artist()
  Artist=m_Artist
    End Property
 '专集
 Property Get Album()
  Album=m_Album
    End Property
 '出品年代
 Property Get IssueYear()
  IssueYear=m_IssueYear
    End Property
 '备注
 Property Get Comment()
  Comment=m_Comment
    End Property
 '类型
 Property Get Genre()
  Genre=m_Genre
    End Property
 '流派
 Property Get Tcon()
  Tcon=m_Tcon
    End Property
 '时间
 Property Get MpTime()
  MpTime=m_MpTime
    End Property
 '音轨
 Property Get Track()
  Track=m_Track
    End Property
 '歌词
 Property Get USLT()
  USLT=m_USLT
    End Property
 '版权
 Property Get CopyRight()
  CopyRight=m_CopyRight
    End Property

 '[优先返回ID3V2版本信息]
 Sub GetID3Msg()
  If m_File<>"" Then
   Set objStream = Server.CreateObject("ADODB.Stream")
   With objStream
    .Type = 1 'adTypeBinary
    .Open
    .LoadFromFile Server.MapPath(m_File)
    '[判断ID3版本 只区分ID3v1和ID3v2]
'    .Position = 0
    If Ucase(Bin2Str(.Read(3)))="ID3" Then
     m_ID3Type="ID3v2"
     Call GetId3v2
    Else
     .Position = .Size - 128
     If Bin2Str(.Read(3)) = "TAG" Then
      m_ID3Type="ID3v1"
      '[ID3V1信息读取]
      m_Title = Bin2Str(.Read(30))
      m_Artist = Bin2Str(.Read(30))
      m_Album = Bin2Str(.Read(30))
      m_IssueYear = Bin2Str(.Read(4))
      m_Comment = Bin2Str(.Read(30))
      m_Genre = Bin2Str(.Read(3))
     Else
      m_ID3Type="No Tag"
     End If
    End If
    .Close
   End With
   Set objStream = Nothing
  End If
 End Sub

 '[ID3V2信息读取]
 Private Sub GetId3v2()
  Dim FrameID,FrameSize
  Dim MaxSize
  With objStream
   .Position = 6
   MaxSize = TopSize(.Read(4))
   Do While .Position < MaxSize
    FrameID = Bin2Str(.Read(4))
    If IsNull(FrameID) or FrameID="" Then Exit Do
    FrameSize = GetFrameSize(.Read(4))
    If FrameSize= 0 Then
     Exit Do
    Else
     .Position = .Position + 2 '[Flag]
     '[赋值给属性]
     Select case Ucase(FrameID)
      Case "TIT2" : m_Title = Bin2Str(.Read(FrameSize))
      Case "TPE1" : m_Artist = Bin2Str(.Read(FrameSize))
      Case "TALB" : m_Album = Bin2Str(.Read(FrameSize))
      Case "TYER" : m_IssueYear = Bin2Str(.Read(FrameSize))
      Case "COMM" : m_Comment = Bin2Str(.Read(FrameSize))
      Case "TCON" : m_Tcon = Bin2Str(.Read(FrameSize))
      Case "TLEN" : m_MpTime = FormatTime(CLng(Bin2Str(.Read(FrameSize)))/1000)
      Case "USLT" : m_USLT = Bin2Str(.Read(FrameSize))
      Case "TRCK" : m_Track = Bin2Str(.Read(FrameSize))
      Case "TCOP" : m_CopyRight = Bin2Str(.Read(FrameSize))
      Case Else
' Frame = Bin2Str(.Read(FrameSize))
' Response.write FrameID & ":" & Frame & "<br>"
 'TENC:
       .Position = .Position + FrameSize
     End Select
    End If
   Loop
  End With
 End Sub

 '[获取头标签长度/标签总长度]
 Private Function FormatTime(ByVal TotolSec)
  Dim iMin,iSec,sRet
  sRet=vbNullString
  iMin=TotolSec / 60
  iSec=TotolSec Mod 60
  If iSec<10 Then
   sRet=sRet & iMin & ":0" & iSec
  Else
   sRet=sRet & iMin & ":" & iSec
  End If
  FormatTime=sRet
 End Function

 '[转换函数,有些类型还是判断不了]
 Private Function Bin2Str(ByVal BinStr)
'  on error resume next
  Dim iChar,iCharLow,sRet,i,iLen
  sRet = vbNullString
  iLen=LenB(binstr)
  For i=1 To iLen
   iChar=AscB(MidB(BinStr,i,1))
   If iChar > 127 Then
    i=i+1
    If i<=iLen Then sRet =sRet & Chr(iChar*&H100 + AscB(MidB(BinStr,i,1)))
 '    sRet =sRet & Chr(AscW(MidB(binstr,i+1,1) & sChar))
   Else
    If iChar<>0 Then sRet = sRet & Chr(iChar)
   End If
  Next
  Bin2Str = sRet
 End Function

 '[获取ID3v2头标签长度(标签总长度)]
 Private Function TopSize(ByVal Num)
  TopSize = 0
  Dim a,b,c,d
  a = Midb(Num,1,1)
  b = Midb(Num,2,1)
  c = Midb(Num,3,1)
  d = Midb(Num,4,1)
  If Not IsNull(a) Then TopSize=AscB(a) * 2097152
  If Not IsNull(b) Then TopSize=TopSize + AscB(b) * 1024
  If Not IsNull(c) Then TopSize=TopSize + AscB(c) * 128
  If Not IsNull(d) Then TopSize=TopSize + AscB(d)
 End Function

 '[获取标签帧长度(某个具体标签内容长度)]
 Private Function GetFrameSize(ByVal Num)
  GetFrameSize=0
  Dim a,b,c,d
  a = midb(Num,1,1)
  b = midb(Num,2,1)
  c = midb(Num,3,1)
  d = midb(Num,4,1)
  If Not IsNull(a) Then GetFrameSize=AscB(a) * 4294967296
  If Not IsNull(b) Then GetFrameSize=GetFrameSize + AscB(b) * 65536
  If Not IsNull(c) Then GetFrameSize=GetFrameSize + AscB(c) * 256
  If Not IsNull(d) Then GetFrameSize=GetFrameSize + AscB(d)
 End Function

 '[获取文件名后缀]
 Private Function GetFileExt(ByVal FullPath)
  Dim iTmp
  GetFileExt = ""
  iTmp=InStrRev(FullPath, ".")
  If Not iTmp Then GetFileExt = LCase(Mid(FullPath,iTmp))
 End Function
End Class
</SCRIPT>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值