A class that can read ID3 information [it's easy to add MP3]

Source: Internet
Author: User
Tags exit chr id3
<!--METADATA type= "TypeLib"


uuid= "00000205-0000-0010-8000-00AA006D2EA4"


name= "ADODB Type Library"


-->


<%


' Author: Dragon zyvslxl,zyvslxl@163.com please keep


' property to be specified

Path to
' path file

The
' class header section defines an attribute that can get information, of course, and can theoretically return any label value


' Adds a known label to the Select Case Frameid (i) section of ID3v2 () to return the appropriate content


' Because personal knowledge is limited, please advise








' Available Methods


' CreateStream Open file stream


' pre executes


' Closestream closes file stream





Class mp3





Public Path


Public Flag


public title ' title


public Artist ' author


Public Album ' album


public issueyear ' production age


public Comment ' remarks


public genre ' type


public Tcon ' genre


public mptime ' time


public USLT ' lyrics


Private objstream








' [to be extended]


private Function exitext ()


Dim ext


ext = LCase (right path,len (path)-instrrev ("."))


Exitext = ext


End Function








' [conversion function, some types still cannot be judged]


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








' [Loading file]


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





' [Close file stream]


public Function closestream ()


objStream.Close


Set objstream = Nothing


End Function








' [flag info]


public Function ID ()


Dim Comm


objstream.position = 0


Comm = Objstream.read (3)


id = bin2str (Comm)


End Function








' [ID3v2 information read]


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





' [Assign value to property]


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 "Talb": Album = CStr (Frame (i))


case "Tyer": Issueyear = CStr (Frame (i))


case "Tcon": Tcon = CStr (Frame (i))


case "Time": Mptime = CStr (Frame (i))


case "USLT": USLT = CStr (Frame (i))


End Select


Next


End Function











' [Get label frame length/specific label content length]


Private Function Size (num)


Size = Null


Dim a,b,c,d


A = MidB







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.