support multiple cameras
parent
9e4a217b5f
commit
59e6c5048b
|
@ -189,3 +189,4 @@ cython_debug/
|
|||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
test_images/
|
23
README.md
23
README.md
|
@ -1,28 +1,9 @@
|
|||
# msv-webcam-backend
|
||||
|
||||
|
||||
useradd --system msvwebcambackend -m
|
||||
passwd -l msvwebcambackend
|
||||
|
||||
|
||||
- `mkdir /opt/msv-webcam-backend/`
|
||||
- `cd /opt/msv-webcam-backend/`
|
||||
- import `msv_webcam_backend.py` and `config.py`
|
||||
- Set the constants in `config.py`
|
||||
- import `msv_webcam_backend.py`
|
||||
- `chmod +x /opt/msv-webcam-backend/msv_webcam_backend.py`
|
||||
- `chown -R msvwebcambackend /opt/msv-webcam-backend/`
|
||||
- `nano /etc/systemd/system/msv-webcam-backend.service`
|
||||
- create dst dir `mkdir -p /var/www/html/msv-buehl-moos.de/webcam/data`
|
||||
- `systemctl daemon-reload && systemctl enable --now msv-webcam-backend.service`
|
||||
|
||||
|
||||
mkdir /var/www/html/msv-buehl-moos.de/webcam/
|
||||
|
||||
chown -R wwwrun:wwwrun /var/www/html/msv-buehl-moos.de/
|
||||
|
||||
|
||||
|
||||
|
||||
location /webcam {
|
||||
root /var/www/html/msv-buehl-moos.de;
|
||||
index index.html;
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Author: Hendrik Schutter, mail@hendrikschutter.com
|
||||
"""
|
||||
|
||||
image_search_path = "./test_images/"
|
||||
destination_image_full_path = "./www/data/still.jpg"
|
||||
update_interval = 10 # 10sec
|
|
@ -4,11 +4,13 @@ After=syslog.target
|
|||
After=network.target
|
||||
|
||||
[Service]
|
||||
RestartSec=2s
|
||||
Type=oneshot
|
||||
User=msvwebcambackend
|
||||
Type=simple
|
||||
User=root
|
||||
Group=root
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
WorkingDirectory=/opt/msv-webcam-backend/
|
||||
ExecStart=/usr/bin/python3 /opt/msv-webcam-backend/msv_webcam_backend.py
|
||||
ExecStart=/usr/bin/python3 /opt/msv-webcam-backend/msv_webcam_backend.py interval=10 search_dir=/home/dockeruser/ftps_server/files/msvcamS search_dir=/home/dockeruser/ftps_server/files/msvcamN destination_dir=/var/www/html/msv-buehl-moos.de/webcam/data/ destination_owner=wwwrun
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -3,53 +3,84 @@
|
|||
""" Author: Hendrik Schutter, mail@hendrikschutter.com
|
||||
"""
|
||||
|
||||
import config
|
||||
import glob
|
||||
import os
|
||||
import time
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
def copy_image(src):
|
||||
shutil.copy(src, config.destination_image_full_path)
|
||||
os.chmod(config.destination_image_full_path, 644)
|
||||
def copy_image(src, destination_dir_path, destination_owner):
|
||||
# print("src: " + str(src))
|
||||
# print("dst: " + str(destination_dir_path))
|
||||
shutil.copyfile(src, destination_dir_path)
|
||||
os.chmod(destination_dir_path, 0o0644)
|
||||
shutil.chown(destination_dir_path, destination_owner)
|
||||
|
||||
def main():
|
||||
print("starting ...")
|
||||
|
||||
newest_file_path = ""
|
||||
newest_file_size = 0
|
||||
update_interval = -1
|
||||
destination_dir_path = -1
|
||||
destination_owner = -1
|
||||
search_dirs = list()
|
||||
|
||||
for argument in sys.argv:
|
||||
if argument.startswith('interval'):
|
||||
update_interval = int(argument.split("=")[1])
|
||||
if argument.startswith('destination_dir'):
|
||||
destination_dir_path = argument.split("=")[1]
|
||||
if argument.startswith('destination_owner'):
|
||||
destination_owner = argument.split("=")[1]
|
||||
if argument.startswith('search_dir'):
|
||||
tmp_search_dir = {
|
||||
"search_dir_path" : argument.split("=")[1],
|
||||
"newest_file_path" : "",
|
||||
"newest_file_size" : 0
|
||||
}
|
||||
search_dirs.append(tmp_search_dir)
|
||||
|
||||
if ((update_interval == -1) or (destination_dir_path == -1) or (destination_owner == -1) or (len(search_dirs) == 0)):
|
||||
print("Unable to parse config!")
|
||||
print("Example usage:")
|
||||
print(" python msv_webcam_backend.py interval=10 search_dir=test_images/msvcamS search_dir=test_images/msvcamN destination_dir=www/ destination_owner=hendrik")
|
||||
sys.exit(-1)
|
||||
|
||||
while True:
|
||||
|
||||
while True:
|
||||
for search_dir in search_dirs:
|
||||
try:
|
||||
# print(config.image_search_path)
|
||||
list_of_files = glob.glob(config.image_search_path+"/**/*.jpg", recursive=True)
|
||||
# print(list_of_files)
|
||||
# print("\nSearch dir: " + str(search_dir["search_dir_path"]))
|
||||
list_of_files = glob.glob(search_dir["search_dir_path"]+"/**/*.jpg", recursive=True)
|
||||
# print(list_of_files)
|
||||
newest_file_path_tmp = max(list_of_files, key=os.path.getctime)
|
||||
newest_file_size_tmp = os.stat(newest_file_path_tmp).st_size
|
||||
list_of_files.clear()
|
||||
|
||||
if (newest_file_path_tmp == newest_file_path) and (newest_file_size_tmp == newest_file_size):
|
||||
if (newest_file_path_tmp == search_dir["newest_file_path"]) and (newest_file_size_tmp == search_dir["newest_file_size"]):
|
||||
# already found the newest file
|
||||
print("no newer file found")
|
||||
break
|
||||
else:
|
||||
time.sleep(1) # wait 1sec to see if the upload is still in progress
|
||||
|
||||
time.sleep(1) # wait 1sec to see if the upload is still in progress
|
||||
list_of_files = glob.glob(search_dir["search_dir_path"]+"/**/*.jpg", recursive=True)
|
||||
newest_file_path_tmp_delayed = max(list_of_files, key=os.path.getctime)
|
||||
newest_file_size_tmp_delayed = os.stat(newest_file_path_tmp_delayed).st_size
|
||||
list_of_files.clear()
|
||||
|
||||
list_of_files = glob.glob(config.image_search_path+"/**/*.jpg", recursive=True)
|
||||
newest_file_path = max(list_of_files, key=os.path.getctime)
|
||||
newest_file_size = os.stat(newest_file_path).st_size
|
||||
|
||||
if (newest_file_path_tmp == newest_file_path) and (newest_file_size_tmp == newest_file_size):
|
||||
print("Found new file:")
|
||||
print("Name: "+str(newest_file_path))
|
||||
print("Size: " + str(newest_file_size))
|
||||
copy_image(newest_file_path)
|
||||
break
|
||||
if (newest_file_path_tmp == newest_file_path_tmp_delayed) and (newest_file_size_tmp == newest_file_size_tmp_delayed):
|
||||
search_dir["newest_file_path"] = newest_file_path_tmp_delayed
|
||||
search_dir["newest_file_size"] = newest_file_size_tmp_delayed
|
||||
print("Found new file:")
|
||||
print("Name: " + str(search_dir["newest_file_path"]))
|
||||
print("Size: " + str(search_dir["newest_file_size"]))
|
||||
dst_file_tmp = os.path.join(destination_dir_path, (os.path.basename(os.path.normpath(search_dir["search_dir_path"])) + os.path.splitext(search_dir["newest_file_path"])[1]))
|
||||
copy_image(search_dir["newest_file_path"], dst_file_tmp, destination_owner)
|
||||
#break
|
||||
else:
|
||||
print("Upload not finished yet!")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
#break
|
||||
time.sleep(config.update_interval)
|
||||
time.sleep(update_interval)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 63 KiB |
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
|
@ -8,7 +8,9 @@
|
|||
<p>You are connected!</p>
|
||||
|
||||
|
||||
<img src="data/still.jpg" alt="still webcam image">
|
||||
<img src="data/msvcamN.jpg" alt="msvcamN still webcam image">
|
||||
|
||||
<img src="data/msvcamS.jpg" alt="msvcamS still webcam image">
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue