Control VLC over HTTP

Post your working scripts, libraries and tools.
NFNNLN
Posts: 3
Joined: 28 Jan 2023, 22:38

Control VLC over HTTP

Post by NFNNLN » 31 Jan 2023, 22:36

AutoHotKey v2
AHK 2.0
VLC Remote

Modify the password from "vlcremote"
Modify the url if required

Code: Select all

; =================== 
; Program Calls - VLC
; ===================

#f10::VlcRequest("pl_pause")
#f11::VlcRequest("pl_previous")
#f12::VlcRequest("pl_next")
#NumpadAdd::VlcRequest("volume&val=+8")
#NumpadSub::VlcRequest("volume&val=-8")

VlcRequest(command)
{
	base64Pwd := b64encode(":" . "vlcremote")
	;base64Pwd := "OnZsY3JlbW90ZQ=="
	headers := Map()
	headers["Authorization"] := "Basic " . base64Pwd
	url := "http://localhost:8080/requests/status.xml?command="
	
	WebRequest(url . command, "GET", headers)
}

WebRequest(url, method := "GET", HeadersArray:=Map())
{
	req := ComObject("WinHttp.WinHttpRequest.5.1")
	req.Open(method, url, true)
	for name, value in HeadersArray {
		req.SetRequestHeader(name, value)
	}
	req.Send()
	req.WaitForResponse()
	status := req.status
	if (status != 200)
		error := "HttpRequest error, status: " . status
	return status
}


; ===================================================================================================================

; ====================
; https://autohotkey.com/boards/viewtopic.php?f=6&t=47895
; Base64 by user AlleyArtwork
; =========================

; ========================================
; Usage:  b64Encode(InString,Encoding := "")
;         b64Decode(InString,Encoding := "")
;
;    Encoding is an optional parameter.  Use it to force "UTF-8", "UTF-16" or other encoding.
;    Otherwise encoding is automatically selected based on the current system.
; ========================================
; Examples
; ========================================
; myVar := b64Encode("a b c d", "UTF-16") ; 
; msgbox "output 1: " myVar
; myVar2 := b64Decode(myVar, "UTF-16") ; 
; msgbox "output 2: " myVar2
; ========================================

b64Encode(sInput,encoding:="UTF-8") {
    If (sInput != "") {
        funcName := (encoding = "UTF-8") ? "CryptBinaryToStringA" : "CryptBinaryToStringW"
        
        bin := Buffer(StrPut(sInput, encoding),0)
        StrPut(sInput, bin, encoding)
        
        if !(DllCall("crypt32\" funcName, "Ptr", bin.ptr, "UInt", bin.size, "uint", 0x1, "ptr", 0, "uint*", &chars:=0)) ; param 2 was len
            throw Error(funcName " failed to determine size.", -1)
        
        buf := Buffer(chars * ((encoding="UTF-16") ? 2 : 1), 0)
        
        if !(DllCall("crypt32\" funcName, "ptr", bin.ptr, "uint", bin.size, "uint", 0x1, "ptr", buf.ptr, "uint*", &chars))
            throw Error(funcName " failed to execute", -1)
		
        return StrGet(buf,encoding)
    } Else
        return ""
}

b64Decode(sInput,encoding:="UTF-8") {
    InvalidChars := RegexMatch(sInput,"[\#\(\)\$\^\{\}\[\]\.\*\?\+\|]+")
    If (InvalidChars > 0) {
        MsgBox "Invalid characters detected.  Halting.  (Char position: " InvalidChars ")"
        return ""
    }
    
    size := 0
    If (sInput != "") {
        funcName := (encoding = "UTF-8") ? "CryptStringToBinaryA" : "CryptStringToBinaryW"
        
        buf := Buffer(StrPut(sInput,encoding),0)
        StrPut(sInput,buf,encoding)
        
        if !(DllCall("crypt32\" funcName, "ptr", buf.ptr, "uint", 0, "uint", 0x1, "ptr", 0, "uint*", &size:=0, "ptr", 0, "ptr", 0))
            throw Error(funcName " failed to determine size.", -1)
        
        buf2 := Buffer(size, 0)
        if !(DllCall("crypt32\" funcName, "ptr", buf.ptr, "uint", 0, "uint", 0x1, "ptr", buf2.ptr, "uint*", &size, "ptr", 0, "ptr", 0))
            throw Error(funcName " failed to execute.", -1)
        
        return StrGet(buf2, encoding)
    } Else
        return ""
}

Return to “Scripts and Functions (v2)”