69 lines
2.3 KiB
PowerShell
69 lines
2.3 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Lance gpx_video.py sur toutes les traces GPX du répertoire courant.
|
|
|
|
.DESCRIPTION
|
|
Utilise le venv .venv situé à côté de ce script (il est créé et les
|
|
dépendances de requirements.txt installées s'il n'existe pas encore).
|
|
Chaque fichier *.gpx du répertoire courant produit une vidéo MP4 du même nom.
|
|
Les arguments supplémentaires sont transmis tels quels à gpx_video.py.
|
|
|
|
.EXAMPLE
|
|
.\gpx_video.ps1
|
|
.\gpx_video.ps1 --duree 90 --zoom-villes
|
|
#>
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$code = 0
|
|
|
|
try {
|
|
$racine = $PSScriptRoot
|
|
$venv = Join-Path $racine '.venv'
|
|
$python = Join-Path $venv 'Scripts\python.exe'
|
|
$script = Join-Path $racine 'gpx_video.py'
|
|
|
|
if (-not (Test-Path $python)) {
|
|
Write-Host "Création du venv dans $venv ..."
|
|
& python -m venv $venv
|
|
if ($LASTEXITCODE -ne 0) { throw "Échec de la création du venv." }
|
|
& $python -m pip install --upgrade pip
|
|
& $python -m pip install -r (Join-Path $racine 'requirements.txt')
|
|
if ($LASTEXITCODE -ne 0) { throw "Échec de l'installation des dépendances." }
|
|
}
|
|
|
|
if (-not (Get-Command ffmpeg -ErrorAction SilentlyContinue)) {
|
|
throw "ffmpeg introuvable dans le PATH."
|
|
}
|
|
|
|
$traces = @(Get-ChildItem -Path (Get-Location) -Filter '*.gpx' -File | Sort-Object Name)
|
|
if ($traces.Count -eq 0) {
|
|
throw "Aucun fichier .gpx dans $(Get-Location)."
|
|
}
|
|
|
|
$echecs = @()
|
|
$i = 0
|
|
foreach ($trace in $traces) {
|
|
$i++
|
|
Write-Host "[$i/$($traces.Count)] $($trace.Name)" -ForegroundColor Cyan
|
|
& $python $script $trace.FullName @args
|
|
if ($LASTEXITCODE -ne 0) { $echecs += $trace.Name }
|
|
}
|
|
|
|
if ($echecs.Count -gt 0) {
|
|
throw "Échec pour : $($echecs -join ', ')"
|
|
}
|
|
Write-Host "Terminé : $($traces.Count) vidéo(s) générée(s)." -ForegroundColor Green
|
|
}
|
|
catch {
|
|
Write-Host "ERREUR : $($_.Exception.Message)" -ForegroundColor Red
|
|
$code = 1
|
|
}
|
|
|
|
# Laisse la fenêtre ouverte en cas d'échec (lancement par double-clic ou
|
|
# « Exécuter avec PowerShell »), sauf en mode non interactif.
|
|
if ($code -ne 0 -and [Environment]::UserInteractive -and
|
|
-not ([Environment]::GetCommandLineArgs() -match '^-NonI')) {
|
|
Read-Host "Appuyez sur Entrée pour fermer" | Out-Null
|
|
}
|
|
exit $code
|