Add object detection, tracking, mobile notifications, and search to any security camera.
stream
roryclear37ffc09d9fcc
diff --git a/player.html b/player.htmlindex ace76a9..36281ad 100644--- a/player.html+++ b/player.html@@ -79,6 +79,31 @@let isPlaying = false;let isScrubbing = false;+ async function fetchSegments() {+ try {+ const response = await fetch('/get-segments');+ if (response.ok) {+ const newSegments = await response.json();++ if (Array.isArray(newSegments)) {+ const oldTotalDuration = totalDuration;++ // Update segments list and total duration+ segments = newSegments;+ totalDuration = segments.length * segmentDuration;++ // If the total duration changes, update UI+ if (totalDuration !== oldTotalDuration) {+ updateTimeline();+ preloadNextSegment();+ }+ }+ }+ } catch (error) {+ console.error('Failed to fetch segments:', error);+ }+ }+function formatTime(seconds) {const minutes = Math.floor(seconds / 60);const secs = Math.floor(seconds % 60).toString().padStart(2, '0');@@ -109,7 +134,6 @@updateTimeline();}-function startScrubbing(e) {isScrubbing = true;scrub(e);@@ -138,25 +162,6 @@}}- function checkForNewSegments() {- const nextSegmentIndex = segments.length;- const nextSegment = `${nextSegmentIndex}.mp4`;-- fetch(nextSegment, { method: 'HEAD' })- .then(response => {- if (response.ok) {- segments.push(nextSegment);- totalDuration = segments.length * segmentDuration;-- // Update preloaded video if needed- if (currentSegment + 1 === segments.length - 1) {- preloadNextSegment();- }- }- })- .catch(() => {});- }-function playSegment() {currentVideo.src = segments[currentSegment];currentVideo.currentTime = 0;@@ -192,8 +197,8 @@document.addEventListener("mouseup", stopScrubbing);setInterval(() => {- checkForNewSegments();- }, 3000);+ fetchSegments();+ }, 3000); // Poll every 3 seconds for new segmentsvideoPlayer1.addEventListener("timeupdate", updateTimeline);videoPlayer2.addEventListener("timeupdate", updateTimeline);@@ -215,4 +220,4 @@playSegment();</script></body>-</html>+</html>\ No newline at end of filediff --git a/server.py b/server.pynew file mode 100644index 0000000..7c84ad2--- /dev/null+++ b/server.py@@ -0,0 +1,36 @@+import os+import json+from http.server import HTTPServer, SimpleHTTPRequestHandler++PORT = 8080++class CustomHandler(SimpleHTTPRequestHandler):+ def do_GET(self):+ if self.path == "/get-segments":+ self.handle_get_segments()+ else:+ super().do_GET()++ def handle_get_segments(self):+ try:+ # Find all .mp4 files in the current directory+ segments = [f for f in os.listdir('.') if f.endswith('.mp4')]+ segments.sort(key=lambda x: int(x.split('.')[0]))++ # Respond with JSON+ self.send_response(200)+ self.send_header("Content-Type", "application/json")+ self.end_headers()+ self.wfile.write(json.dumps(segments).encode())+ except Exception as e:+ # Handle errors and send a response+ self.send_response(500)+ self.send_header("Content-Type", "text/plain")+ self.end_headers()+ self.wfile.write(f"Error: {str(e)}".encode())++if __name__ == "__main__":+ # Start the server+ server = HTTPServer(("0.0.0.0", PORT), CustomHandler)+ print(f"Serving on http://localhost:{PORT}")+ server.serve_forever()\ No newline at end of file