A class that can read ID3 information [can be convenient to add MP3]

xiaoxiao2021-03-06  45

UUID = "00000205-0000-0010-8000-00Aa006d2ea4"

Name = "AdoDb Type Library"

->

<%

'Author: Xiaolong Zyvslxl, Zyvslxl @ 163.com Please keep

'Require the specified properties

'Path file path

The attribute defined by the 'class head section is the information that can be obtained. Of course, there is more than this, and it can be returned to any tag value.

'Add a known label in Id3V2 (), you can return the corresponding content

'Because personal knowledge is limited, please advise

'Available method

'CreateStream opens the file stream

'pre-execution

'CloseStream Close File Flow

Class MP3

Public path

Public Flag

Public Title 'Title

Public Artist 'author

Public album 'collection

Public Issueyear '

Public Comment 'Notes

Public genre 'type

Public TCON 'genre

Public mptime 'time

Public USLT 'lyrics

Private Objstream

'[To be expanded]

Private function exitext ()

DIM EXT

EXT = LCASE (Right (Path, Len (PATH) -insTrrev (".")))

EXITEXT = EXT

END FUNCTION

'[Convert function, some types or judgment]

Private function bin2str (binstr, num)

ON Error ResMe 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

'[Load file]

Public function createsTream ()

ON Error ResMe 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 Flow]

Public function closestream () objstream.close

Set objstream = Nothing

END FUNCTION

'[Logo information]

Public Function ID ()

DIM COMM

Objstream.position = 0

Comm = Objstream.read (3)

ID = Bin2Str (Comm)

END FUNCTION

'[ID3V2 information reading]

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 "& maxsize &"
"

Do While Objstream.Position

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) = "" "" The 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

'[Assignment to attributes]]

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 / a specific tag content length]

Private function size (num)

Size = NULL

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

Size = ASCB (a) * 4294967296

END IF

IF not isnull (b) THEN

SIZE = Size ASCB (b) * 65536

END IF

IF not isnull (c) THEN

Size = Size ASCB (C) * 256

END IF

IF not isnull (d) THEN

Size = Size ASCB (D)

END IF

END FUNCTION

'[Get head tag length / tag length]

Private function Topsize (NUM)

TOPSIZE = NULL

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

END IF

IF not isnull (b) THEN

TOPSIZE = Topsize ASCB (b) * 1024

END IF

IF not isnull (c) THEN

TOPSIZE = TOPSIZE ASCB (C) * 128

END IF

IF not isnull (d) THEN

TOPSIZE = Topsize ASCB (D)

END IF

END FUNCTION

'[ID3V1 information reading]

Private function ID3v1 ()

Objstream.position = objstream.size - 128

Flag = bin2str (Objstream.Read (3), 3)

IF flag = "tag" then

Title = bin2str (Objstream.read (30), 30)

Artist = bin2str (Objstream.Read (30), 30)

Album = bin2str (Objstream.Read (30), 30)

Issueyear = bin2str (Objstream.Read (4), 4)

Comment = bin2str (Objstream.Read (30), 30)

Genre = Bin2Str (Objstream.Read (3), 3)

END IF

END FUNCTION

'[Judgment ID3 version only distinguishes ID3v1 and id3v2]

Private function fileflag ()

Objstream.position = 0

DIM FLAG

Flag = ucase (bin2str (Objstream.Read (3), 3))

If Flag = "ID3" THEN FILEFLAG = TRUE

'Response.write flag & "
"

END FUNCTION

'[Priority Return ID3V2 Version Information]

Public Function pre ()

IF fileflag dam

ID3V2

Else

ID3V1

END IF

END FUNCTION

END CLASS

%>

转载请注明原文地址:https://www.9cbs.com/read-84172.html

New Post(0)