mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 17:55:21 +03:00
Fix recordings summary with timezone
This commit is contained in:
parent
42fb94e44a
commit
175672e084
@ -1,5 +1,5 @@
|
|||||||
import base64
|
import base64
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta, timezone
|
||||||
import copy
|
import copy
|
||||||
import glob
|
import glob
|
||||||
import logging
|
import logging
|
||||||
@ -801,7 +801,6 @@ def get_recordings_storage_usage():
|
|||||||
def recordings_summary(camera_name):
|
def recordings_summary(camera_name):
|
||||||
tz_name = request.args.get("timezone", default="utc", type=str)
|
tz_name = request.args.get("timezone", default="utc", type=str)
|
||||||
tz_offset = f"{int(datetime.now(pytz.timezone(tz_name)).utcoffset().total_seconds()/60/60)} hour"
|
tz_offset = f"{int(datetime.now(pytz.timezone(tz_name)).utcoffset().total_seconds()/60/60)} hour"
|
||||||
logger.error(f"The difference is {tz_offset}")
|
|
||||||
recording_groups = (
|
recording_groups = (
|
||||||
Recordings.select(
|
Recordings.select(
|
||||||
fn.strftime(
|
fn.strftime(
|
||||||
@ -1023,12 +1022,12 @@ def vod_ts(camera_name, start_ts, end_ts):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/vod/<year_month>/<day>/<hour>/<camera_name>")
|
# TODO make this nicer when vod module is removed
|
||||||
def vod_hour(year_month, day, hour, camera_name):
|
@bp.route("/vod/<year_month>/<day>/<hour>/<camera_name>/<tz_name>")
|
||||||
tz_name = request.args.get("timezone", "utc")
|
def vod_hour(year_month, day, hour, camera_name, tz_name):
|
||||||
start_date = datetime.strptime(f"{year_month}-{day} {hour}", "%Y-%m-%d %H").replace(
|
tz_name = tz_name.replace("_", "/")
|
||||||
tzinfo=pytz.timezone(tz_name)
|
parts = year_month.split("-")
|
||||||
)
|
start_date = datetime(int(parts[0]), int(parts[1]), int(day), int(hour), tzinfo=pytz.timezone(tz_name)).astimezone(timezone.utc)
|
||||||
end_date = start_date + timedelta(hours=1) - timedelta(milliseconds=1)
|
end_date = start_date + timedelta(hours=1) - timedelta(milliseconds=1)
|
||||||
start_ts = start_date.timestamp()
|
start_ts = start_date.timestamp()
|
||||||
end_ts = end_date.timestamp()
|
end_ts = end_date.timestamp()
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import useSWR from 'swr';
|
|||||||
|
|
||||||
export default function Recording({ camera, date, hour = '00', minute = '00', second = '00' }) {
|
export default function Recording({ camera, date, hour = '00', minute = '00', second = '00' }) {
|
||||||
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
//const timezone = "America/Chicago"
|
//const timezone = 'America/Chicago';
|
||||||
const currentDate = useMemo(
|
const currentDate = useMemo(
|
||||||
() => (date ? parseISO(`${date}T${hour || '00'}:${minute || '00'}:${second || '00'}`) : new Date()),
|
() => (date ? parseISO(`${date}T${hour || '00'}:${minute || '00'}:${second || '00'}`) : new Date()),
|
||||||
[date, hour, minute, second]
|
[date, hour, minute, second]
|
||||||
@ -24,7 +24,6 @@ export default function Recording({ camera, date, hour = '00', minute = '00', se
|
|||||||
const recordingParams = {
|
const recordingParams = {
|
||||||
before: getUnixTime(endOfHour(currentDate)),
|
before: getUnixTime(endOfHour(currentDate)),
|
||||||
after: getUnixTime(startOfHour(currentDate)),
|
after: getUnixTime(startOfHour(currentDate)),
|
||||||
timezone,
|
|
||||||
};
|
};
|
||||||
const { data: recordings } = useSWR([`${camera}/recordings`, recordingParams], { revalidateOnFocus: false });
|
const { data: recordings } = useSWR([`${camera}/recordings`, recordingParams], { revalidateOnFocus: false });
|
||||||
|
|
||||||
@ -71,14 +70,17 @@ export default function Recording({ camera, date, hour = '00', minute = '00', se
|
|||||||
description: `${camera} recording @ ${h.hour}:00.`,
|
description: `${camera} recording @ ${h.hour}:00.`,
|
||||||
sources: [
|
sources: [
|
||||||
{
|
{
|
||||||
src: `${apiHost}/vod/${year}-${month}/${day}/${h.hour}/${camera}/master.m3u8`,
|
src: `${apiHost}/vod/${year}-${month}/${day}/${h.hour}/${camera}/${timezone.replaceAll(
|
||||||
|
'/',
|
||||||
|
'_'
|
||||||
|
)}/master.m3u8`,
|
||||||
type: 'application/vnd.apple.mpegurl',
|
type: 'application/vnd.apple.mpegurl',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.reverse();
|
.reverse();
|
||||||
}, [apiHost, date, recordingsSummary, camera]);
|
}, [apiHost, date, recordingsSummary, camera, timezone]);
|
||||||
|
|
||||||
const playlistIndex = useMemo(() => {
|
const playlistIndex = useMemo(() => {
|
||||||
const index = playlist.findIndex((item) => item.name === hour);
|
const index = playlist.findIndex((item) => item.name === hour);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user