DavinciTimestamp.psm1
function Find-EDLFile { [CmdletBinding()] param() Get-ChildItem -Path $PWD.Path,$HOME,"C:\temp","/tmp" -Filter *.edl -File -ErrorAction SilentlyContinue | Select-Object -First 1 } <# .SYNOPSIS Converts an Edit Decision List (EDL) string to timestamps and titles. .DESCRIPTION This cmdlet reads an EDL string specified by the user and extracts timestamps and titles from it. If the provided EDL data only contains Timestamps that start with "01:", it's assumed that the user made an error. In that case all resulting Timestamps will start with "00:" instead. That behavior can be changed, if providing the -IgnoreOnly01Timestamps switch parameter. .PARAMETER Value The EDL string data that should be processed. This parameter is mandatory. .PARAMETER IgnoreOnly01Timestamps Ignores that all Timestamps might start with '01:' and does not try to fix it by using '00:' instead. .EXAMPLE ConvertFrom-EDL -Value $MyEDLData Reads the provided EDL String data and outputs the extracted timestamps and titles. .EXAMPLE ConvertFrom-EDL -Value $MyEDLData -IgnoreOnly01Timestamps Reads the provided EDL String data and outputs the extracted timestamps and titles. Ignores that all Timestamps in the EDL data start with '01:'. .INPUTS None. You cannot pipe objects to Convert-EDL2Timestamp.ps1. .OUTPUTS String. Outputs strings that combine a timestamp and a title, separated by a space. .NOTES Version: 1.0 Author: Andreas Dieckmann Creation Date: 2025-08-30 Purpose/Change: Initial development .LINK https://github.com/diecknet/DavinciTimestamp #> function ConvertFrom-EDL { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [AllowEmptyString()] [String[]] $Value, [switch]$IgnoreOnly01Timestamps ) # If EDL was provided as one multi-line string instead of an array if($Value.Count -eq 1) { $Value = $Value -split "`n" } $Result = [Ordered]@{} for($i = 0; $i -lt $Value.Count ; $i++){ $Title = $null # Reset title if($Value[$i] -match "^\d{3}\s+\d{3}.+?(\d{2}:\d{2}:\d{2})") { $Timestamp = $Matches[1] Write-Verbose "Found timestamp on line ${i}: $Timestamp" $i++ # Move to next line if($Value[$i] -match "\|M:(.+?) \|") { $Title = $Matches[1] Write-Verbose "Found title on line ${i}: $Title" } $Result[$Timestamp] = $Title } } # if there are only Timestamps that start with "01:" there might be something wrong if($Result.Keys -like "01:*" -and $Result.Keys -notlike "00:*" -and (-not $IgnoreOnly01Timestamps)) { Write-Warning "There were only Timestamps that start with '01:', which seems wrong, so they got replaced by '00:'" Write-Warning "You can prevent this behavior by specifying -IgnoreOnly01Timestamps (or provide EDL data where the Timestamps start with '00:')" foreach($Key in $Result.Keys) { "00:{0} {1}" -f ($Key -split ":",2)[1],$($Result[$Key]) } } else { foreach($Key in $Result.Keys) { "{0} {1}" -f $Key,$($Result[$Key]) } } } <# .SYNOPSIS Gets Timestamp and Title Data from an Edit Decision List (EDL) file. .DESCRIPTION This cmdlet reads an EDL file specified by the user and extracts timestamps and titles from it. If no path an EDL file was specified, the cmdlet will try to find a .edl file itself. Under the hood Get-EDLTimestamp reads the EDL file and then calls ConvertFrom-EDL. There is also the "gts" alias for Get-EDLTimestamp. .PARAMETER Path The EDL file that should be processed. This parameter is optional. If no Path is specified, the cmdlet tries to find a EDL file. .PARAMETER IgnoreOnly01Timestamps Ignores that all Timestamps might start with '01:' and does not try to fix it by using '00:' instead. .EXAMPLE Get-EDLTimestamp -Path "C:\Video\MyVideo.edl" Reads the provided EDL file and outputs the extracted timestamps and titles. .EXAMPLE Get-EDLTimestamp Since no EDL file was provided, the cmdlet tries to automatically find an .edl file itself. It looks in the following locations (in this order) $PWD.Path, $HOME, C:\temp, /tmp It will only use the first file found. .INPUTS None. You cannot pipe objects to Get-EDLTimestamp. .OUTPUTS String. Outputs strings that combine a timestamp and a title, separated by a space. .NOTES Version: 1.0 Author: Andreas Dieckmann Creation Date: 2025-08-30 Purpose/Change: Initial development .LINK https://github.com/diecknet/DavinciTimestamp #> function Get-EDLTimestamp { [Alias("gts")] [CmdletBinding()] param( [Parameter(Mandatory=$false)] [System.IO.FileInfo] $Path, [switch]$IgnoreOnly01Timestamps) $OptionalParametersPassThrough = @{} if($PSBoundParameters.ContainsKey("IgnoreOnly01Timestamps")) { $OptionalParametersPassThrough["IgnoreOnly01Timestamps"] = $IgnoreOnly01Timestamps } if([string]::IsNullOrEmpty($Path)) { Write-Verbose "No 'Path' specified by user, trying to find EDL file automatically instead..." $Path = Find-EDLFile if(-not $Path) { Write-Verbose "Found no EDL file. Aborting." throw "ERROR: Please provide the path of an EDL file with -Path" } Write-Verbose "Found EDL file: $Path" } if(Test-Path($Path)) { Write-Verbose "Reading content of EDL file: $Path" $EDLFileContent = Get-Content -Path $Path -ErrorAction Stop Write-Verbose "Calling ConvertFrom-EDL" ConvertFrom-EDL -Value $EDLFileContent @OptionalParametersPassThrough } else { throw "File does not exist ($Path)." } } # This will will be automatically filled by the build process / PSake |