Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

dont change hour

rorycleara11a42e9b569
diff --git a/clearcam/player.html b/clearcam/player.html
index b6331ee..4b5e059 100644
--- a/clearcam/player.html
+++ b/clearcam/player.html
@@ -268,26 +268,21 @@
}
});
- let lastFetchedHour = null;
+ const fetchStartTime = new Date(); // Capture the time once and never change it
+ const currentDate = formatDate(fetchStartTime); // Compute the date once
+
+ function formatDate(date) {
+ const year = date.getFullYear();
+ const month = String(date.getMonth() + 1).padStart(2, '0');
+ const day = String(date.getDate()).padStart(2, '0');
+ const hour = String(date.getHours()).padStart(2, '0');
+ return `${year}-${month}-${day}_${hour}`;
+ }
+
async function fetchSegments() {
try {
const startParam = segments.length;
- // Get the current date and hour in YYYY-MM-DD_HH format
- const now = new Date();
- const year = now.getFullYear();
- const month = String(now.getMonth() + 1).padStart(2, '0');
- const day = String(now.getDate()).padStart(2, '0');
- const hour = String(now.getHours()).padStart(2, '0');
- const currentDate = `${year}-${month}-${day}_${hour}`;
-
- // Check if the hour has changed
- if (lastFetchedHour !== hour) {
- segments = []; // Reset segments if the hour has changed
- totalDuration = 0; // Reset totalDuration
- lastFetchedHour = hour;
- }
-
const response = await fetch(`/get-segments?date=${currentDate}&start=${startParam}`);
if (response.ok) {
const newSegments = await response.json();
@@ -314,8 +309,7 @@
if (totalDuration !== oldTotalDuration) {
updateTimeline();
preloadNextSegments();
-
- // TODO: Improve autoplay logic
+
if (currentVideo.currentTime + segments[currentSegment].cumulativeStart === 0 ||
(isPlaying && isWaitingForNextSegment && segments.length < currentSegment + 1)) {
playSegment();
@@ -332,7 +326,6 @@
}
}
-
function formatTime(seconds) {
const hours = Math.floor(seconds / 3600).toString().padStart(2, '0');
const minutes = Math.floor((seconds % 3600) / 60).toString().padStart(2, '0');