這是我寫的第一個讀取文件信息的代碼,好像是05年寫的. 當時只會asp。寫好後才發現性能不是一般的低
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Option Explicit
Response.Buffer = False
server.ScriptTimeout = 3600000
Class Mp3WmaInfo
Private Info
Private Stream
Private Standard_Wma_Header
Private Standard_Wma_Tag_Header
Private Standard_Wma_ExTag_Header
Private Standard_Mp3_ID3V2Tag_Header
Private TagCoding,Mp3_Genres(147)
Public Function GetTag(Path,Input_TagCoding)
Set Info = Server.CreateObject("Scripting.Dictionary")
Set Stream = Server.CreateObject("Adodb.Stream")
Dim Temp_Index
Dim Hex_String
Stream.Type = 1
Stream.Mode = 3
Stream.Open
Stream.Position = 0
Stream.LoadFromFile Path
TagCoding = Input_TagCoding
If TagCoding = "" Then TagCoding = "Unicode" End If
For Temp_Index = 1 To 16
Hex_String = Hex_String & Hex(AscB(Stream.Read(1)))
Next
If Hex_String = Standard_Wma_Header Then
Call GetWmaInfo()
Else
Call GetMp3Info()
End If
Stream.Close
Set Stream = NoThing
Set GetTag = Info
End Function
Private Sub GetMp3Info()
Dim Temp_Index
Dim Hex_String
Stream.Position = 0
For Temp_Index = 1 To 3
Hex_String = Hex_String & Hex(AscB(Stream.Read(1)))
Next
If Hex_String = Standard_Mp3_ID3V2Tag_Header Then
Set Info.Item("ID3V2") = Server.CreateObject("Scripting.Dictionary")
Dim ID3V2_Temp_Size(3)
Dim ID3V2_Size
Dim ID3V2_Flag
Dim ID3V2_Temp_FrameSize(3)
Dim ID3V2_FrameID
Dim ID3V2_FrameSize
Dim ID3V2_FrameSizeFlags
Dim ID3V2_FrameContent
Info.Item("ID3V2").Item("Ver") = AscB(Stream.Read(1))
Info.Item("ID3V2").Item("Revision") = AscB(Stream.Read(1))
ID3V2_Flag = AlgorismToBinary(AscB(Stream.Read(1)),8)
ID3V2_Temp_Size(0) = AscB(Stream.Read(1)) * 2097152
ID3V2_Temp_Size(1) = AscB(Stream.Read(1)) * 16384
ID3V2_Temp_Size(2) = AscB(Stream.Read(1)) * 128
ID3V2_Temp_Size(3) = AscB(Stream.Read(1))
ID3V2_Size = ID3V2_Temp_Size(0) + ID3V2_Temp_Size(1) + ID3V2_Temp_Size(2) + ID3V2_Temp_Size(3)
While Stream.Position <= ID3V2_Size
ID3V2_FrameID = Trim(ByteToText(Stream.Read(4),TagCoding))
ID3V2_Temp_FrameSize(0) = AscB(Stream.Read(1)) * 16777216
ID3V2_Temp_FrameSize(1) = AscB(Stream.Read(1)) * 65536
ID3V2_Temp_FrameSize(2) = AscB(Stream.Read(1)) * 256
ID3V2_Temp_FrameSize(3) = AscB(Stream.Read(1))
ID3V2_FrameSize = ID3V2_Temp_FrameSize(0) + ID3V2_Temp_FrameSize(1) + ID3V2_Temp_FrameSize(2) + ID3V2_Temp_FrameSize(3)
ID3V2_FrameSizeFlags = AlgorismToBinary(AscB(Stream.Read(1)),8)
ID3V2_FrameSizeFlags = ID3V2_FrameSizeFlags & AlgorismToBinary(AscB(Stream.Read(1)),8)
If ID3V2_FrameSize <> 0 Then
ID3V2_FrameContent = Trim(ByteToText(Stream.Read(ID3V2_FrameSize),TagCoding))
End If
If ID3V2_FrameID <> "" AND (ID3V2_FrameSizeFlags = "0000000000000000" OR ID3V2_FrameSizeFlags = "0010000000000000") Then
Info.Item("ID3V2").Item(ID3V2_FrameID) = ID3V2_FrameContent
End If
Wend
End If
Stream.Position = Stream.Size - 128
If ByteToText(Stream.Read(3),TagCoding) = "TAG" Then
Dim Mp3_ID3v1_Cenre,Mp3_ID3v1_Cenre_Index
Set Info.Item("ID3v1") = Server.CreateObject("Scripting.Dictionary")
Info.Item("ID3v1").Item("Title") = ByteToText(Stream.Read(30),TagCoding)
Info.Item("ID3v1").Item("Artist") = ByteToText(Stream.Read(30),TagCoding)
Info.Item("ID3v1").Item("Album") = ByteToText(Stream.Read(30),TagCoding)
Info.Item("ID3v1").Item("Year") = ByteToText(Stream.Read(4),TagCoding)
Info.Item("ID3v1").Item("Comment") = ByteToText(Stream.Read(28),TagCoding)
Info.Item("ID3v1").Item("Reserve") = AscB(Stream.Read(1))
Info.Item("ID3v1").Item("Track") = AscB(Stream.Read(1))
Mp3_ID3v1_Cenre_Index = AscB(Stream.Read(1))
If Mp3_ID3v1_Cenre_Index <= 147 Then Mp3_ID3v1_Cenre = Mp3_Genres(Mp3_ID3v1_Cenre_Index) End If
Info.Item("ID3v1").Item("Cenre") = Mp3_ID3v1_Cenre
End If
End Sub
Private Sub GetWmaInfo()
Set Info.Item("Tag") = Server.CreateObject("Scripting.Dictionary")
Set Info.Item("ExTag") = Server.CreateObject("Scripting.Dictionary")
Dim Wma_Tag_Header,Temp_Index
Dim Temp_Byte
Dim Wma_Music_Title_Byte_Length
Dim Wma_Music_Artist_Byte_Length
Dim Wma_Music_Album_Byte_Length
Dim Wma_Music_Comment_Byte_Length
Dim Wma_Music_Other_Byte_Length
Dim Wma_Music_ExTag_Count
Dim Temp_Wma_Music_ExTag_Count_Index
Dim Wma_Music_ExTag_ID
Dim Wma_Music_ExTag_Flag
Dim Wma_Music_ExTag_Content_Index
Dim Wma_Music_ExTag_Content
Stream.Position = 30
For Temp_Index = 1 To 16
Wma_Tag_Header = Wma_Tag_Header & Hex(AscB(Stream.Read(1)))
Next
While Wma_Tag_Header = Standard_Wma_Tag_Header OR Wma_Tag_Header = Standard_Wma_ExTag_Header
If Wma_Tag_Header = Standard_Wma_Tag_Header Then
Stream.Position = Stream.Position + 8
Temp_Byte = ""
Temp_Byte = Hex(AscB(Stream.Read(1)))
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
Wma_Music_Title_Byte_Length = Clng(Temp_Byte)
Temp_Byte = ""
Temp_Byte = Hex(AscB(Stream.Read(1)))
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
Wma_Music_Artist_Byte_Length = Clng(Temp_Byte)
Temp_Byte = ""
Temp_Byte = Hex(AscB(Stream.Read(1)))
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
Wma_Music_Album_Byte_Length = Clng(Temp_Byte)
Temp_Byte = ""
Temp_Byte = Hex(AscB(Stream.Read(1)))
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
Wma_Music_Comment_Byte_Length = Clng(Temp_Byte)
Temp_Byte = ""
Temp_Byte = Hex(AscB(Stream.Read(1)))
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
Wma_Music_Other_Byte_Length = Clng(Temp_Byte)
If Wma_Music_Title_Byte_Length <> 0 Then
Info.Item("Tag").Item("Title") = ByteToText(Stream.Read(Wma_Music_Title_Byte_Length),"Unicode")
End If
If Wma_Music_Artist_Byte_Length <> 0 Then
Info.Item("Tag").Item("Artist") = ByteToText(Stream.Read(Wma_Music_Artist_Byte_Length),"Unicode")
End If
If Wma_Music_Album_Byte_Length <> 0 Then
Info.Item("Tag").Item("Album") = ByteToText(Stream.Read(Wma_Music_Album_Byte_Length),"Unicode")
End If
If Wma_Music_Comment_Byte_Length <> 0 Then
Info.Item("Tag").Item("Comment") = ByteToText(Stream.Read(Wma_Music_Comment_Byte_Length),"Unicode")
End If
If Wma_Music_Other_Byte_Length <> 0 Then
Info.Item("Tag").Item("Other") = ByteToText(Stream.Read(Wma_Music_Other_Byte_Length),"Unicode")
End If
End If
If Wma_Tag_Header = Standard_Wma_ExTag_Header Then
Stream.Position = Stream.Position + 8
Temp_Byte = Hex(AscB(Stream.Read(1)))
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
Wma_Music_ExTag_Count = Clng(Temp_Byte)
For Temp_Wma_Music_ExTag_Count_Index = 1 To Wma_Music_ExTag_Count
Temp_Byte = Hex(AscB(Stream.Read(1)))
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
Wma_Music_ExTag_ID = ByteToText(Stream.Read(Clng(Temp_Byte)),"Unicode")
Temp_Byte = Hex(AscB(Stream.Read(1)))
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
Wma_Music_ExTag_Flag = Clng(Temp_Byte)
Temp_Byte = Hex(AscB(Stream.Read(1)))
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
Temp_Byte = Clng(Temp_Byte)
If Wma_Music_ExTag_Flag = 3 Then
For Wma_Music_ExTag_Content_Index = 1 To Temp_Byte Step + 4
Temp_Byte = Hex(AscB(Stream.Read(1)))
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
Wma_Music_ExTag_Content = Clng(Temp_Byte)
Next
Else
Wma_Music_ExTag_Content = ByteToText(Stream.Read(Temp_Byte),"Unicode")
End If
Info.Item("ExTag").Item(Wma_Music_ExTag_ID) = Wma_Music_ExTag_Content
Next
End If
For Temp_Index = 1 To 16
Wma_Tag_Header = Wma_Tag_Header & Hex(AscB(Stream.Read(1)))
Next
Wend
End Sub
Private Function ByteToText(ByteData,Coding)
Dim MyStream,Temp_Byte
Set MyStream = Server.CreateObject("Adodb.Stream")
MyStream.Type = 1
MyStream.Mode = 3
MyStream.Open
MyStream.Write ByteData
MyStream.Position = 0
Select Case Coding
Case "Unicode"
If MyStream.Size Mod 2 = 0 Then
While Not MyStream.EoS
Temp_Byte = Hex(AscB(MyStream.Read(1)))
Temp_Byte = Hex(AscB(MyStream.Read(1))) & Temp_Byte
Temp_Byte = "&H" & Temp_Byte
ByteToText = ByteToText & ChrW(Temp_Byte)
Wend
End If
Case Else
MyStream.Type = 2
MyStream.Charset = Coding
ByteToText = MyStream.ReadText
End Select
MyStream.Close
Set MyStream = Nothing
End Function
Private Function AlgorismToBinary(Algorism,Length)
While Algorism <> 0
AlgorismToBinary = Algorism Mod 2 & AlgorismToBinary
Algorism = Int(Algorism / 2)
Wend
While Len(AlgorismToBinary) < Length
AlgorismToBinary = "0" & AlgorismToBinary
Wend
End Function
Private Sub Class_Initialize()
Standard_Wma_Header = "3026B2758E66CF11A6D90AA062CE6C" 'Wma鏂囦歡澶?
Standard_Wma_Tag_Header = "3326B2758E66CF11A6D90AA062CE6C" 'Wma鏍囧噯Tag甯у悕
Standard_Wma_ExTag_Header = "40A4D0D27E3D21197F00A0C95EA850" 'Wma鎵╁睍Tag甯у悕
Standard_Mp3_ID3V2Tag_Header = "494433" 'Mp3ID3V2Tag鏍囩鍚?
Mp3_Genres(0) = "Blues"
Mp3_Genres(1) = "ClassicRock"
Mp3_Genres(2) = "Country"
Mp3_Genres(3) = "Dance"
Mp3_Genres(4) = "Disco"
Mp3_Genres(5) = "Funk"
Mp3_Genres(6) = "Grunge"
Mp3_Genres(7) = "Hip-Hop"
Mp3_Genres(8) = "Jazz"
Mp3_Genres(9) = "Metal"
Mp3_Genres(10) = "NewAge"
Mp3_Genres(11) = "Oldies"
Mp3_Genres(12) = "Other"
Mp3_Genres(13) = "Pop"
Mp3_Genres(14) = "R&B"
Mp3_Genres(15) = "Rap"
Mp3_Genres(16) = "Reggae"
Mp3_Genres(17) = "Rock"
Mp3_Genres(18) = "Techno"
Mp3_Genres(19) = "Industrial"
Mp3_Genres(20) = "Alternative"
Mp3_Genres(21) = "Ska"
Mp3_Genres(22) = "DeathMetal"
Mp3_Genres(23) = "Pranks"
Mp3_Genres(24) = "Soundtrack"
Mp3_Genres(25) = "Euro-Techno"
Mp3_Genres(26) = "Ambient"
Mp3_Genres(27) = "Trip-Hop"
Mp3_Genres(28) = "Vocal"
Mp3_Genres(29) = "Jazz+Funk"
Mp3_Genres(30) = "Fusion"
Mp3_Genres(31) = "Trance"
Mp3_Genres(32) = "Classical"
Mp3_Genres(33) = "Instrumental"
Mp3_Genres(34) = "Acid"
Mp3_Genres(35) = "House"
Mp3_Genres(36) = "Game"
Mp3_Genres(37) = "SoundClip"
Mp3_Genres(38) = "Gospel"
Mp3_Genres(39) = "Noise"
Mp3_Genres(40) = "AlternRock"
Mp3_Genres(41) = "Bass"
Mp3_Genres(42) = "Soul"
Mp3_Genres(43) = "Punk"
Mp3_Genres(44) = "Space"
Mp3_Genres(45) = "Meditative"
Mp3_Genres(46) = "InstrumentalPop"
Mp3_Genres(47) = "InstrumentalRock"
Mp3_Genres(48) = "Ethnic"
Mp3_Genres(49) = "Gothic"
Mp3_Genres(50) = "Darkwave"
Mp3_Genres(51) = "Techno-Industrial"
Mp3_Genres(52) = "Electronic"
Mp3_Genres(53) = "Pop-Folk"
Mp3_Genres(54) = "Eurodance"
Mp3_Genres(55) = "Dream"
Mp3_Genres(56) = "SouthernRock"
Mp3_Genres(57) = "Comedy"
Mp3_Genres(58) = "Cult"
Mp3_Genres(59) = "Gangsta"
Mp3_Genres(60) = "Top40"
Mp3_Genres(61) = "ChristianRap"
Mp3_Genres(62) = "Pop/Funk"
Mp3_Genres(63) = "Jungle"
Mp3_Genres(64) = "NativeAmerican"
Mp3_Genres(65) = "Cabaret"
Mp3_Genres(66) = "NewWave"
Mp3_Genres(67) = "Psychadelic"
Mp3_Genres(68) = "Rave"
Mp3_Genres(69) = "Showtunes"
Mp3_Genres(70) = "Trailer"
Mp3_Genres(71) = "Lo-Fi"
Mp3_Genres(72) = "Tribal"
Mp3_Genres(73) = "AcidPunk"
Mp3_Genres(74) = "AcidJazz"
Mp3_Genres(75) = "Polka"
Mp3_Genres(76) = "Retro"
Mp3_Genres(77) = "Musical"
Mp3_Genres(78) = "Rock&Roll"
Mp3_Genres(79) = "HardRock"
Mp3_Genres(80) = "Folk"
Mp3_Genres(81) = "Folk-Rock"
Mp3_Genres(82) = "NationalFolk"
Mp3_Genres(83) = "Swing"
Mp3_Genres(84) = "FastFusion"
Mp3_Genres(85) = "Bebob"
Mp3_Genres(86) = "Latin"
Mp3_Genres(87) = "Revival"
Mp3_Genres(88) = "Celtic"
Mp3_Genres(89) = "Bluegrass"
Mp3_Genres(90) = "Avantgarde"
Mp3_Genres(91) = "GothicRock"
Mp3_Genres(92) = "ProgessiveRock"
Mp3_Genres(93) = "PsychedelicRock"
Mp3_Genres(94) = "SymphonicRock"
Mp3_Genres(95) = "SlowRock"
Mp3_Genres(96) = "BigBand"
Mp3_Genres(97) = "Chorus"
Mp3_Genres(98) = "EasyListening"
Mp3_Genres(99) = "Acoustic"
Mp3_Genres(100) = "Humour"
Mp3_Genres(101) = "Speech"
Mp3_Genres(102) = "Chanson"
Mp3_Genres(103) = "Opera"
Mp3_Genres(104) = "ChamberMusic"
Mp3_Genres(105) = "Sonata"
Mp3_Genres(106) = "Symphony"
Mp3_Genres(107) = "BootyBass"
Mp3_Genres(108) = "Primus"
Mp3_Genres(109) = "PornGroove"
Mp3_Genres(110) = "Satire"
Mp3_Genres(111) = "SlowJam"
Mp3_Genres(112) = "Club"
Mp3_Genres(113) = "Tango"
Mp3_Genres(114) = "Samba"
Mp3_Genres(115) = "Folklore"
Mp3_Genres(116) = "Ballad"
Mp3_Genres(117) = "PowerBallad"
Mp3_Genres(118) = "RhythmicSoul"
Mp3_Genres(119) = "Freestyle"
Mp3_Genres(120) = "Duet"
Mp3_Genres(121) = "PunkRock"
Mp3_Genres(122) = "DrumSolo"
Mp3_Genres(123) = "Acapella"
Mp3_Genres(124) = "Euro-House"
Mp3_Genres(125) = "DanceHall"
Mp3_Genres(126) = "Goa"
Mp3_Genres(127) = "Drum&Bass"
Mp3_Genres(128) = "Club-House"
Mp3_Genres(129) = "Hardcore"
Mp3_Genres(130) = "Terror"
Mp3_Genres(131) = "Indie"
Mp3_Genres(132) = "BritPop"
Mp3_Genres(133) = "Negerpunk"
Mp3_Genres(134) = "PolskPunk"
Mp3_Genres(135) = "Beat"
Mp3_Genres(136) = "ChristianGangstaRap"
Mp3_Genres(137) = "HeavyMetal"
Mp3_Genres(138) = "BlackMetal"
Mp3_Genres(139) = "Crossover"
Mp3_Genres(140) = "ContemporaryChristian"
Mp3_Genres(141) = "ChristianRock"
Mp3_Genres(142) = "Merengue"
Mp3_Genres(143) = "Salsa"
Mp3_Genres(144) = "TrashMetal"
Mp3_Genres(145) = "Anime"
Mp3_Genres(146) = "JPop"
Mp3_Genres(147) = "Synthpop"
End Sub
End Class
Sub FileList(Lookup_Path)
Dim MyFileSystemObject,MyGetFolder,MySubFolders,Folder
Dim MyFiles,File
Dim Info,Info1,Mp3WmaInfo_,Infodd
Set MyFileSystemObject = Server.CreateObject("Scripting.FileSystemObject")
Set MyGetFolder = MyFileSystemObject.GetFolder(Lookup_Path)
Set MySubFolders = MyGetFolder.SubFolders
Set MyFiles = MyGetFolder.Files
Set Mp3WmaInfo_ = New Mp3WmaInfo
For Each Folder IN MySubFolders
Call FileList(Folder.Path)
Next
For Each File IN MyFiles
Response.Write ""
Set Infodd = Mp3WmaInfo_.GetTag(File.Path,"gb2312")
Response.Write ""
Response.Write ""
Response.Write ""
Response.Write ""
Response.Write "
"
& File.Name & " | " & File.Path & " | " & FormatNumber(File.Size / 1048576,2,-1,0,0) & "M |
" Response.Write
"" For Each Info IN Infodd Response.Write "" Response.Write "" Next Response.Write "" & Info & " | " If Infodd.Item(Info).Count > 0 Then Response.Write "" For Each Info1 In Infodd.Item(Info)
Response.Write "" Response.Write "" Next Response.Write "" & Info1 & " | " & Infodd.Item(Info)(Info1) & " | " End If Response.Write " |
|
"
If Response.IsClientConnected = False Then Response.End() End If
Next
End Sub
%>
<% Call FileList(Server.MapPath("music")) %>