[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 flashercs 于 2021-11-19 05:45 编辑
  1. <#*,:&cls
  2. @echo off
  3. pushd "%~dp0"
  4. powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
  5. popd
  6. exit /b
  7. #>
  8. function GenSrt {
  9.   param(
  10.     [string]$Source,
  11.     [string]$Output,
  12.     [timespan]$EndTimeDiff = ([timespan]::FromMilliseconds(150)),
  13.     [timespan]$StartTimeDiff = ([timespan]::FromMilliseconds(-500)),
  14.     [timespan]$MinDiff = ([timespan]::FromMilliseconds(1000))
  15.   )
  16.   $re = New-Object System.Text.RegularExpressions.Regex -ArgumentList @("(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})", [System.Text.RegularExpressions.RegexOptions]::Compiled)
  17.   # $re = [regex]"(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})"
  18.   $format = "hh\:mm\:ss\,fff"
  19.   $timelineformat = "{0:$format} --> {1:$format}"
  20.   Get-Content -Path $Source -Encoding utf8 | ForEach-Object -Begin {
  21.     $lineCtr = 0
  22.     $section = @([timespan]::Zero.Add($EndTimeDiff), $null)
  23.     $sectionIndex = 1
  24.   } -Process {
  25.     if ($lineCtr -eq 1) {
  26.       $match = $re.Match($_)
  27.       if ($match.Success) {
  28.         $section[1] = [timespan]::ParseExact($match.Groups[1].Value, $format, $null).Add($StartTimeDiff)
  29.         if ($section[1].Subtract($section[0]).Duration() -ge $MinDiff ) {
  30.           $sectionIndex
  31.           $timelineformat -f $section
  32.           ""
  33.           ""
  34.           $sectionIndex++
  35.         }
  36.         # $timelineformat -f $section | Write-Host -ForegroundColor Green
  37.         $section[0] = [timespan]::ParseExact($match.Groups[2].Value, $format, $null).Add($EndTimeDiff)
  38.       }
  39.     }
  40.     if ($lineCtr -ge 3) {
  41.       $lineCtr = 0
  42.     } else {
  43.       $lineCtr++
  44.     }
  45.   } | Set-Content -Path $Output -Encoding utf8
  46. }
  47. # [System.IO.Directory]::CreateDirectory($dstdir) | Out-Null
  48. Get-ChildItem -Path "*.srt" -Filter "*.srt" -Exclude "*-副本.srt" | ForEach-Object {
  49.   if (-not $_.PSIsContainer) {
  50.     $dstfile = $_.BaseName + "-副本.srt"
  51.     Write-Host "$($_.Name) --> $dstfile"
  52.     GenSrt -Source $_ -Output $dstfile
  53.   }
  54. }
复制代码
微信:flashercs
QQ:49908356

TOP

回复 3# tianzi


    已修改了.
微信:flashercs
QQ:49908356

TOP

返回列表