如何在 Vbscript 中检查视频或音频流是否在线?
How to check if a video or an audio stream is online or not in Vbscript?
我想知道在 vbscript 中检查视频或音频流是否在线时要查找的参数或值是什么?
所以这就是我到目前为止尝试的代码,但是,它给了我一个错误的结果,因为我已经用 VLC 检查了所有这些流并且它们工作 5/5,但是这个脚本是第二个和第三个流给我离线 ??
Option Explicit
Dim Title,URLArray,URL,ws,Msg,Data
Title = "Audio and Video Stream Checker"
URLArray = Array("https://5ac31d8a4c9af.streamlock.net/saheltv/_definst_/myStream/chunklist_w956788169.m3u8"_
,"http://aska.ru-hoster.com:8053/autodj"_
,"http://www.chocradios.ch/djbuzzradio_windows.mp3.asx")
Call ForceCScriptExecution()
For Each URL in URLArray
wscript.echo "The stream " & URL & " is "& CheckOnline(URL) & vbCrlf & String(100,"-")
Next
'----------------------------------------------------
Function CheckOnline(URL)
On Error Resume Next
Const WHR_EnableRedirects = 6
Dim h,AllResponseHeaders
Set h = CreateObject("WinHttp.WinHttpRequest.5.1")
h.Option(WHR_EnableRedirects) = False 'disable redirects
h.Open "HEAD", URL , False
h.Send()
AllResponseHeaders = h.GetAllResponseHeaders()
wscript.echo AllResponseHeaders
If Err.number = 0 Then
If h.status = 200 OR h.status = 201 OR h.status = 202 OR h.status = 203 OR h.status = 204 Then
CheckOnline = "ONLINE"
Else
CheckOnline = "OFFLINE"
End IF
Else
CheckOnline = "OFFLINE" & vbCrlf & Err.Description
On Error Goto 0
End IF
End Function
'----------------------------------------------------
Sub ForceCScriptExecution()
Dim Arg, Str, cmd
cmd = "CMD /K Title " & Title &" & color 0A & "
If Not LCase( Right( WScript.FullName, 12 ) ) = "\cscript.exe" Then
For Each Arg In WScript.Arguments
If InStr( Arg, " " ) Then Arg = """" & Arg & """"
Str = Str & " " & Arg
Next
CreateObject( "WScript.Shell" ).Run _
cmd & "cscript //nologo """ & _
WScript.ScriptFullName & _
""" " & Str
WScript.Quit
End If
End Sub
'--------------------------------------------------
我得到的回复是这样的:
Cache-Control: no-cache
Date: Sat, 28 Dec 2019 00:14:27 GMT
Content-Length: 232
Content-Type: application/vnd.apple.mpegurl
Accept-Ranges: bytes
Server: WowzaStreamingEngine/4.7.8
Access-Control-Expose-Headers: Date, Server, Content-Type, Content-Length
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: OPTIONS, GET, POST, HEAD
Access-Control-Allow-Headers: Content-Type, User-Agent, If-Modified-Since, Cache-Control, Range
The stream https://5ac31d8a4c9af.streamlock.net/saheltv/_definst_/myStream/chunklist_w956788169.m3u8 is ONLINE
-------------------------------------------------------------------------------
Cache-Control: no-cache
Date: Sat, 28 Dec 2019 00:14:28 GMT
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Server: Icecast 2.4.2
The stream http://aska.ru-hoster.com:8053/autodj is OFFLINE
-------------------------------------------------------------------------------
Connection: keep-alive
Date: Sat, 28 Dec 2019 00:14:28 GMT
Content-Type: text/html; charset=iso-8859-1
Location: https://www.chocradios.ch/djbuzzradio_windows.mp3.asx
Server: nginx
X-Powered-By: PleskLin
The stream http://www.chocradios.ch/djbuzzradio_windows.mp3.asx is OFFLINE
-------------------------------------------------------------------------------
以下是 WMP 的可能实现方式:
Option Explicit
forceCScriptExecution "Audio and Video Stream Checker"
testStreams
Sub testStreams()
Dim urls
Dim sourceUrl
Dim isOnline
Dim mediaName
Dim streamUrl
urls = Array(_
"https://5ac31d8a4c9af.streamlock.net/saheltv/_definst_/myStream/chunklist_w956788169.m3u8", _
"http://aska.ru-hoster.com:8053/autodj", _
"http://www.chocradios.ch/djbuzzradio_windows.mp3.asx" _
)
For Each sourceUrl In urls
WScript.Echo ""
WScript.Echo "sourceUrl " & sourceUrl
WScript.Echo "Checking..."
checkStreamOnline sourceUrl, 30, isOnline, mediaName, streamUrl
WScript.Echo "isOnline " & isOnline
WScript.Echo "mediaName " & mediaName
WScript.Echo "streamUrl " & streamUrl
Next
End Sub
Sub checkStreamOnline(sourceUrl, timeout, isOnline, mediaName, streamUrl)
Dim wmp
Dim isTimeout
Dim t
Set wmp = CreateObject("WMPlayer.OCX")
wmp.settings.autostart = False
wmp.url = sourceUrl
wmp.settings.volume = 0
wmp.controls.play
t = DateAdd("s", timeout, Now)
Do
isOnline = wmp.playState = 3
isTimeout = Now >= t
WScript.Sleep 5
Loop Until isOnline Or isTimeout
mediaName = wmp.currentMedia.Name
streamUrl = wmp.currentMedia.sourceUrl
wmp.controls.stop
End Sub
Sub forceCScriptExecution(title)
Dim arg, args, cmd
cmd = "%comspec% /K Title " & title &" & color 0A & "
If Not LCase(Right(WScript.FullName, 12)) = "\cscript.exe" Then
For Each arg In WScript.Arguments
If InStr(arg, " ") Then arg = """" & arg & """"
args = args & " " & arg
Next
CreateObject("WScript.Shell").Run _
cmd & "cscript //nologo """ & _
WScript.ScriptFullName & _
""" " & args
WScript.Quit
End If
End Sub
我想知道在 vbscript 中检查视频或音频流是否在线时要查找的参数或值是什么?
所以这就是我到目前为止尝试的代码,但是,它给了我一个错误的结果,因为我已经用 VLC 检查了所有这些流并且它们工作 5/5,但是这个脚本是第二个和第三个流给我离线 ??
Option Explicit
Dim Title,URLArray,URL,ws,Msg,Data
Title = "Audio and Video Stream Checker"
URLArray = Array("https://5ac31d8a4c9af.streamlock.net/saheltv/_definst_/myStream/chunklist_w956788169.m3u8"_
,"http://aska.ru-hoster.com:8053/autodj"_
,"http://www.chocradios.ch/djbuzzradio_windows.mp3.asx")
Call ForceCScriptExecution()
For Each URL in URLArray
wscript.echo "The stream " & URL & " is "& CheckOnline(URL) & vbCrlf & String(100,"-")
Next
'----------------------------------------------------
Function CheckOnline(URL)
On Error Resume Next
Const WHR_EnableRedirects = 6
Dim h,AllResponseHeaders
Set h = CreateObject("WinHttp.WinHttpRequest.5.1")
h.Option(WHR_EnableRedirects) = False 'disable redirects
h.Open "HEAD", URL , False
h.Send()
AllResponseHeaders = h.GetAllResponseHeaders()
wscript.echo AllResponseHeaders
If Err.number = 0 Then
If h.status = 200 OR h.status = 201 OR h.status = 202 OR h.status = 203 OR h.status = 204 Then
CheckOnline = "ONLINE"
Else
CheckOnline = "OFFLINE"
End IF
Else
CheckOnline = "OFFLINE" & vbCrlf & Err.Description
On Error Goto 0
End IF
End Function
'----------------------------------------------------
Sub ForceCScriptExecution()
Dim Arg, Str, cmd
cmd = "CMD /K Title " & Title &" & color 0A & "
If Not LCase( Right( WScript.FullName, 12 ) ) = "\cscript.exe" Then
For Each Arg In WScript.Arguments
If InStr( Arg, " " ) Then Arg = """" & Arg & """"
Str = Str & " " & Arg
Next
CreateObject( "WScript.Shell" ).Run _
cmd & "cscript //nologo """ & _
WScript.ScriptFullName & _
""" " & Str
WScript.Quit
End If
End Sub
'--------------------------------------------------
我得到的回复是这样的:
Cache-Control: no-cache
Date: Sat, 28 Dec 2019 00:14:27 GMT
Content-Length: 232
Content-Type: application/vnd.apple.mpegurl
Accept-Ranges: bytes
Server: WowzaStreamingEngine/4.7.8
Access-Control-Expose-Headers: Date, Server, Content-Type, Content-Length
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: OPTIONS, GET, POST, HEAD
Access-Control-Allow-Headers: Content-Type, User-Agent, If-Modified-Since, Cache-Control, Range
The stream https://5ac31d8a4c9af.streamlock.net/saheltv/_definst_/myStream/chunklist_w956788169.m3u8 is ONLINE
-------------------------------------------------------------------------------
Cache-Control: no-cache
Date: Sat, 28 Dec 2019 00:14:28 GMT
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Server: Icecast 2.4.2
The stream http://aska.ru-hoster.com:8053/autodj is OFFLINE
-------------------------------------------------------------------------------
Connection: keep-alive
Date: Sat, 28 Dec 2019 00:14:28 GMT
Content-Type: text/html; charset=iso-8859-1
Location: https://www.chocradios.ch/djbuzzradio_windows.mp3.asx
Server: nginx
X-Powered-By: PleskLin
The stream http://www.chocradios.ch/djbuzzradio_windows.mp3.asx is OFFLINE
-------------------------------------------------------------------------------
以下是 WMP 的可能实现方式:
Option Explicit
forceCScriptExecution "Audio and Video Stream Checker"
testStreams
Sub testStreams()
Dim urls
Dim sourceUrl
Dim isOnline
Dim mediaName
Dim streamUrl
urls = Array(_
"https://5ac31d8a4c9af.streamlock.net/saheltv/_definst_/myStream/chunklist_w956788169.m3u8", _
"http://aska.ru-hoster.com:8053/autodj", _
"http://www.chocradios.ch/djbuzzradio_windows.mp3.asx" _
)
For Each sourceUrl In urls
WScript.Echo ""
WScript.Echo "sourceUrl " & sourceUrl
WScript.Echo "Checking..."
checkStreamOnline sourceUrl, 30, isOnline, mediaName, streamUrl
WScript.Echo "isOnline " & isOnline
WScript.Echo "mediaName " & mediaName
WScript.Echo "streamUrl " & streamUrl
Next
End Sub
Sub checkStreamOnline(sourceUrl, timeout, isOnline, mediaName, streamUrl)
Dim wmp
Dim isTimeout
Dim t
Set wmp = CreateObject("WMPlayer.OCX")
wmp.settings.autostart = False
wmp.url = sourceUrl
wmp.settings.volume = 0
wmp.controls.play
t = DateAdd("s", timeout, Now)
Do
isOnline = wmp.playState = 3
isTimeout = Now >= t
WScript.Sleep 5
Loop Until isOnline Or isTimeout
mediaName = wmp.currentMedia.Name
streamUrl = wmp.currentMedia.sourceUrl
wmp.controls.stop
End Sub
Sub forceCScriptExecution(title)
Dim arg, args, cmd
cmd = "%comspec% /K Title " & title &" & color 0A & "
If Not LCase(Right(WScript.FullName, 12)) = "\cscript.exe" Then
For Each arg In WScript.Arguments
If InStr(arg, " ") Then arg = """" & arg & """"
args = args & " " & arg
Next
CreateObject("WScript.Shell").Run _
cmd & "cscript //nologo """ & _
WScript.ScriptFullName & _
""" " & args
WScript.Quit
End If
End Sub