Skip to content

Commit

Permalink
Adjust time format for filenames??, #98
Browse files Browse the repository at this point in the history
  • Loading branch information
vmdocua committed Jul 15, 2024
1 parent a8a7c7a commit 8d19d5e
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions Parsing/parse_wQR.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import re
from datetime import datetime, timedelta
from re import match
from typing import Optional

from pydantic import BaseModel, Field
Expand Down Expand Up @@ -69,21 +70,31 @@ def get_video_time_info(path_video: str) -> VideoTimeInfo:
start_time=None, end_time=None)
# Define the regex pattern for the timestamp and file extension
# (either .mkv or .mp4)
pattern = (r'^(\d{4}\.\d{2}\.\d{2}\.\d{2}\.\d{2}\.\d{2}\.\d{3})'
pattern1 = (r'^(\d{4}\.\d{2}\.\d{2}\.\d{2}\.\d{2}\.\d{2}\.\d{3})'
r'_(\d{4}\.\d{2}\.\d{2}\.\d{2}\.\d{2}\.\d{2}\.\d{3})\.(mkv|mp4)$')

# add support for new file format
pattern2 = (r'^(\d{4}\.\d{2}\.\d{2}\-\d{2}\.\d{2}\.\d{2}\.\d{3})'
r'\-\-(\d{4}\.\d{2}\.\d{2}\-\d{2}\.\d{2}\.\d{2}\.\d{3})\.(mkv|mp4)$')

file_name: str = os.path.basename(path_video)
logger.info(f"Video file name : {file_name}")

match = re.match(pattern, file_name)
if not match:
res.error = "Filename does not match the required pattern."
return res

start_ts, end_ts, extension = match.groups()
ts_format = ""
match1: str = re.match(pattern1, file_name)
if match1:
# Define the format for datetime parsing
ts_format = "%Y.%m.%d.%H.%M.%S.%f"
else:
match1 = re.match(pattern2, file_name)
if match1:
# Define the format for datetime parsing
ts_format = "%Y.%m.%d-%H.%M.%S.%f"
else:
res.error = "Filename does not match the required pattern."
return res

# Define the format for datetime parsing
ts_format = "%Y.%m.%d.%H.%M.%S.%f"
start_ts, end_ts, extension = match1.groups()

try:
# Parse the timestamps
Expand Down

0 comments on commit 8d19d5e

Please sign in to comment.