asp读取wma文件Tag的类

网上搜了下,只找到了个PHP的类,只好照葫芦画瓢写了一个,目前只完成了读取的功能,由于本人水平有限,如有写得不妥的地方,还请各位能帮忙指出

类主文件:wmaExif.class.asp
  1. <%
  2. 'Author: dragonbbc
  3. 'Email: dragonbbc@163.com
  4. '参考文章:
  5. 'http://linle.ycool.com/post.1255557.html
  6. 'http://www.itlearner.com/Article/2007/3944.shtml
  7. '需指定的属性
  8. 'File
  9. '可用方法
  10. 'CheckSize  检查文件大小
  11. 'Parse  读取信息
  12. 'GetInfo(TagName)
  13. '常见TagName
  14. '标准Tag: Title, Artist, Copyright, Description
  15. '扩展Tag: WM/AlbumTitle, WM/EncodedBy, WM/Genre, WM/Lyrics, WM/Track, WM/Year, WM/URL, WM/UserWebURL, WMFSDKVersion, WM/TrackNumber
  16. Class wmaExif
  17.     Public File '文件
  18.     
  19.     Private objStream
  20.     Private headtag, bodytag, std_tag, ext_tag
  21.     Private headsize,headext1,tagnum,headext2,headbuf,bodysize,bodybuf
  22.     Private framebuf(),sectionbuf()
  23.     Private items1, items2
  24.     Private Sub Class_Initialize()
  25.     headtag = "3026b2758e66cf11a6d900aa0062ce6c"
  26.     bodytag = "3626b2758e66cf11a6d900aa0062ce6c"
  27.     std_tag = "3326b2758e66cf11a6d900aa0062ce6c"
  28.     ext_tag = "40a4d0d207e3d21197f000a0c95ea850"
  29.     items1 = Array("Title""Artist""Copyright""Description""Reserved")
  30.     'items2 = Array("AlbumTitle", "EncodedBy", "Genre", "Lyrics", "Track", _
  31.     '                            "Year", "URL", "UserWebURL", "TrackNumber")
  32.     End Sub
  33.   Private Sub Class_Terminate
  34.     on error resume next
  35.     CloseStream
  36.   End Sub
  37.     
  38. 'GetInfo
  39.     Public Function GetInfo(TagName)
  40.         TagName = Replace(TagName, "/""")
  41.         If Eval("Not IsEmpty("&TagName&")"Then
  42.             Execute("GetInfo = "&TagName)
  43.         End If
  44.     End Function
  45. 'CheckSize
  46.     Public Function CheckSize()
  47.         CheckSize = False
  48.         CreateStream
  49.         If ReadHeader = False Then Exit Function
  50.         If ReadBody = False Then Exit Function
  51.         If objStream.Size <> headsize + bodysize Then Exit Function
  52.         CheckSize = True
  53.         CloseStream
  54.     End Function
  55. 'Parse
  56.     Public Function Parse()
  57.         CreateStream
  58.         If ReadHeader = False Then Exit Function
  59.         ReDim framebuf(tagnum)
  60.         head_off = 1
  61.         For j = 1 To tagnum
  62.             frame_head = MidB(headbuf, head_off, 24)
  63.             head_off = head_off + 24
  64.             frametag = ReadHex(LeftB(frame_head, 16))
  65.             framesize = ReadLong_UL(MidB(frame_head,17,4))
  66.             'framebuf(j) = MidB(headbuf,head_off-24,framesize)
  67.             If frametag = std_tag Then
  68.                 Dim lenx(5)
  69.                 tmp_off = 0
  70.                 For i = 0 To 4
  71.                     lenx(i) = ReadShort_UL(MidB(headbuf, head_off+2*i, 2))
  72.                     tempstr = ReadString(MidB(headbuf, head_off+10+tmp_off, lenx(i)))
  73.                     tmp_off = tmp_off + lenx(i)
  74.                     Execute(items1(i)&" = tempstr")
  75.                 Next
  76.                 head_off = head_off + 10 + temp_off
  77.             ElseIf frametag = ext_tag Then
  78.                 inum = ReadShort_UL(MidB(headbuf, head_off, 2))
  79.                 tmp_off = 2
  80.                 While k < inum And tmp_off+24 < framesize
  81.                     nlen = ReadShort_UL(MidB(headbuf, head_off+tmp_off, 2))
  82.                     nbuf = ReadString(MidB(headbuf, head_off+tmp_off+2, nlen))
  83.                     flag = ReadShort_UL(MidB(headbuf, head_off+tmp_off+2+nlen, 2))
  84.                     vlen = ReadShort_UL(MidB(headbuf, head_off+tmp_off+2+nlen+2, 2))
  85.                     vbuf = ReadString(MidB(headbuf, head_off+tmp_off+2+nlen+4, vlen))
  86.                     'on error resume next
  87.                     Execute(Replace(nbuf,"/","")&" = vbuf")
  88.                     'err.clear
  89.                     tmp_off = tmp_off + 6 + nlen + vlen
  90.                     k = k + 1
  91.                 Wend
  92.                 head_off = head_off + framesize-24
  93.             Else
  94.                 head_off = head_off + framesize-24
  95.             End If
  96.         Next
  97.         
  98.         CloseStream
  99.     End Function
  100. 'get the header
  101.     Private Function ReadHeader()
  102.         ReadHeader = False
  103.         buf = objStream.Read(30)
  104.         If ReadHex(LeftB(buf, 16)) <> headtag Then Exit Function
  105.         headsize = ReadLong_UL(MidB(buf,17,4))
  106.         headext1 = MidB(buf,21,4)
  107.         tagnum = ReadLong_UL(MidB(buf,25,4))
  108.         headext2 = MidB(buf,29,2)
  109.         headbuf = objStream.Read(headsize-30)
  110.         ReadHeader = True
  111.     End Function
  112. 'get the body
  113.     Private Function ReadBody()
  114.         ReadBody = False
  115.         buf = objStream.Read(24)
  116.         If ReadHex(LeftB(buf, 16)) <> bodytag Then Exit Function
  117.         bodysize = ReadLong_UL(MidB(buf,17,4))
  118.         bodybuf = objStream.Read(bodysize-24)
  119.         ReadBody = True
  120.     End Function
  121. 'CreateStream
  122.     Public Function CreateStream()
  123.         on error resume next
  124.         Set objStream = Server.CreateObject("ADODB.Stream")
  125.         objStream.Type = 1
  126.         objStream.Open
  127.         Err.clear
  128.         objStream.LoadFromFile File
  129.         If err<>0 Then
  130.         objStream.LoadFromFile server.mappath(File)
  131.         End If
  132.         Err.clear
  133.     End Function
  134. 'CloseStream
  135.     Public Function CloseStream()
  136.         objStream.close
  137.         Set objStream = nothing
  138.     End Function
  139. 'Read String    From Byte
  140.     Private Function ReadString(binstr)
  141.         If LenB(binstr) > 2 Then
  142.             ReadString = LeftB(binstr, LenB(binstr)-2)
  143.         Else
  144.             ReadString = binstr
  145.         End If
  146.     End Function
  147. 'Read Hex   From Byte
  148.     Private Function ReadHex(binstr)
  149.         ReadHex = ""
  150.         on error resume next
  151.         For i = 1 To LenB(binstr)
  152.             ReadHex = ReadHex & Hex((AscB(MidB(binstr,i,1)) And &HF0)/16) & Hex(AscB(MidB(binstr,i,1)) And &H0F)
  153.         Next
  154.         ReadHex = LCase(ReadHex)
  155.     End Function
  156. 'Read Unsigned Long(Little Endian) From Byte
  157.     Private Function ReadLong_UL(binstr)
  158.         ReadLong_UL = 0
  159.         on error resume next
  160.         ReadLong_UL = AscB(MidB(binstr,1,1)) + AscB(MidB(binstr,2,1))*256 + AscB(MidB(binstr,3,1))*65536 + AscB(MidB(binstr,4,1))*16777216
  161.     End Function
  162. 'Read Unsigned Short(Little Endian) From Byte
  163.     Private Function ReadShort_UL(binstr)
  164.         ReadShort_UL = 0
  165.         on error resume next
  166.         ReadShort_UL = AscB(MidB(binstr,1,1)) + AscB(MidB(binstr,2,1))*256
  167.     End Function
  168. End Class
  169. %>
测试程序:wma.asp
  1. <!-- #include file="wmaExif.class.asp" -->
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  6. <title>利用ASP获取WMA的TAG信息</title>
  7. </head>
  8. <body>
  9. <%
  10. dim info
  11. set info = New wmaExif
  12. set info.File=request("soundPath")
  13. If info.CheckSize = True Then
  14.     info.Parse
  15.   Response.write "歌名:"&info.GetInfo("Title")&"<br/>"
  16.   Response.write "歌手:"&info.GetInfo("Artist")&"<br/>"
  17.   Response.write "版权:"&info.GetInfo("CopyRight")&"<br/>"
  18.   Response.write "注释:"&info.GetInfo("Description")&"<br/>"
  19.   Response.write "专辑:"&info.GetInfo("WM/AlbumTitle")&"<br/>"
  20.   Response.write "曲目:"&info.GetInfo("WM/TrackNumber")&"<br/>"
  21.   Response.write "发行年份:"&info.GetInfo("WM/Year")&"<br/>"
  22.   Response.write "类型:"&info.GetInfo("WM/Genre")&"<br/>"
  23. Else
  24.     Response.Write "error"
  25. End If
  26. set info = Nothing
  27. %>
  28. </body>
  29. </html>


参考资料:
http://linle.ycool.com/post.1255557.html
http://www.itlearner.com/Article/2007/3944.shtml
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值