Commit 67e49482 authored by Боярский Андрей Олегович's avatar Боярский Андрей Олегович
Browse files

Some fixes

parent 2a3a5e51
No related merge requests found
Showing with 214 additions and 620 deletions
+214 -620
......@@ -208,6 +208,57 @@
}
},
"auditories": {
"302": {
"136": {
"ip": "172.18.191.136",
"port": "80",
"streamuri": "rtsp://audi.proxy/302/3"
},
"135": {
"ip": "172.18.191.135",
"port": "8899",
"streamuri": "rtsp://audi.proxy/302/2"
},
"243": {
"ip": "172.18.191.243",
"port": "80",
"streamuri": "rtsp://audi.proxy/302/1"
}
},
"303": {
"133": {
"ip": "172.18.191.133",
"port": "80",
"streamuri": "rtsp://audi.proxy/303/3"
},
"132": {
"ip": "172.18.191.132",
"port": "8899",
"streamuri": "rtsp://audi.proxy/303/2"
},
"134": {
"ip": "172.18.191.134",
"port": "80",
"streamuri": "rtsp://audi.proxy/303/1"
}
},
"304": {
"143": {
"ip": "172.18.191.143",
"port": "80",
"streamuri": "rtsp://audi.proxy/304/3"
},
"142": {
"ip": "172.18.191.142",
"port": "8899",
"streamuri": "rtsp://audi.proxy/304/2"
},
"141": {
"ip": "172.18.191.141",
"port": "80",
"streamuri": "rtsp://audi.proxy/304/1"
}
},
"305": {
"53": {
"ip": "172.18.191.53",
......@@ -334,6 +385,11 @@
}
},
"504": {
"93": {
"ip": "172.18.191.93",
"port": "9000",
"streamuri": "rtsp://audi.proxy/504/3"
},
"95": {
"ip": "172.18.191.95",
"port": "80",
......@@ -349,11 +405,6 @@
"port": "8899",
"streamuri": "rtsp://audi.proxy/504/2"
},
"93": {
"ip": "172.18.191.93",
"port": "9000",
"streamuri": "rtsp://audi.proxy/504/3"
},
"94": {
"ip": "172.18.191.94",
"port": "80",
......
......@@ -208,6 +208,57 @@
}
},
"auditories": {
"302": {
"136": {
"ip": "172.18.191.136",
"port": "80",
"streamuri": "rtsp://audi.proxy/302/3"
},
"135": {
"ip": "172.18.191.135",
"port": "8899",
"streamuri": "rtsp://audi.proxy/302/2"
},
"243": {
"ip": "172.18.191.243",
"port": "80",
"streamuri": "rtsp://audi.proxy/302/1"
}
},
"303": {
"133": {
"ip": "172.18.191.133",
"port": "80",
"streamuri": "rtsp://audi.proxy/303/3"
},
"132": {
"ip": "172.18.191.132",
"port": "8899",
"streamuri": "rtsp://audi.proxy/303/2"
},
"134": {
"ip": "172.18.191.134",
"port": "80",
"streamuri": "rtsp://audi.proxy/303/1"
}
},
"304": {
"143": {
"ip": "172.18.191.143",
"port": "80",
"streamuri": "rtsp://audi.proxy/304/3"
},
"142": {
"ip": "172.18.191.142",
"port": "8899",
"streamuri": "rtsp://audi.proxy/304/2"
},
"141": {
"ip": "172.18.191.141",
"port": "80",
"streamuri": "rtsp://audi.proxy/304/1"
}
},
"305": {
"53": {
"ip": "172.18.191.53",
......@@ -334,6 +385,11 @@
}
},
"504": {
"93": {
"ip": "172.18.191.93",
"port": "9000",
"streamuri": "rtsp://audi.proxy/504/3"
},
"95": {
"ip": "172.18.191.95",
"port": "80",
......
......@@ -208,6 +208,57 @@
}
},
"auditories": {
"302": {
"136": {
"ip": "172.18.191.136",
"port": "80",
"streamuri": "rtsp://audi.proxy/302/3"
},
"135": {
"ip": "172.18.191.135",
"port": "8899",
"streamuri": "rtsp://audi.proxy/302/2"
},
"243": {
"ip": "172.18.191.243",
"port": "80",
"streamuri": "rtsp://audi.proxy/302/1"
}
},
"303": {
"133": {
"ip": "172.18.191.133",
"port": "80",
"streamuri": "rtsp://audi.proxy/303/3"
},
"132": {
"ip": "172.18.191.132",
"port": "8899",
"streamuri": "rtsp://audi.proxy/303/2"
},
"134": {
"ip": "172.18.191.134",
"port": "80",
"streamuri": "rtsp://audi.proxy/303/1"
}
},
"304": {
"143": {
"ip": "172.18.191.143",
"port": "80",
"streamuri": "rtsp://audi.proxy/304/3"
},
"142": {
"ip": "172.18.191.142",
"port": "8899",
"streamuri": "rtsp://audi.proxy/304/2"
},
"141": {
"ip": "172.18.191.141",
"port": "80",
"streamuri": "rtsp://audi.proxy/304/1"
}
},
"305": {
"53": {
"ip": "172.18.191.53",
......@@ -334,6 +385,11 @@
}
},
"504": {
"93": {
"ip": "172.18.191.93",
"port": "9000",
"streamuri": "rtsp://audi.proxy/504/3"
},
"95": {
"ip": "172.18.191.95",
"port": "80",
......
......@@ -13,5 +13,5 @@ class make_request:
try:
response = requests.post(service, data = data, timeout = 3)
return response
except requests.exceptions.ConnectionError:
except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):
return ''
......@@ -60,35 +60,39 @@ def replace_all(text, dic):
'''
'''
def get_response(service, Onvif, body, octet = None):
response = Onvif.make_request(service, body)
def get_response(service, Onvif, body, direct, octet = None):
response = Onvif.make_request(service, body)
if direct == True:
if response != '':
return response.text
else:
return ''
else:
if response != '':
if response.status_code != 500:
#if response.status_code == 400 or response.text == '' or response.text.find('400 Bad Request') > 0 or response.text.find('404 Not Found') > 0 or response.text.find('404 File Not Found') > 0:
#service = service.split('_')[0].lower()
#if service.rfind('/') > -1:
# to_list = service.split('/')
# service = to_list[len(to_list) - 1].lower()
#if service in list(servicepatterns.keys()):
# service_length = len(servicepatterns[service])
# iterrator = 0
# while (response.status_code == 400 or response.text == '' or response.text.find('400 Bad Request') > 0 or response.text.find('404 Not Found') > 0 or response.text.find('404 File Not Found') > 0) and iterrator < service_length:
#response = Onvif.make_request(servicepatterns[service][iterrator], body)
# response = Onvif.make_request(service, body)
# iterrator += 1
#else:
#logging.info('Нет сервиса {}'.format(service))
if response.status_code == 400 or response.text == '' or response.text.find('400 Bad Request') > 0 or response.text.find('404 Not Found') > 0 or response.text.find('404 File Not Found') > 0:
return ''
else:
return response.text
service = service.split('_')[0].lower()
if service.rfind('/') > -1:
to_list = service.split('/')
service = to_list[len(to_list) - 1].lower()
if service in list(servicepatterns.keys()):
service_length = len(servicepatterns[service])
iterrator = 0
while (response.status_code == 400 or response.text == '' or response.text.find('400 Bad Request') > 0 or response.text.find('404 Not Found') > 0 or response.text.find('404 File Not Found') > 0) and iterrator < service_length:
response = Onvif.make_request(servicepatterns[service][iterrator], body)
# response = Onvif.make_request(service, body)
iterrator += 1
else:
logging.info('Нет сервиса {}'.format(service))
if response.status_code == 400 or response.text == '' or response.text.find('400 Bad Request') > 0 or response.text.find('404 Not Found') > 0 or response.text.find('404 File Not Found') > 0:
return ''
else:
return response.text
else:
return ''
else:
return ''
'''
'''
def replace_token(response, octet):
if response == None:
return ''
......@@ -289,13 +293,13 @@ class Proccesser():
Onvif = make_request(ip, port)
if body.find('GetCapabilities') > 0 or body.find('GetServices') > 0:
response = get_response('device_service', Onvif, body)
response = get_response('device_service', Onvif, body, False)
#logging.info('Capabilities {}'.format(response))
response = replace_all(response,
get_replace_template(ipport,
self.ip,#cameras['host_ip'],
self.ip, #cameras['host_ip'],
auditory,
self.port))#cameras['port']))
self.port)) #cameras['port']))
response = replace_all(response,
get_replace_template(r'http://{}/'.format(ip),
self.ip,#cameras['host_ip'],
......@@ -310,7 +314,7 @@ class Proccesser():
logging.info('Сервис {}'.format(service))
if body.find('GetScopes') > 0:
response = get_response(service, Onvif, body)
response = get_response(service, Onvif, body, False)
#logging.info('До Response {}'.format(response))
......@@ -327,7 +331,7 @@ class Proccesser():
response = response.replace(location, '{}'.format(auditory))
elif body.find('GetProfiles') > 0:
response = get_response(service, Onvif, body)
response = get_response(service, Onvif, body, False)
response = replace_token(response, ips[0])
first_part = response[:response.rfind('GetProfilesResponse')]
first_part = first_part[:first_part.rfind('>') + 1]
......@@ -337,7 +341,7 @@ class Proccesser():
for i in range(1, len(ips)):
Onvif = make_request(cameras['auditories'][auditory][ips[i]]['ip'],
cameras['auditories'][auditory][ips[i]]['port'])
add_response = get_response(service, Onvif, body, ips[i])
add_response = get_response(service, Onvif, body, False, ips[i])
add_response = replace_token(add_response, ips[i])
add_response = add_response[add_response.find('GetProfilesResponse') + 20:add_response.rfind(
'GetProfilesResponse')]
......@@ -346,7 +350,7 @@ class Proccesser():
response = response + second_part
#logging.info('Response {}'.format(response))
elif body.find('GetVideoSources') > 0:
response = get_response(service, Onvif, body)
response = get_response(service, Onvif, body, False)
response = replace_token(response, ips[0])
first_part = response[:response.rfind('GetVideoSourcesResponse')]
first_part = first_part[:first_part.rfind('>') + 1]
......@@ -357,7 +361,7 @@ class Proccesser():
Onvif = make_request(cameras['auditories'][auditory][ips[i]]['ip'],
cameras['auditories'][auditory][ips[i]]['port'])
add_response = get_response(service, Onvif, body, ips[i])
add_response = get_response(service, Onvif, body, False, ips[i])
add_response = replace_token(add_response, ips[i])
add_response = add_response[
......@@ -389,7 +393,7 @@ class Proccesser():
Onvif = make_request(cameras['auditories'][auditory][octet]['ip'],
cameras['auditories'][auditory][octet]['port'])
response = get_response(service, Onvif, body)
response = get_response(service, Onvif, body, False)
if body.find('GetStreamUri') > 0:
old_streamuri = response[response.find('>rtsp') + 1:]
......@@ -404,7 +408,7 @@ class Proccesser():
cameras['auditories'][auditory][
octet]['ip']))
else:
response = get_response(service, Onvif, body)
response = get_response(service, Onvif, body, False)
response = replace_token(response, ips[0])
response = re.sub("^\s+|\n|\r|\s+$", '', response)
......@@ -462,7 +466,7 @@ class Proccesser():
Onvif = make_request(ip, port)
if body.find('GetCapabilities') > 0 or body.find('GetServices') > 0:
response = get_response('device_service', Onvif, body)
response = get_response('device_service', Onvif, body, True)
response = replace_all(response, get_replace_template(ipport, self.ip, None, self.port))
response = replace_all(response, get_replace_template(r'http://{}/'.format(ip), self.ip, None, self.port))
response = response.encode()
......@@ -477,7 +481,7 @@ class Proccesser():
#logging.info('Запрос {}'.format(body))
if body.find('GetScopes') > 0:
response = get_response(service, Onvif, body)
response = get_response(service, Onvif, body, True)
if response.find('/location/') > 0 and response.find('/location/') != response.find('/location/country'):
response = response.replace('/location/', '/location/{}'.format(auditory))
......@@ -491,7 +495,7 @@ class Proccesser():
response = response.replace(location, '{}'.format(auditory))
elif body.find('GetProfiles') > 0:
response = get_response(service, Onvif, body)
response = get_response(service, Onvif, body, True)
response = replace_token(response, needed_ip)
if int(cam_num) < 1:
first_part = response[:response.rfind('GetProfilesResponse')]
......@@ -502,7 +506,7 @@ class Proccesser():
for i in range(1, len(ips)):
Onvif = make_request(cameras[paradigm][auditory][ips[i]]['ip'],
cameras[paradigm][auditory][ips[i]]['port'])
add_response = get_response(service, Onvif, body, ips[i])
add_response = get_response(service, Onvif, body, True, ips[i])
add_response = replace_token(add_response, ips[i])
add_response = add_response[
add_response.find('GetProfilesResponse') + 20:add_response.rfind(
......@@ -511,7 +515,7 @@ class Proccesser():
response = response + add_response
response = response + second_part
elif body.find('GetVideoSources') > 0:
response = get_response(service, Onvif, body)
response = get_response(service, Onvif, body, True)
response = replace_token(response, needed_ip)
if int(cam_num) < 1:
first_part = response[:response.rfind('GetVideoSourcesResponse')]
......@@ -523,7 +527,7 @@ class Proccesser():
Onvif = make_request(cameras[paradigm][auditory][ips[i]]['ip'],
cameras[paradigm][auditory][ips[i]]['port'])
add_response = get_response(service, Onvif, body, ips[i])
add_response = get_response(service, Onvif, body, True, ips[i])
add_response = replace_token(add_response, ips[i])
add_response = add_response[
add_response.find('GetVideoSourcesResponse') + 24:add_response.rfind(
......@@ -564,7 +568,7 @@ class Proccesser():
cameras[paradigm][auditory][octet]['port'])
#logging.info('Запрос к камере {}'.format(body))
response = get_response(service, Onvif, body)
response = get_response(service, Onvif, body, True)
#logging.info('Ответ до переработки {}'.format(response))
if body.find('GetStreamUri') > 0:
......@@ -580,7 +584,7 @@ class Proccesser():
cameras[paradigm][auditory][octet][
'ip']))
else:
response = get_response(service, Onvif, body)
response = get_response(service, Onvif, body, True)
response = replace_token(response, ips[0])
#logging.info('Ответ после обработки {}'.format(response))
response = re.sub("^\s+|\n|\r|\s+$", '', response)
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment