You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

10 months ago
import requests
import time
import threading
from core.DBManager import DBManager
from myutils.MyLogger_logger import LogHandler
from myutils.ConfigManager import myCongif
class ViewManager:
def __init__(self):
self.thcheck = False
self.lock = threading.Lock()
self.logger = LogHandler().get_logger("ViewManager")
def check_rtsp_url(self,rtsp_url): #通过发送http请求判断rtsp流的在线状态
http_url = rtsp_url.replace("rtsp://", "http://")
try:
response = requests.options(http_url, timeout=5)
if response.status_code == 200:
return True
except requests.RequestException:
pass
return False
def check_all_urls(self): #?
strsql = "select ID,ulr from channel;"
datas = self.mDBM.do_select(strsql)
IDs = [row[0] for row in datas]
urls = [row[1] for row in datas]
#print(IDs,urls)
for i in range(len(urls)):
url = urls[i]
ID = IDs[i]
result = self.check_rtsp_url(url)
iret = 1 if result else 0
strsql = f"update channel set status={iret} where ID={ID};"
self.logger.debug(strsql)
self.mDBM.do_sql(strsql)
def start_check_rtsp(self, interval=myCongif.get_data('RTSP_Check_Time')): #通过线程循环检查添加的RTSP地址在线情况
def run():
self.mDBM = DBManager()
self.mDBM.connect()
while True:
self.check_all_urls()
time.sleep(interval)
if self.thcheck == False:
thread = threading.Thread(target=run)
thread.daemon = True
thread.start()
self.thcheck = True
mVManager = ViewManager()
if __name__ =='__main__':
mVManager.start_check_rtsp()
time.sleep(65)