Jump to content

Recording Service status into a variable


majstang

Recommended Posts

the basic url is:

http://[user:password@]IP[:port]/api

I assume if you going to mess with a web api you know what this means and which parameters are needed or not. :lol:

if I refer to URL in the examples I mean the above construct.

 

All answers are xml "files"

 

The Status of the service:

url/status.html

Is this the only way to query the status of the service (if recordings are active or not)? Is there some other way or maybe some windows process that changes whenever a recording is active. The only trace in windows (if not using the webinterface) when a recording starts seem to be the RS tray icon goes red.

 

To answer my own question i found a way to get the status of Recording Service into a variable. This will make it easier for those who wanna make for example VBScripts which is dependant on RS status. The script separates the Tooltip string of the RS systray icon and tells you if:

DVBViewer Service is idle.

or

DVBViewer Service is recording.

 

It is a autohotkey script but is usable in a VBScript with run command.

 

#NoTrayIcon
DetectHiddenWindows, On

OutputVar := TrayIcons("DVBVCtrl.exe")
FoundPos := RegExMatch(OutputVar, "(?<=Tooltip:)(.*)", SubPat)
MsgBox % SubPat
Return

/*
WM_MOUSEMOVE   = 0x0200
WM_LBUTTONDOWN   = 0x0201
WM_LBUTTONUP   = 0x0202
WM_LBUTTONDBLCLK= 0x0203
WM_RBUTTONDOWN   = 0x0204
WM_RBUTTONUP   = 0x0205
WM_RBUTTONDBLCLK= 0x0206
WM_MBUTTONDOWN   = 0x0207
WM_MBUTTONUP   = 0x0208
WM_MBUTTONDBLCLK= 0x0209

PostMessage, nMsg, uID, WM_RBUTTONDOWN, , ahk_id %hWnd%
PostMessage, nMsg, uID, WM_RBUTTONUP  , , ahk_id %hWnd%
*/


TrayIcons(sExeName)
{
  WinGet,   pidTaskbar, PID, ahk_class Shell_TrayWnd
  hProc:=   DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
  pProc:=   DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
  idxTB:=   GetTrayBar()
     SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
  Loop,   %ErrorLevel%
  {
     SendMessage, 0x417, A_Index-1, pProc, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_GETBUTTON
     VarSetCapacity(btn,32,0), VarSetCapacity(nfo,32,0)
     DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)
        iBitmap   := NumGet(btn, 0)
        idn   := NumGet(btn, 4)
        Statyle := NumGet(btn, 8)
     If   dwData   := NumGet(btn,12)
        iString   := NumGet(btn,16)
     Else   dwData   := NumGet(btn,16,"int64"), iString:=NumGet(btn,24,"int64")
     DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 32, "Uint", 0)
     If   NumGet(btn,12)
        hWnd   := NumGet(nfo, 0)
     ,   uID   := NumGet(nfo, 4)
     ,   nMsg   := NumGet(nfo, 8)
     ,   hIcon   := NumGet(nfo,20)
     Else   hWnd   := NumGet(nfo, 0,"int64"), uID:=NumGet(nfo, 8), nMsg:=NumGet(nfo,12)
     WinGet, pid, PID,              ahk_id %hWnd%
     WinGet, sProcess, ProcessName, ahk_id %hWnd%
     WinGetClass, sClass,           ahk_id %hWnd%
     If !sExeName || (sExeName = sProcess) || (sExeName = pid)
        VarSetCapacity(sTooltip,128), VarSetCapacity(wTooltip,128*2)
     ,   DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128*2, "Uint", 0)
     ,   DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
     ,   sTrayIcons .= "idx: " . A_Index-1 . " | idn: " . idn . " | Pid: " . pid . " | uID: " . uID . " | MessageID: " . nMsg . " | hWnd: " . hWnd . " | Class: " . sClass . " | Process: " . sProcess . "`n" . "   | Tooltip: " . sTooltip . "`n"
  }
  DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
  DllCall("CloseHandle", "Uint", hProc)
  Return   sTrayIcons
}

GetTrayBar()
{
       ControlGet, hParent, hWnd,, TrayNotifyWnd1  , ahk_class Shell_TrayWnd
       ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
  Loop
  {
     ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
     If  Not   hWnd
        Break
     Else If   hWnd = %hChild%
     {
        idxTB := A_Index
        Break
     }
  }
  Return   idxTB
}

Link to comment

Found an another solution getting status and other stuff from RS direct as a variable without using DVBViewer COM. It is called URL download to a variable. Again in Autohotkey unfortunatley (to use Autohotkey you need to download and install it). Works and tested with XP. For example getting status from RS, simply punch in your URL http://username:password@IP:Port/api/status.html into the script and execute it and you will have RS status in a messagebox/variable.

0=RS is idle.

1 or higher=RS is recording

 

OutputVar := UrlDownloadToVar("http://xxxx:xxxxx@127.0.0.1:8075/api/status.html")
FoundPos := RegExMatch(OutputVar, "(?<=recordcount>)(.)", SubPat)
MsgBox, % SubPat

UrlDownloadToVar(URL, Proxy="", ProxyBypass="") {
AutoTrim, Off
hModule := DllCall("LoadLibrary", "str", "wininet.dll") 

If (Proxy != "")                                                          
AccessType=3
Else
AccessType=1
;INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
;INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
;INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
;INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS

io_hInternet := DllCall("wininet\InternetOpenA"
, "str", "" ;lpszAgent
, "uint", AccessType
, "str", Proxy
, "str", ProxyBypass
, "uint", 0) ;dwFlags

iou := DllCall("wininet\InternetOpenUrlA"
, "uint", io_hInternet
, "str", url
, "str", "" ;lpszHeaders
, "uint", 0 ;dwHeadersLength
, "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item
, "uint", 0) ;dwContext

If (ErrorLevel != 0 or iou = 0) {
DllCall("FreeLibrary", "uint", hModule)
return 0
}

VarSetCapacity(buffer, 512, 0)
VarSetCapacity(NumberOfBytesRead, 4, 0)
Loop
{
 irf := DllCall("wininet\InternetReadFile", "uint", iou, "uint", &buffer, "uint", 512, "uint", &NumberOfBytesRead)
 NOBR = 0
 Loop 4  ; Build the integer by adding up its bytes. - ExtractInteger
   NOBR += *(&NumberOfBytesRead + A_Index-1) << 8*(A_Index-1)
 IfEqual, NOBR, 0, break
 ;BytesReadTotal += NOBR
 DllCall("lstrcpy", "str", buffer, "uint", &buffer)
 res = %res%%buffer%
}
StringTrimRight, res, res, 2

DllCall("wininet\InternetCloseHandle",  "uint", iou)
DllCall("wininet\InternetCloseHandle",  "uint", io_hInternet)
DllCall("FreeLibrary", "uint", hModule)
AutoTrim, on
return, res
}

 

The only thing im missing now is how to get NextRecordingTime from RS. There seem not to be any page through the api accessing that info. Does somebody have other info about this?

Edited by majstang
Link to comment

url/timerlist.html[?utf8=]

Should help to find the next Recording and then u have to compare this with the systemtime. :)

Edited by nuts
Link to comment

url/timerlist.html[?utf8=]

Should help to find the next Recording and then u have to compare this with the systemtime. :)

Yes, I was afraid of that! Makes it a whole lot more complicated. Thanks for your answer, nuts :)

Link to comment

Hi

 

@nuts, do you know anything about sorting the timerslist for example after date or alphabetical? As it is now it is helter-skelter.

 

The sorting of the timer list is undefined.

 

Regards

Prinz

Edited by Prinz
Link to comment
  • 2 weeks later...

Ok, another piece of the puzzle solved...how to get Time to next recording direct from RecService (without using DVBViewer COM.

Again an Autohotkey script and an adaptation of the URL to a variable script, this time with some serious stringmanagement. The time to next recording will be showed in minutes.

Enjoy!

 

OutputVar := UrlDownloadToVar("http://xxxxx:xxxxx@127.0.0.1:8075/api/timerlist.html[?utf8=]")
StringReplace, OutputVar, OutputVar, <Timer, % Chr(4) . "<Timer", All
StringReplace, OutputVar, OutputVar, </Timer>, % "</Timer>" . Chr(4), All
MyList := A_Now A_Tab "<now>"
While pos := RegexMatch( OutputVar,"<Timer[^>]*Date=""(?<_D>\d+)\D(?<_M>\d+)\D(?<_Y>\d+)""[^>]*Start="""
. "(?<_H>\d+)\D(?<_N>\d+)\D(?<_S>\d+)""[^\x04]*<ID>(?<_ID>\d*)", Tmr, A_Index = 1 ? 1 : pos + StrLen(Tmr) )
  MyList .= "`n" . Tmr_Y . Tmr_M . Tmr_D . Tmr_H . Tmr_N . Tmr_S . A_Tab . Tmr_ID
Sort, MyList, N

set=0
Loop, Parse,MyList, `n
{
if set=1
{
datetime:=A_LoopField
break
}
IfInString, a_loopfield,<now>
set=1
}
StringSplit, datetime,datetime,%A_Tab%
EnvSub, datetime1,A_Now,min
RS_TimeToNextRecordingVar:=datetime1 ;time in minutes to next recording
MsgBox, minutes to go %RS_TimeToNextRecordingVar%

UrlDownloadToVar(URL, Proxy="", ProxyBypass="")
{
AutoTrim, Off
hModule := DllCall("LoadLibrary", "str", "wininet.dll")

If (Proxy != "")
AccessType=3
Else
AccessType=1
;INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
;INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
;INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
;INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS

io_hInternet := DllCall("wininet\InternetOpenA"
, "str", "" ;lpszAgent
, "uint", AccessType
, "str", Proxy
, "str", ProxyBypass
, "uint", 0) ;dwFlags

iou := DllCall("wininet\InternetOpenUrlA"
, "uint", io_hInternet
, "str", url
, "str", "" ;lpszHeaders
, "uint", 0 ;dwHeadersLength
, "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item
, "uint", 0) ;dwContext

If (ErrorLevel != 0 or iou = 0) {
DllCall("FreeLibrary", "uint", hModule)
return 0
}

VarSetCapacity(buffer, 512, 0)
VarSetCapacity(NumberOfBytesRead, 4, 0)
Loop
{
 irf := DllCall("wininet\InternetReadFile", "uint", iou, "uint", &buffer, "uint", 512, "uint", &NumberOfBytesRead)
 NOBR = 0
 Loop 4  ; Build the integer by adding up its bytes. - ExtractInteger
   NOBR += *(&NumberOfBytesRead + A_Index-1) << 8*(A_Index-1)
 IfEqual, NOBR, 0, break
 ;BytesReadTotal += NOBR
 DllCall("lstrcpy", "str", buffer, "uint", &buffer)
 res = %res%%buffer%
}
StringTrimRight, res, res, 2

DllCall("wininet\InternetCloseHandle",  "uint", iou)
DllCall("wininet\InternetCloseHandle",  "uint", io_hInternet)
DllCall("FreeLibrary", "uint", hModule)
AutoTrim, on
return, res
}

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...