Herstructureer dashcam naar uniforme front/rear structuur (46 mappen hernoemd, 1022 bestanden gesorteerd)
This commit is contained in:
parent
bc8139f2f1
commit
b161a4945c
2 changed files with 140 additions and 19 deletions
|
|
@ -54,33 +54,20 @@ YYYYMMDDHHMMSS_XXXXXXXX<kamera>.MP4
|
|||
|
||||
## 4. SSD structuur (doel)
|
||||
|
||||
### Bestaande data
|
||||
### Huidige data (na herstructurering)
|
||||
|
||||
```
|
||||
/mnt/ultratouch/dashcam/
|
||||
├── 20250808/
|
||||
│ ├── chauffeur/ ← 56 GB
|
||||
│ └── weg/
|
||||
├── 20250811/ ← 72 GB
|
||||
│ ├── chauffeur/
|
||||
│ └── weg/
|
||||
├── ...
|
||||
├── 20260328/
|
||||
│ ├── front/
|
||||
│ └── rear/
|
||||
├── ...
|
||||
└── 20260425/ ← 59 GB
|
||||
├── front/
|
||||
└── rear/
|
||||
├── YYYYMMDD/ ← 55 datum-mappen (20250808 t/m 20260425)
|
||||
│ ├── front/ ← hernoemd van chauffeur (2025) of bestond al (2026)
|
||||
│ └── rear/ ← hernoemd van weg (2025) of bestond al (2026)
|
||||
```
|
||||
|
||||
- 2025: mappen `chauffeur/` en `weg/` — oude dashcam
|
||||
- 2026: mappen `front/` en `rear/` — huidige dashcam
|
||||
- Alle mappen nu uniform: `front/` en `rear/`
|
||||
- Platte mappen (20260301-20260311) gesorteerd op F/B suffix
|
||||
- Totale grootte: **3,0 TB**
|
||||
- Oudste map: ~56 GB, nieuwste: ~59 GB
|
||||
|
||||
### Gewenste structuur (bij nieuwe transfers)
|
||||
|
||||
```
|
||||
/mnt/ultratouch/dashcam/
|
||||
└── YYYYMMDD/ ← datum uit bestandsnaam (bv. 20260529)
|
||||
|
|
|
|||
134
restructure.py
Normal file
134
restructure.py
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Herstructureer /mnt/ultratouch/dashcam naar uniforme front/rear structuur."""
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
CAMERA_MAP = {"F": "front", "B": "rear"}
|
||||
CAMERA_PATTERN = re.compile(r"\.MP4$", re.IGNORECASE)
|
||||
# Match bestandsnaam zoals 20260304073341_0000023F.MP4
|
||||
FILE_PATTERN = re.compile(
|
||||
r"^(\d{8})\d{6}_\d+([FB])\.MP4$", re.IGNORECASE
|
||||
)
|
||||
|
||||
DASHCAM = "/mnt/ultratouch/dashcam"
|
||||
|
||||
# === 1. Rename chauffeur → front, weg → rear ===
|
||||
|
||||
def rename_old_subdirs():
|
||||
renamed = 0
|
||||
for entry in sorted(os.listdir(DASHCAM)):
|
||||
date_dir = os.path.join(DASHCAM, entry)
|
||||
if not os.path.isdir(date_dir) or not re.match(r"^\d{8}$", entry):
|
||||
continue
|
||||
|
||||
for old_name, new_name in [("chauffeur", "front"), ("weg", "rear")]:
|
||||
old_path = os.path.join(date_dir, old_name)
|
||||
new_path = os.path.join(date_dir, new_name)
|
||||
if os.path.isdir(old_path) and not os.path.isdir(new_path):
|
||||
shutil.move(old_path, new_path)
|
||||
print(f"Hernoemd: {old_path} → {new_path}")
|
||||
renamed += 1
|
||||
|
||||
if renamed == 0:
|
||||
print("Geen 'chauffeur' of 'weg' mappen gevonden om te hernoemen.")
|
||||
else:
|
||||
print(f"{renamed} mappen hernoemd.")
|
||||
return renamed
|
||||
|
||||
|
||||
# === 2. Splits platte bestanden in front/rear submappen ===
|
||||
|
||||
def sort_flat_files():
|
||||
total_moved = 0
|
||||
for entry in sorted(os.listdir(DASHCAM)):
|
||||
date_dir = os.path.join(DASHCAM, entry)
|
||||
if not os.path.isdir(date_dir) or not re.match(r"^\d{8}$", entry):
|
||||
continue
|
||||
|
||||
# Alleen mappen zonder front/rear subdirs
|
||||
has_front = os.path.isdir(os.path.join(date_dir, "front"))
|
||||
has_rear = os.path.isdir(os.path.join(date_dir, "rear"))
|
||||
if has_front or has_rear:
|
||||
continue
|
||||
|
||||
files = [
|
||||
f for f in os.listdir(date_dir)
|
||||
if FILE_PATTERN.match(f)
|
||||
]
|
||||
if not files:
|
||||
continue
|
||||
|
||||
print(f"\nVerwerk platte bestanden in {entry} ...")
|
||||
for fname in files:
|
||||
match = FILE_PATTERN.match(fname)
|
||||
if not match:
|
||||
continue
|
||||
date_str, cam_suffix = match.group(1), match.group(2).upper()
|
||||
cam_dir = CAMERA_MAP.get(cam_suffix)
|
||||
if not cam_dir:
|
||||
continue
|
||||
|
||||
target_dir = os.path.join(date_dir, cam_dir)
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
|
||||
src = os.path.join(date_dir, fname)
|
||||
dst = os.path.join(target_dir, fname)
|
||||
if os.path.exists(dst):
|
||||
print(f" Overslaan (bestaat al): {dst}")
|
||||
continue
|
||||
|
||||
shutil.move(src, dst)
|
||||
print(f" {fname} → {cam_dir}/")
|
||||
total_moved += 1
|
||||
|
||||
if total_moved:
|
||||
print(f"\n{total_moved} bestanden gesorteerd in front/rear mappen.")
|
||||
else:
|
||||
print("\nGeen platte bestanden gevonden om te sorteren.")
|
||||
return total_moved
|
||||
|
||||
|
||||
# === 3. Controleer of er nog afwijkingen zijn ===
|
||||
|
||||
def check_missers():
|
||||
issues = []
|
||||
for entry in sorted(os.listdir(DASHCAM)):
|
||||
date_dir = os.path.join(DASHCAM, entry)
|
||||
if not os.path.isdir(date_dir) or not re.match(r"^\d{8}$", entry):
|
||||
continue
|
||||
|
||||
front = os.path.isdir(os.path.join(date_dir, "front"))
|
||||
rear = os.path.isdir(os.path.join(date_dir, "rear"))
|
||||
if not (front and rear):
|
||||
issues.append(f" {entry}: heeft niet beide front+rear subdirs")
|
||||
|
||||
# Check of er nog MP4's direct in de date map liggen
|
||||
files = [
|
||||
f for f in os.listdir(date_dir)
|
||||
if FILE_PATTERN.match(f)
|
||||
]
|
||||
if files:
|
||||
issues.append(f" {entry}: {len(files)} MP4 direct in datum-map (niet in front/rear)")
|
||||
|
||||
if issues:
|
||||
print("\n=== Afwijkingen ===")
|
||||
for i in issues:
|
||||
print(i)
|
||||
else:
|
||||
print("\n✅ Alle mappen hebben de juiste structuur.")
|
||||
|
||||
|
||||
def main():
|
||||
print("=== Dashcam herstructurering ===")
|
||||
print(f"Doel: {DASHCAM}\n")
|
||||
|
||||
rename_old_subdirs()
|
||||
sort_flat_files()
|
||||
check_missers()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue