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.

107 satır
4.1KB

  1. from PIL import Image
  2. import numpy as np
  3. import cv2
  4. import base64
  5. import io,os
  6. import requests
  7. import time,json
  8. import string,random
  9. import glob
  10. ##for CeKanYuan
  11. def get_offlineUrls(taskUrl,offlineFile,jsonfile='SendLog/platformQueryOfftask.json'):
  12. with open(offlineFile,'r') as fp:
  13. lines=fp.readlines()
  14. doneCodes=[line.strip().split(' ')[2] for line in lines]
  15. try:
  16. res = requests.get(taskUrl,timeout=10).json()
  17. offlines=res['data'] ##offlines[0]['code'],offlines[0]['videoUrl']
  18. with open(jsonfile,'w') as fp:
  19. json.dump(res,fp, ensure_ascii=False)
  20. except Exception as ee:
  21. timestr=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  22. print('###line43 %s read taskUrl:%s error:%s '%(timestr,taskUrl,ee))
  23. offlines=[]
  24. outOfflines=[]
  25. for off in offlines:
  26. off['port']=1935;
  27. off.update({'name':'off-' +off.pop("code")})
  28. if off['name'] in doneCodes:
  29. continue
  30. off.update({'url': off.pop("videoUrl")})
  31. outOfflines.append(off)
  32. #off['url']=off['videoUrl']
  33. return outOfflines
  34. def platurlToJsonfile(taskUrl,jsonfile='SendLog/platformQuery.json'):
  35. try:
  36. res = requests.get(taskUrl,timeout=10).json()
  37. offlines=res['data'] ##offlines[0]['code'],offlines[0]['videoUrl']
  38. with open(jsonfile,'w') as fp:
  39. json.dump(res,fp, ensure_ascii=False)
  40. except Exception as ee:
  41. timestr=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  42. print('###line43 %s read taskUrl:%s error:%s '%(timestr,taskUrl,ee))
  43. def get_websource_fromTxt(txtfile):
  44. with open(txtfile,'r') as fp:
  45. lines = fp.readlines()
  46. sources=[ ]
  47. for line in lines:
  48. sous={}
  49. try:
  50. sps = line.strip().split(' ')
  51. sous['url']=sps[0];sous['port']=sps[1]
  52. #webs.append(sps[0])
  53. if 'rtmp' in sps[0]:
  54. name = sps[0].split('/')[4]
  55. else:
  56. name = sps[0][-3:]
  57. sous['name']='live-'+name.replace('_','')
  58. sous['port']=sps[1]
  59. sources.append(sous)
  60. except Exception as ee:
  61. print('####format error : %s, line:%s , in file:%s#####'%(ee,line,txtfile))
  62. assert len(sources)>0
  63. return sources
  64. def update_websource_offAndLive(platform_query_url,sourceFile,offlineFile,jsonfile='SendLog/platformQuery.json'):
  65. #platform_query_url='http://47.96.182.154:9051/api/suanfa/getPlatformInfo'
  66. txtSource=get_websource_fromTxt(sourceFile)
  67. try:
  68. res = requests.get(platform_query_url,timeout=10).json()
  69. questionUrl = res['data']['questionUrl'] ###直播流时,问题图片的推送地址
  70. offlineUrl = res['data']['offlineUrl'] ###http离线视频时,问题图片的推送地址
  71. taskUrl = res['data']['taskUrl'] ###http离线视频时,离线视频存放的地址
  72. with open(jsonfile,'w') as fp:
  73. json.dump(res,fp, ensure_ascii=False)
  74. except Exception as ee:
  75. timestr=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  76. print('######line83: %s: file:geturlPlatform: error %s ,url:%s #####'%(timestr,ee,platform_query_url))
  77. taskUrl='http://121.40.249.52:9050/api/analyse/getAiInspectionList'
  78. if taskUrl:
  79. offlines=get_offlineUrls(taskUrl,offlineFile)
  80. txtSource.extend(offlines)
  81. #[{'url': 'rtmp://demoplay.yunhengzhizao.cn/live/THSA_HD5M', 'port': '1935', 'name': 'live-THSAHD5M'}]
  82. outlist=[]
  83. for sourss in txtSource :
  84. source_url = sourss['url']
  85. vid = cv2.VideoCapture(source_url)
  86. if vid.isOpened():
  87. outlist.append( sourss )
  88. return outlist
  89. #print('##line65:',txtSource)
  90. if __name__=='__main__':
  91. platform_query_url='http://47.96.182.154:9051/api/suanfa/getPlatformInfo'
  92. sourceFile='../config/source.txt'
  93. offlineFile='../mintors/offlines/doneCodes.txt'
  94. jsonfile='../SendLog/platformQuery.json'
  95. txtSource=update_websource_offAndLive(platform_query_url,sourceFile,offlineFile,jsonfile=jsonfile)
  96. print(txtSource)