powershell 用于将WebVTT转换为SRT的Windows PowerShell脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 用于将WebVTT转换为SRT的Windows PowerShell脚本相关的知识,希望对你有一定的参考价值。

# convertWebVTT
#
# This is a very basic and incomplete WebVTT to SRT converter. 
# It does not parse or understand the WebVTT elements NOTE, STYLE, REGION or any C-style comments in the WebVTT file. 
#
# Save this file to your desktop as ConvertWebVTT.ps1
# 
# Then create a shortcut for powershell to execute this file (change your username)
# C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -noexit -ExecutionPolicy ByPass -file C:\Users\brian\Desktop\ConvertWebVTT.ps1

# you can drag and drop a .vtt file onto the shortcut and it will convert the file.
#
# Brian A. Onn 

param ( [parameter(Mandatory=$true,ValueFromRemainingArguments=$true)]
        [string[]] $Paths )

ForEach ($Path in $Paths) {
    $Outfile = $Path -replace '(\.vtt|\.txt)','.srt'
    '' > $Outfile
    Get-Content $Path |
         ForEach-Object {
             $_ = $_ -replace '^WEBVTT.*$', ''
             if ($_ -match ':\d\d\.\d{1,3}.*-->') {  
               $_ = $_ -replace '(^|\s)(\d\d):(\d\d)\.(\d{1,3})', '${1}00:$2:$3,$4'
               $_ = $_ -replace ':(\d\d)\.(\d{1,3})', ':$1,$2'
             }
             $_ >> $Outfile
         }

"Converted $Path to $Outfile"
""
}

以上是关于powershell 用于将WebVTT转换为SRT的Windows PowerShell脚本的主要内容,如果未能解决你的问题,请参考以下文章

Windows Powershell脚本用于在特定字符串后查找和替换字符串

我下载了一些视频,但字幕是webvtt格式的,我用的是暴风影音,因此看不到字幕。请问有啥办法可以

powershell PowerShell:将GUID转换为Packed / Compressed

powershell 使用PowerShell将JSON转换为CSV格式

powershell PowerShell:将WMI日期/时间转换为DateTime

powershell 使用PowerShell将JSON转换为CSV格式