TIPS - Søg iblandt mp3 samling og lav en Playlist af resultatet
1. load alle mp3'er i winamp, (alle mp3'er skal have samme rod'mappe fx. f:\mp3'er\ eller anden2. gem playlisten i undermappen til det bibliotek dette script ligger i. skal hedde /RAW/ eller angiv selv et i scriptet
3. ændre Net-Path hvis andre brugere på et LAN skal kunne høre / downloade mp3'erne...
[INDEX.ASP]
<!-- #include file="mp3tools.asp" -->
<%
'if people on the LAN should be able to listen / download via links
CONST NetPath = "ComputerName\SharedSubFolder-to-the-mp3-folder\"
Response.Buffer = True
Dim Mysec
Mysec = Timer
%>
<div align="center">
<form name="form1" method="get" action="">
<input type="text" name="alike" size="40" value="<%=Request.Querystring("alike")%>">
<input type="submit" name="Submit" value="Search">
<input type="submit" name="Download Playlist" value="Download Playlist">
<input type="submit" name="Download LAN-Playtlist" value="Download LAN-Playtlist">
</form>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="7%">Number</td>
<td width="7%">Seconds</td>
<td width="12%">BitRate</td>
<td width="74%">Album - Artist - Track - Title</td>
</tr>
<tr>
<td width="7%"> </td>
<td width="7%"> </td>
<td width="12%"> </td>
<td width="74%"> </td>
</tr>
<%
Dim TextArr(4999,1)
Set m3uObject = Server.CreateObject("Scripting.FileSystemObject")
Set m3uFile = m3uObject.OpenTextFile(Server.MapPath("Raw\Raw.m3u"),1)
m3uFile.SkipLine
do while m3uFile.AtEndOfStream = false
LineCount = LineCount + 1
TextArr(LineCount,0) = m3uFile.ReadLine
TextArr(LineCount,1) = m3uFile.ReadLine
loop
m3uFile.Close
Set m3uFile = Nothing
Set m3uObject = Nothing
set PlayListObject = Server.CreateObject("Scripting.FileSystemObject")
set FileM3u = PlayListObject.CreateTextFile(Server.Mappath(Request.Querystring("alike") & ".m3u"),true)
FileM3u.WriteLine("#EXTM3U")
For ReadArr = 1 to 4999
If inStr(LCase(TextArr(ReadArr,0)),LCase(Request.Querystring("alike"))) or inStr(LCase(TextArr(ReadArr,1)),LCase(Request.Querystring("alike"))) Then
if Request.Querystring("Download LAN-Playtlist") = "Download LAN-Playtlist" then
FileM3u.WriteLine(Replace(TextArr(ReadArr,0),"G:\","\\" & NetPatch )
FileM3u.WriteLine(Replace(TextArr(ReadArr,1),"G:\","\\" & NetPatch )
else
FileM3u.WriteLine(TextArr(ReadArr,0))
FileM3u.WriteLine(TextArr(ReadArr,1))
end if
'-<<Open ID3 tags>>-
if Request.Querystring("alike") <> "" and Request.Querystring("Download Playlist") = "" and Request.Querystring("Download LAN-Playtlist") = "" then
Set sf = Server.CreateObject("newObjects.utilctls.SFMain")
Set file = sf.OpenFile(TextArr(ReadArr,1),&H40)
Set mp3 = New CMP3Frame
Set mp3.stream = file
If mp3.FindFrame Then
'MP3Version = mp3.Version
'MP3Layer = mp3.Layer
'MP3Protection = mp3.Protection
MP3Bitrate = mp3.BitRate
'MP3Frequency = mp3.Freq
'MP3Padded = mp3.Padded
'MP3Channelmode = mp3.ChannelMode
'MP3Copyright = mp3.Copyright
'MP3Original = mp3.Original
'MP3Emphasis = mp3.Emphasis
'MP3framesize = mp3.FrameSize
'MP3frames = mp3.FramesCount
If mp3.ReadIDTag Then
mp3Title = mp3.Title
mp3Album = mp3.Album
mp3Artist = mp3.Artist
'mp3Year = mp3.Year
'mp3Comment = mp3.Comment
'mp3Genrecode = mp3.GenreCode
'mp3Genre = mp3.GenreText
End If
Else
Response.Write("Error")
End If
End if
'--<<end id3>>--
TimeLength = split(Replace(TextArr(ReadArr,0),"#EXTINF:",""),",")
TimeSeconds = int((TimeLength(0)/60 - int(TimeLength(0)/60)) * 60)
TimeMinutes = int(TimeLength(0)/60)
PlayListMin = PlayListMin + TimeMinutes
PlayListSec = PlayListMin + TimeSeconds
MatchCount = MatchCount + 1
%>
<tr>
<td width="7%"><%=ReadArr%></td>
<td width="7%"><%=TimeMinutes & ":" & TimeSeconds%></td>
<td width="12%">
<%
MP3Bitrate = Replace(MP3Bitrate,"48","48 (Variable)")
MP3Bitrate = Replace(MP3Bitrate,"64","64 (Variable)")
If Request.Querystring("alike") <> "" then
Response.Write MP3Bitrate
else
Response.Write "Out of Bunds"
end if
%>
</td>
<td width="74%">
<%
For TimeLengthRead = 1 to UBound(TimeLength)
Response.Write "<a Title="""
Response.Write "Artist: " & mp3Artist & Chr(10)
Response.Write "Title: " & mp3Title & Chr(10)
Response.Write "Ablum: " & mp3Album
Response.Write """href=""" & Replace(TextArr(ReadArr,1),"G:\","\\" & NetPatch & ")
Response.Write """>" & TimeLength(TimeLengthRead) & "</a>"
Next
mp3Artist = "" : mp3Title = "" : mp3Album = "" : MP3Bitrate = ""
%>
</td>
</tr>
<%
End if
Next
FileM3u.Close
set FileM3u = nothing
set PlayListObject = nothing
%>
<tr>
<td width="7%"> </td>
<td width="7%"> </td>
<td width="12%"> </td>
<td width="74%"> </td>
</tr>
<tr>
<td width="7%">Total</td>
<td colspan="2">
<%
TotalMins = int(PlayListMin + (PlayListSec/60 - int(PlayListSec/60)))
TotalSecs = PlayListSec - (int(PlayListSec/60)*60)
TotalHours = int(TotalMins/60)
TotalMins = int(((TotalMins/60) - TotalHours) * 60)
Response.Write TotalHours & "h: " & TotalMins& "m: " & TotalSecs & "s"
%>
</td>
<td width="74%"> <%="Total Matches: " & MatchCount%> </td>
</tr>
</table>
<%
if Request.Querystring("Download Playlist") <> "" or Request.Querystring("Download LAN-Playtlist") <> "" then
Response.Redirect(Request.Querystring("alike") & ".m3u")
end if
%>
<%
If MatchCount = "" then
set EmptyFileDeleteObject = Server.CreateObject("Scripting.FileSystemObject")
set EmptyFile = EmptyFileDeleteObject.GetFile(Server.Mappath(Request.Querystring("alike") & ".m3u"))
EmptyFile.Delete
set EmptyFile = nothing
set EmptyFileDeleteObject = nothing
end if
%>
<%
Response.Write(Timer - Mysec & " Seconds")
%>
</div>
[/INDEX.ASP]
[mp3Tools.ASP]
<%
Dim V1L1(15), V1L2(15), V1L3(15), V2L1(15), V2L2(15), V2L3(15)
V1L1(0) = "variable"
V1L1(1) = 32
V1L1(2) = 64
V1L1(3) = 96
V1L1(4) = 128
V1L1(5) = 160
V1L1(6) = 192
V1L1(7) = 224
V1L1(8) = 256
V1L1(9) = 288
V1L1(10) = 320
V1L1(11) = 352
V1L1(12) = 384
V1L1(13) = 416
V1L1(14) = 448
V1L1(15) = "bad"
V1L2(0) = "variable"
V1L2(1) = 32
V1L2(2) = 48
V1L2(3) = 56
V1L2(4) = 64
V1L2(5) = 80
V1L2(6) = 96
V1L2(7) = 112
V1L2(8) = 128
V1L2(9) = 160
V1L2(10) = 192
V1L2(11) = 224
V1L2(12) = 256
V1L2(13) = 320
V1L2(14) = 384
V1L2(15) = "bad"
V1L3(0) = "variable"
V1L3(1) = 32
V1L3(2) = 40
V1L3(3) = 48
V1L3(4) = 56
V1L3(5) = 64
V1L3(6) = 80
V1L3(7) = 96
V1L3(8) = 112
V1L3(9) = 128
V1L3(10) = 160
V1L3(11) = 192
V1L3(12) = 224
V1L3(13) = 256
V1L3(14) = 320
V1L3(15) = "bad"
V2L1(0) = "variable"
V2L1(1) = 32
V2L1(2) = 48
V2L1(3) = 56
V2L1(4) = 64
V2L1(5) = 80
V2L1(6) = 96
V2L1(7) = 112
V2L1(8) = 128
V2L1(9) = 144
V2L1(10) = 160
V2L1(11) = 176
V2L1(12) = 192
V2L1(13) = 224
V2L1(14) = 256
V2L1(15) = "bad"
V2L2(0) = "variable"
V2L2(1) = 8
V2L2(2) = 16
V2L2(3) = 24
V2L2(4) = 32
V2L2(5) = 40
V2L2(6) = 48
V2L2(7) = 56
V2L2(8) = 64
V2L2(9) = 80
V2L2(10) = 96
V2L2(11) = 112
V2L2(12) = 128
V2L2(13) = 144
V2L2(14) = 160
V2L2(15) = "bad"
V2L3(0) = "variable"
V2L3(1) = 8
V2L3(2) = 16
V2L3(3) = 24
V2L3(4) = 32
V2L3(5) = 40
V2L3(6) = 48
V2L3(7) = 56
V2L3(8) = 64
V2L3(9) = 80
V2L3(10) = 96
V2L3(11) = 112
V2L3(12) = 128
V2L3(13) = 144
V2L3(14) = 160
V2L3(15) = "bad"
Dim F(3,3)
F(3,0) = 44100
F(2,0) = 22050
F(0,0) = 11025
F(1,0) = "Unknown"
F(3,1) = 48000
F(2,1) = 24000
F(0,1) = 12000
F(1,1) = "Unknown"
F(3,2) = 32000
F(2,2) = 16000
F(0,2) = 8000
F(1,2) = "Unknown"
F(3,3) = "Unknown"
F(2,3) = "Unknown"
F(0,3) = "Unknown"
F(1,3) = "Unknown"
Dim Genre(80)
Genre( 0) = "Blues"
Genre( 1) = "Classic Rock"
Genre( 2) = "Country"
Genre( 3) = "Dance"
Genre( 4) = "Disco"
Genre( 5) = "Funk"
Genre( 6) = "Grunge"
Genre( 7) = "Hip-Hop"
Genre( 8) = "Jazz"
Genre( 9) = "Metal"
Genre(10) = "New Age"
Genre(11) = "Oldies"
Genre(12) = "Other"
Genre(13) = "Pop"
Genre(14) = "R&B"
Genre(15) = "Rap"
Genre(16) = "Reggae"
Genre(17) = "Rock"
Genre(18) = "Techno"
Genre(19) = "Industrial"
Genre(20) = "Alternative"
Genre(21) = "Ska"
Genre(22) = "Death Metal"
Genre(23) = "Pranks"
Genre(24) = "Soundtrack"
Genre(25) = "Euro-Techno"
Genre(26) = "Ambient"
Genre(27) = "Trip-Hop"
Genre(28) = "Vocal"
Genre(29) = "Jazz+Funk"
Genre(30) = "Fusion"
Genre(31) = "Trance"
Genre(32) = "Classical"
Genre(33) = "Instrumental"
Genre(34) = "Acid"
Genre(35) = "House"
Genre(36) = "Game"
Genre(37) = "Sound Clip"
Genre(38) = "Gospel"
Genre(39) = "Noise"
Genre(40) = "AlternRock"
Genre(41) = "Bass"
Genre(42) = "Soul"
Genre(43) = "Punk"
Genre(44) = "Space"
Genre(45) = "Meditative"
Genre(46) = "Instrumental Pop"
Genre(47) = "Instrumental Rock"
Genre(48) = "Ethnic"
Genre(49) = "Gothic"
Genre(50) = "Darkwave"
Genre(51) = "Techno-Industrial"
Genre(52) = "Electronic"
Genre(53) = "Pop-Folk"
Genre(54) = "Eurodance"
Genre(55) = "Dream"
Genre(56) = "Southern Rock"
Genre(57) = "Comedy"
Genre(58) = "Cult"
Genre(59) = "Gangsta"
Genre(60) = "Top 40"
Genre(61) = "Christian Rap"
Genre(62) = "Pop/Funk"
Genre(63) = "Jungle"
Genre(64) = "Native American"
Genre(65) = "Cabaret"
Genre(66) = "New Wave"
Genre(67) = "Psychadelic"
Genre(68) = "Rave"
Genre(69) = "Showtunes"
Genre(70) = "Trailer"
Genre(71) = "Lo-Fi"
Genre(72) = "Tribal"
Genre(73) = "Acid Punk"
Genre(74) = "Acid Jazz"
Genre(75) = "Polka"
Genre(76) = "Retro"
Genre(77) = "Musical"
Genre(78) = "Rock & Roll"
Genre(79) = "Hard Rock"
Genre(80) = "Unknown"
Class CMP3Frame
Public stream
' MP3 infor properties
Public Version, Layer, Protection, BitRate, Freq, Padded, ChannelMode, ModeExt, Copyright, Original, Emphasis
Public nVersion, nLayer, nProtection, nBitRate, nFreq, nPadded, nChannelMode, nModeExt, nCopyright, nOriginal, nEmphasis
Public FrameSize
Public Title, Artist, Album, Year, Comment, GenreText, GenreCode
Public FramePos, IsRead
Private flt, bitLogic
Private Sub Class_Initialize()
Set flt = Server.CreateObject("newObjects.utilctls.SFFilter")
flt.buffSize = 4
Set bitLogic = Server.CreateObject("newObjects.utilctls.TypeConvertor")
FramePos = 0
FrameSize = 0
IsRead = False
End Sub
Public Function ReadIDTag
Dim pos, rec
pos = stream.Pos
Set rec = Server.CreateObject("newObjects.utilctls.SFRecord")
rec.AddField "TAG", vbString, 3
rec.AddField "Title", vbString, 30
rec.AddField "Artist", vbString, 30
rec.AddField "Album", vbString, 30
rec.AddField "Year", vbString, 4
rec.AddField "Comment", vbString, 30
rec.AddField "Genre", vbByte, 1
rec.BindTo stream
rec.Filter.unicodeText = False
rec.ReBind
stream.Pos = stream.Size - 128
If Not rec.Read Then
ReadIDTag = False
stream.Pos = pos
Exit Function
End If
stream.Pos = pos
If rec("TAG").Value <> "TAG" Then
ReadIDTag = False
Exit Function
End If
Title = rec("Title").Value
Album = rec("Album").Value
Artist = rec("Artist").Value
Year = rec("Year").Value
Comment = rec("Comment").Value
GenreCode = rec("Genre").Value
If GenreCode <= UBound(Genre) Then
GenreText = Genre(GenreCode)
Else
GenreText = "Unknown"
End If
ReadIDTag = True
End Function
Public Function ReadFrame
If Not flt.Read(stream) Then
ReadFrame = False
Exit Function
End If
Dim head, b
head = 0
b = flt.GetVar(vbByte,1)
head = bitLogic.BitOr(head,bitLogic.BitLeft(b,24))
b = flt.GetVar(vbByte,1)
head = bitLogic.BitOr(head,bitLogic.BitLeft(b,16))
b = flt.GetVar(vbByte,1)
head = bitLogic.BitOr(head,bitLogic.BitLeft(b,8))
b = flt.GetVar(vbByte,1)
head = bitLogic.BitOr(head,b)
If CalcProps(head) Then
IsRead = True
FramePos = stream.Pos - 4
ReadFrame = True
Else
IsRead = False
FramePos = 0
ReadFrame = False
End If
End Function
Public Function FindFrame
Dim head, b, pos
pos = stream.Pos
While flt.Read(stream)
head = 0
b = flt.GetVar(vbByte,1)
head = bitLogic.BitOr(head,bitLogic.BitLeft(b,24))
b = flt.GetVar(vbByte,1)
head = bitLogic.BitOr(head,bitLogic.BitLeft(b,16))
b = flt.GetVar(vbByte,1)
head = bitLogic.BitOr(head,bitLogic.BitLeft(b,8))
b = flt.GetVar(vbByte,1)
head = bitLogic.BitOr(head,b)
If CalcProps(head) Then
FramePos = stream.Pos - 4
FindFrame = True
IsRead = True
Exit Function
Else
stream.Pos = pos + 1
pos = pos + 1
End If
Wend
IsRead = False
FramePos = 0
FindFrame = False
End Function
Public Function ReadNextFrame
If Not IsRead Or FrameSize = 0 Then
ReadNextFrame = False
Else
stream.Pos = FramePos + FrameSize
ReadNextFrame = ReadFrame
End If
End Function
Public Property Get FramesCount
If FrameSize > 0 Then
FramesCount = Int(stream.Size / FrameSize)
Else
FramesCount = 0
End If
End Property
Private Function CalcProps(h)
If bitLogic.BitAnd(&HFFE00000,h) <> &HFFE00000 Then
' Not a frame
CalcProps = False
Exit Function
End If
' Calc audio ver
nVersion = bitLogic.BitAnd(&H00000003,bitLogic.BitRight(h,19))
Select Case nVersion
Case 0
Version = "MPEG Version 2.5"
Case 1
Version = "Unknown"
Case 2
Version = "MPEG Version 2"
Case 3
Version = "MPEG Version 1"
End Select
' Layer descr
nLayer = bitLogic.BitAnd(&H00000003,bitLogic.BitRight(h,17))
Select Case nLayer
Case 0
Layer = "Unknown"
Case 1
Layer = "Layer III"
Case 2
Layer = "Layer II"
Case 3
Layer = "Layer I"
End Select
' Protection
nProtection = bitLogic.BitAnd(&H00000001,bitLogic.BitRight(h,16))
Select Case nProtection
Case 0
Protection = "CRC-16"
Case 1
Protection = "none"
End Select
' BitRate
nBitRate = bitLogic.BitAnd(&H0000000F,bitLogic.BitRight(h,12))
If nVersion = 3 Then
' Version 1
Select Case nLayer
Case 3
BitRate = V1L1(nBitRate)
Case 2
BitRate = V1L2(nBitRate)
Case 1
BitRate = V1L3(nBitRate)
Case Else
BitRate = "Unknown"
End Select
ElseIf nVersion = 2 Or nVersion = 0 Then
' Version 2
Select Case nLayer
Case 3
BitRate = V2L1(nBitRate)
Case 2
BitRate = V2L2(nBitRate)
Case 1
BitRate = V2L3(nBitRate)
Case Else
BitRate = "Unknown"
End Select
Else
BitRate = "Unknown"
End IF
' Sampling rate
nFreq = bitLogic.BitAnd(&H00000003,bitLogic.BitRight(h,10))
Freq = F(nVersion,nFreq)
' Padding
nPadded = bitLogic.BitAnd(&H00000001,bitLogic.BitRight(h,9))
Padded = nPadded
' Channel mode
nChannelMode = bitLogic.BitAnd(&H00000003,bitLogic.BitRight(h,6))
Select Case nChannelMode
Case 0
ChannelMode = "Stereo"
Case 1
ChannelMode = "Joint Stereo"
Case 2
ChannelMode = "Dual channel"
Case 3
ChannelMode = "Mono"
End Select
' ModeExt
nModeExt = bitLogic.BitAnd(&H00000003,bitLogic.BitRight(h,4))
ModeExt = ""
' Copyright bit
nCopyright = bitLogic.BitAnd(&H00000001,bitLogic.BitRight(h,3))
If nCopyright <> 0 Then
Copyright = "Yes"
Else
Copyright = "No"
End If
nOriginal = bitLogic.BitAnd(&H00000001,bitLogic.BitRight(h,2))
If nOriginal Then Original = "Original" Else Original = "Copy"
nEmphasis = bitLogic.BitAnd(&H00000003,h)
Select Case nEmphasis
Case 0
Emphasis = "none"
Case 1
Emphasis = "50/15 ms"
Case 2
Emphasis = "Unknown"
Case 3
Emphasis = "CCIT J.17"
End Select
FrameSize = 0
If IsNumeric(BitRate) And IsNumeric(Freq) Then
If nLayer = 3 Then
' Layer 1
If nVersion = 3 Then
' Mpeg ver 1
FrameSize = Int((48 * CDbl(BitRate * 1000))/CDbl(Freq) + nPadded)
Else
' Mpeg ver 2 and 2.5
FrameSize = Int((24 * CDbl(BitRate * 1000))/CDbl(Freq) + nPadded)
End If
ElseIf nLayer = 2 Or nLayer = 1 Then
' Layer 2 and 3
If nVersion = 3 Then
' Mpeg 1
FrameSize = Int((144 * CDbl(BitRate * 1000))/CDbl(Freq) + nPadded)
Else
' Mpeg ver 2 and 2.5
FrameSize = Int((72 * CDbl(BitRate * 1000))/CDbl(Freq) + nPadded)
End If
Else
FrameSize = 0
End If
End If
CalcProps = True
End Function
End Class
Class CMP3Stats
' ID tag entries
Public Title, Artist, Album, Year, Comment, GenreCode,GenreText
' MP3 info - first frame
Public Version, Layer, Protection, BitRate, Freq, Padded, ChannelMode, ModeExt, Copyright, Original, Emphasis, FrameSize
' Stats info
Public avBitRate, avFreq, FramesCount
Function GetInfo(file)
Dim sf, strm
Set sf = Server.CreateObject("newObjects.utilctls.SFMain")
Set strm = sf.OpenFile(file,&H40)
GetInfo = GetMP3Info(strm)
Set strm = Nothing
Set sf = Nothing
End Function
Function GetMP3Info(stream)
Dim mp3
Set mp3 = New CMP3Frame
Set mp3.stream = stream
If mp3.FindFrame Then
Version = mp3.Version
Layer = mp3.Layer
Protection = mp3.Protection
BitRate = mp3.BitRate
Freq = mp3.Freq
Padded = mp3.Padded
ChannelMode = mp3.ChannelMode
Copyright = mp3.Copyright
Original = mp3.Original
Emphasis = mp3.Emphasis
FrameSize = mp3.FrameSize
If IsNumeric(mp3.Freq) and IsNumeric(mp3.BitRate) Then
FramesCount = 1
avFreq = CDbl(mp3.Freq)
avBitRate = CDbl(mp3.BitRate)
While mp3.ReadNextFrame
If IsNumeric(mp3.Freq) and IsNumeric(mp3.BitRate) Then
avFreq = avFreq + CDbl(mp3.Freq)
avBitRate = avBitRate + CDbl(mp3.BitRate)
FramesCount = FramesCount + 1
End If
Wend
avFreq = avFreq / FramesCount
avBitRate = avBitRate / FramesCount
Else
FramesCount = 0
avFreq = 0
avBitRate = 0
End If
If mp3.ReadIDTag Then
Title = mp3.Title
Artist = mp3.Artist
Album = mp3.Album
Year = mp3.Year
Comment = mp3.Comment
GenreCode = mp3.GenreCode
GenreText = mp3.GenreText
Else
Title = ""
Artist = ""
Album = ""
Year = ""
Comment = ""
GenreCode = 0
GenreText = ""
End If
GetMP3Info = True
Else
GetMP3Info = False
End If
End Function
End Class
%>
[/mp3Tools.ASP]
