moving settings to config file to make it more portable, de-duping off of startTimestamp instead of mp4Url

database
Mark Cotton 2023-09-20 15:35:15 -05:00
parent 438d3bd751
commit c5a8280b19
3 changed files with 41 additions and 18 deletions

View File

@ -23,8 +23,22 @@ config = {
"server_port": "3333",
"server_path": "login_callback",
# preferences
"log_level": "INFO"
# how many days of history should be requested be default, more == slower API call
"days_of_history": 1,
"log_level": "INFO",
# determines directory where videos should be stored, see formating option below
"videos_dir": "videos",
# Folder structure that will be created, default is to save as:
# {video_dir}/{camera_device_id}/{start.year}/{start.month}/{start.day}/
# Setting this to False to save it as:
# {video_dir}/{start.year}/{start.month}/{start.day}/{camera_device_id}/
"path_esn_first": True,
# default is set at 4, but set it to 64 if you feel the need for speed
"num_of_threads_in_pool": 4
}
```

2
app.py
View File

@ -411,7 +411,7 @@ def camera_list_of_videos(esn=None):
for v in camera.videos:
try:
check_video = Download.query.filter(Download.camera_id == db_camera.id)\
.filter(Download.url == v['mp4Url'])\
.filter(Download.start_timestamp == v['startTimestamp'])\
.first()
if check_video is None:
new_video = Download(url=v['mp4Url'],\

View File

@ -16,7 +16,7 @@ from settings import config
import sqlite3
con = sqlite3.connect('instance/project.db')
cur = con.cursor()
def run(args):
@ -36,9 +36,23 @@ def download(args):
end = row[4]
start = datetime.fromisoformat(start)
os.makedirs(f"videos/{camera_device_id}/{start.year}/{start.month}/{start.day}/", exist_ok=True)
fname = f"videos/{camera_device_id}/{start.year}/{start.month}/{start.day}/{camera_device_id}_{start}-{end}.mp4"
video_dir = 'videos'
if 'video_dir' in config:
video_dir = config['video_dir']
path_esn_first = True
if 'path_esn_first' in config:
path_esn_first = config['path_esn_first']
if path_esn_first:
path = f"{video_dir}/{camera_device_id}/{start.year}/{start.month}/{start.day}/"
else:
path = f"{video_dir}/{camera_device_id}/{start.year}/{start.month}/{start.day}/{camera_device_id}"
os.makedirs(path, exist_ok=True)
fname = f"{path}/{camera_device_id}_{start}-{end}.mp4"
@ -68,7 +82,12 @@ def download(args):
if __name__ == '__main__':
pool = Pool(64)
# the settings object to see how many threads we should run in the pool
num_of_threads_in_pool = 4
if 'num_of_threads_in_pool' in config:
num_of_threads_in_pool = config['num_of_threads_in_pool']
pool = Pool(num_of_threads_in_pool)
print("starting up...")
@ -76,8 +95,6 @@ if __name__ == '__main__':
logging.info(f"EagleEyev3 version: {een.__version__}")
cur = con.cursor()
if een:
if een.refresh_token == None or een.refresh_token == '':
@ -111,12 +128,6 @@ if __name__ == '__main__':
# iterate through all the cameras this user has access to
for current_camera in een.cameras:
# create directories if they don't already exists
os.makedirs(f"videos/{current_camera.id}/", exist_ok=True)
# r2d2.get_list_of_videos(start_timestamp=een.time_before(hours=24*1), end_timestamp=een.time_now())
sql = '''SELECT
download.id,
@ -135,11 +146,9 @@ if __name__ == '__main__':
ORDER BY download.start_timestamp
LIMIT 10000;'''
results = cur.execute(sql, ('new', current_camera.id))
# Here is where we send the list of files to be run in the multiprocessing pool
run([results, een, current_camera])