Guest User

getvideo.py

a guest
Apr 10th, 2020
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # USAGE
  2. # python getvideo.py
  3.  
  4. # DESCRIPTION
  5. # This will connect to the specifiec NVR, check for all recordings for the last X minute
  6. # It will download all videos to the downloads dir make sure its the same as in video_detect.py
  7.  
  8. # import the necessary packages
  9. import requests
  10. import json
  11. import time
  12. import os
  13. from datetime import datetime
  14.  
  15. def getvideo():
  16.     #Basic vars
  17.     base = "https://<ip-of-nvr>:7443/api/2.0/recording/"
  18.     apiKey = "?apiKey=<nvr-apikey>"
  19.  
  20.     interval = int(1)
  21.     downloadDir = 'downloads/'
  22.  
  23.     d = datetime.now()
  24.     curUnixtime = time.mktime(d.timetuple())
  25.     curUnixtime = str(curUnixtime)[0:10]
  26.     oneAgoUnixtime = str(int(curUnixtime) - interval * 60)
  27.  
  28.     recordIds = []
  29.     recordCams = []
  30.     files = []
  31.  
  32.     #Disable SSL warnings for now
  33.     requests.packages.urllib3.disable_warnings()
  34.  
  35.     #Get the url
  36.     r = requests.get(base+apiKey, verify=False)
  37.  
  38.     #Parse it to json
  39.     items = r.json()["data"]
  40.  
  41.     #Go through each item
  42.     for item  in items:
  43.         meta = item["meta"]
  44.         cameraName = meta["cameraName"]
  45.         recording = item["_id"]
  46.         endTime = str(item["endTime"])[0:10]
  47.         if str(item["endTime"])[0:10] > oneAgoUnixtime :
  48.             #print("Cam: "+cameraName+", Starttime: "+endTime+", RecordingID: "+recording)
  49.             #print("\r\n")
  50.             recordCams.append(cameraName)
  51.             recordIds.append(str(recording))
  52.  
  53.     count = 0
  54.     for record in recordIds:
  55.         #print(record+" cam "+recordCams[count])
  56.         if not os.path.isfile(downloadDir+str(recordCams[count])+'-'+str(record)+'.mp4') :
  57.             r = requests.get(base+record+"/download"+apiKey, verify=False)
  58.             open(downloadDir+str(recordCams[count])+'-'+str(record)+'.mp4', 'wb').write(r.content)
  59.             files.append(str(recordCams[count])+'-'+str(record)+'.mp4')
  60.             count = count + 1
  61.  
  62.     return files
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×