ASP读取WMA,MP3文件信息类

来源:互联网 发布:勒布朗 詹姆斯身体数据 编辑:程序博客网 时间:2024/04/28 02:53
这是我写的第一个读取文件信息的代码,好像是05年写的. 当时只会asp。写好后才发现性能不是一般的低
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><%Option ExplicitResponse.Buffer = Falseserver.ScriptTimeout = 3600000Class Mp3WmaInfoPrivate InfoPrivate StreamPrivate Standard_Wma_HeaderPrivate Standard_Wma_Tag_HeaderPrivate Standard_Wma_ExTag_HeaderPrivate Standard_Mp3_ID3V2Tag_HeaderPrivate TagCoding,Mp3_Genres(147)Public Function GetTag(Path,Input_TagCoding)Set Info = Server.CreateObject("Scripting.Dictionary")Set Stream = Server.CreateObject("Adodb.Stream")Dim Temp_IndexDim Hex_String Stream.Type = 1Stream.Mode = 3Stream.OpenStream.Position = 0Stream.LoadFromFile PathTagCoding = Input_TagCodingIf TagCoding = "" Then TagCoding = "Unicode" End IfFor Temp_Index = 1 To 16Hex_String = Hex_String & Hex(AscB(Stream.Read(1)))NextIf Hex_String = Standard_Wma_Header ThenCall GetWmaInfo()ElseCall GetMp3Info()End IfStream.CloseSet Stream = NoThingSet GetTag = InfoEnd FunctionPrivate Sub GetMp3Info()Dim Temp_IndexDim Hex_StringStream.Position = 0For Temp_Index = 1 To 3Hex_String = Hex_String & Hex(AscB(Stream.Read(1)))NextIf Hex_String = Standard_Mp3_ID3V2Tag_Header ThenSet Info.Item("ID3V2") = Server.CreateObject("Scripting.Dictionary")Dim ID3V2_Temp_Size(3)Dim ID3V2_SizeDim ID3V2_FlagDim ID3V2_Temp_FrameSize(3)Dim ID3V2_FrameIDDim ID3V2_FrameSizeDim ID3V2_FrameSizeFlagsDim ID3V2_FrameContentInfo.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)) * 2097152ID3V2_Temp_Size(1) = AscB(Stream.Read(1)) * 16384ID3V2_Temp_Size(2) = AscB(Stream.Read(1)) * 128ID3V2_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_SizeID3V2_FrameID = Trim(ByteToText(Stream.Read(4),TagCoding))ID3V2_Temp_FrameSize(0) = AscB(Stream.Read(1)) * 16777216ID3V2_Temp_FrameSize(1) = AscB(Stream.Read(1)) * 65536ID3V2_Temp_FrameSize(2) = AscB(Stream.Read(1)) * 256ID3V2_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 ThenID3V2_FrameContent = Trim(ByteToText(Stream.Read(ID3V2_FrameSize),TagCoding))End IfIf ID3V2_FrameID <> "" AND (ID3V2_FrameSizeFlags = "0000000000000000" OR ID3V2_FrameSizeFlags = "0010000000000000") ThenInfo.Item("ID3V2").Item(ID3V2_FrameID) = ID3V2_FrameContentEnd IfWend End IfStream.Position = Stream.Size - 128If ByteToText(Stream.Read(3),TagCoding) = "TAG" ThenDim Mp3_ID3v1_Cenre,Mp3_ID3v1_Cenre_IndexSet 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 IfInfo.Item("ID3v1").Item("Cenre") = Mp3_ID3v1_CenreEnd IfEnd SubPrivate Sub GetWmaInfo()Set Info.Item("Tag") = Server.CreateObject("Scripting.Dictionary")Set Info.Item("ExTag") = Server.CreateObject("Scripting.Dictionary")Dim Wma_Tag_Header,Temp_IndexDim Temp_ByteDim Wma_Music_Title_Byte_LengthDim Wma_Music_Artist_Byte_LengthDim Wma_Music_Album_Byte_LengthDim Wma_Music_Comment_Byte_LengthDim Wma_Music_Other_Byte_LengthDim Wma_Music_ExTag_CountDim Temp_Wma_Music_ExTag_Count_IndexDim Wma_Music_ExTag_IDDim Wma_Music_ExTag_FlagDim Wma_Music_ExTag_Content_IndexDim Wma_Music_ExTag_ContentStream.Position = 30For Temp_Index = 1 To 16Wma_Tag_Header = Wma_Tag_Header & Hex(AscB(Stream.Read(1)))NextWhile Wma_Tag_Header = Standard_Wma_Tag_Header OR Wma_Tag_Header = Standard_Wma_ExTag_HeaderIf Wma_Tag_Header = Standard_Wma_Tag_Header ThenStream.Position = Stream.Position + 8Temp_Byte = ""Temp_Byte = Hex(AscB(Stream.Read(1)))Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = "&H" & Temp_ByteWma_Music_Title_Byte_Length = Clng(Temp_Byte)Temp_Byte = ""Temp_Byte = Hex(AscB(Stream.Read(1)))Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = "&H" & Temp_ByteWma_Music_Artist_Byte_Length = Clng(Temp_Byte)Temp_Byte = ""Temp_Byte = Hex(AscB(Stream.Read(1)))Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = "&H" & Temp_ByteWma_Music_Album_Byte_Length = Clng(Temp_Byte)Temp_Byte = ""Temp_Byte = Hex(AscB(Stream.Read(1)))Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = "&H" & Temp_ByteWma_Music_Comment_Byte_Length = Clng(Temp_Byte)Temp_Byte = ""Temp_Byte = Hex(AscB(Stream.Read(1)))Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = "&H" & Temp_ByteWma_Music_Other_Byte_Length = Clng(Temp_Byte)If Wma_Music_Title_Byte_Length <> 0 ThenInfo.Item("Tag").Item("Title") = ByteToText(Stream.Read(Wma_Music_Title_Byte_Length),"Unicode")End IfIf Wma_Music_Artist_Byte_Length <> 0 ThenInfo.Item("Tag").Item("Artist") = ByteToText(Stream.Read(Wma_Music_Artist_Byte_Length),"Unicode")End IfIf Wma_Music_Album_Byte_Length <> 0 ThenInfo.Item("Tag").Item("Album") = ByteToText(Stream.Read(Wma_Music_Album_Byte_Length),"Unicode")End IfIf Wma_Music_Comment_Byte_Length <> 0 ThenInfo.Item("Tag").Item("Comment") = ByteToText(Stream.Read(Wma_Music_Comment_Byte_Length),"Unicode")End IfIf Wma_Music_Other_Byte_Length <> 0 ThenInfo.Item("Tag").Item("Other") = ByteToText(Stream.Read(Wma_Music_Other_Byte_Length),"Unicode")End IfEnd IfIf Wma_Tag_Header = Standard_Wma_ExTag_Header ThenStream.Position = Stream.Position + 8Temp_Byte = Hex(AscB(Stream.Read(1)))Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = "&H" & Temp_ByteWma_Music_ExTag_Count = Clng(Temp_Byte)For Temp_Wma_Music_ExTag_Count_Index = 1 To Wma_Music_ExTag_CountTemp_Byte = Hex(AscB(Stream.Read(1)))Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = "&H" & Temp_ByteWma_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_ByteTemp_Byte = "&H" & Temp_ByteWma_Music_ExTag_Flag = Clng(Temp_Byte)Temp_Byte = Hex(AscB(Stream.Read(1)))Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = "&H" & Temp_ByteTemp_Byte = Clng(Temp_Byte)If Wma_Music_ExTag_Flag = 3 Then For Wma_Music_ExTag_Content_Index = 1 To Temp_Byte Step + 4Temp_Byte = Hex(AscB(Stream.Read(1)))Temp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = Hex(AscB(Stream.Read(1))) & Temp_ByteTemp_Byte = "&H" & Temp_Byte Wma_Music_ExTag_Content = Clng(Temp_Byte)NextElseWma_Music_ExTag_Content = ByteToText(Stream.Read(Temp_Byte),"Unicode")End IfInfo.Item("ExTag").Item(Wma_Music_ExTag_ID)= Wma_Music_ExTag_ContentNextEnd IfFor Temp_Index = 1 To 16Wma_Tag_Header = Wma_Tag_Header & Hex(AscB(Stream.Read(1)))NextWendEnd SubPrivate Function ByteToText(ByteData,Coding)Dim MyStream,Temp_ByteSet MyStream = Server.CreateObject("Adodb.Stream")MyStream.Type = 1MyStream.Mode = 3MyStream.OpenMyStream.Write ByteDataMyStream.Position = 0Select Case CodingCase "Unicode"If MyStream.Size Mod 2 = 0 ThenWhile Not MyStream.EoSTemp_Byte = Hex(AscB(MyStream.Read(1)))Temp_Byte = Hex(AscB(MyStream.Read(1))) & Temp_ByteTemp_Byte = "&H" & Temp_ByteByteToText = ByteToText & ChrW(Temp_Byte)WendEnd IfCase ElseMyStream.Type = 2MyStream.Charset = CodingByteToText = MyStream.ReadTextEnd SelectMyStream.CloseSet MyStream = NothingEnd FunctionPrivate Function AlgorismToBinary(Algorism,Length)While Algorism <> 0AlgorismToBinary = Algorism Mod 2 & AlgorismToBinaryAlgorism = Int(Algorism / 2)WendWhile Len(AlgorismToBinary) < LengthAlgorismToBinary = "0" & AlgorismToBinaryWendEnd FunctionPrivate 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 SubEnd ClassSub FileList(Lookup_Path)Dim MyFileSystemObject,MyGetFolder,MySubFolders,FolderDim MyFiles,FileDim Info,Info1,Mp3WmaInfo_,InfoddSet MyFileSystemObject = Server.CreateObject("Scripting.FileSystemObject")Set MyGetFolder = MyFileSystemObject.GetFolder(Lookup_Path)Set MySubFolders = MyGetFolder.SubFoldersSet MyFiles = MyGetFolder.FilesSet Mp3WmaInfo_ = New Mp3WmaInfoFor Each Folder IN MySubFoldersCall FileList(Folder.Path)NextFor Each File IN MyFilesResponse.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 IfNextEnd Sub%><% Call FileList(Server.MapPath("music")) %>
0 0