Page 1 of 1

Delet a video by json

Posted: Thu May 14, 2020 11:39 am
by ben
Hi i like to do delet recorded videos by a json command
Blue Iris send told me with {delclip:@record#} it should work.
The number i record# i get back from a get request when i stop recording a video.
What i need more is that i probably have to give a authentification with as well.
I'm stuck with the command lin
Do you know how the code for python should be?

Am I on the right way with this one?:
URL = 'http://IP-Adress/admin?user=username&pw=password'

data = {'delclip':'@429152'}
r = requests.get(URL, headers={'Content-Type': 'application/json' }, json=data)
a = r.json()
print('\nResponse: \n')
print(a)

with that one i get an error back.. see picture..

Tanks for help :D

Re: Delet a video by json

Posted: Fri May 15, 2020 5:00 pm
by Thixotropic
ben wrote: Thu May 14, 2020 11:39 am with that one i get an error back.. see picture..
I don't see a picture (??)

Re: Delet a video by json

Posted: Sat May 16, 2020 9:21 am
by TimG
Since there is no broken link or URL, I wonder if that was a language thing, i.e. did he mean "Do you get the picture ?".

Re: Delet a video by json

Posted: Sat May 16, 2020 2:39 pm
by ben
So now there is the picture ;D

Re: Delet a video by json

Posted: Mon May 18, 2020 6:19 pm
by ben
So i got this:

URL = "http://user:Password@192.168.1.9:81/json"

r = requests.post(URL, data=json.dumps({"delclip":"@344249"}))
print(r.text)
print(r)

and the answer is this:
{"result":"fail"}
<Response [200]>

Do know what i have to change or add, so i can delet the video?

Re: Delet a video by json

Posted: Tue May 19, 2020 1:13 pm
by ben
i figure it out hope i can help some one else with that.

import json
import hashlib
from urllib.request import Request, urlopen

def Send(request):
jsonRequest = json.dumps(request).encode('ascii')
request = Request(url, jsonRequest)
response = urlopen(request).read().decode()
jsonResponse = json.loads(response)
return jsonResponse

request = { "cmd": "login" }
response = Send(request)
#print(time.monotonic())
#print(response)
session = response["session"]

s = "yourUsername:" + session + ":youPassword"
hash = hashlib.md5(s.encode("utf-8")).hexdigest()
response = Send({ "cmd": "login", "session": session, "response": hash })
print(response)
request = { "cmd": "cliplist", "session": session, "camera":"Cam1"}
#request = { "cmd": "delclip", "session": session, "path":"@441991"}
response = Send(request)
print(response)

request = { "cmd": "logout", "session": session}
response = Send(request)
response

Re: Delet a video by json

Posted: Tue May 19, 2020 1:31 pm
by Thixotropic
Awesome, thank you for posting the solution.