Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- Turn Youtube transcription into srt file. Specify the transcription file name, the offset in minute(s), the offset in second(s) and the end time of the video bellow.
- To get a youtube video transcription :
- Click the 3 dots next to the Share button and click Display the transcription. Then in the comment section click Display the transcription. Copy and paste the transcription on the right of the video to a file.
- #>
- $transcriptionFile = "subtitle-issou-short-retimed.txt"
- $minutesOffset = 3
- $secondsOffset = 21
- $endTime = "00:03:03,000" # example : 3 minutes and 3 seconds
- $PSDefaultParameterValues = @{'*:Encoding' = 'utf8'}
- $counter = 0
- $CustomObjs=@()
- $previousTime = "00:00:00,000"
- $srtName = $transcriptionFile.Replace(".txt", "")
- $srtName = "$srtName.srt"
- if (Test-Path $srtName) {
- Remove-Item $srtName
- }
- Get-Content $transcriptionFile | foreach {
- If ($_ -match '\d{1}\:') {
- $counter = $counter + 1
- $oldTime = $_.Split(":")
- $oldTimeMinutes = $oldTime[0]
- $oldTimeSecondes = $oldTime[1]
- $newTimeNMinutes = $oldTimeMinutes - $minutesOffset
- [int]$newTimeSecondes = $oldTimeSecondes - $secondsOffset
- If ($newTimeSecondes -lt 0) {
- $newTimeNMinutes = $newTimeNMinutes - 1
- $newTimeSecondes = 60 + $newTimeSecondes
- }
- If ($newTimeSecondes -lt 10) {
- $strNewTimeNMinutes = [string]$newTimeSecondes
- $strNewTimeNMinutes = '0' + $strNewTimeNMinutes
- [string]$newTimeSecondes = $strNewTimeNMinutes
- }
- $newTime = "00:0$($newTimeNMinutes):$newTimeSecondes"
- If ($counter - 2 -ge 0) {
- [string]$CustomObjs[$counter-2].Time = "$($CustomObjs[$counter-2].Time + $newTime),000"
- $dateArray =$([string]$CustomObjs[$counter-2].Time).Split(" --> ")
- $fullTime = "$($dateArray[5]) --> "
- }
- Else {
- $fullTime = "00:00:00,000 --> "
- }
- $CustomObj = New-Object -TypeName PSObject -Property @{ 'ID' = $counter ; 'Time' = $fullTime ; 'Text' = "" }
- }
- Else {
- $CustomObj.Text = $_
- $CustomObjs += $CustomObj
- }
- }
- [string]$CustomObjs[$counter-1].Time = "$($CustomObjs[$counter-1].Time)$endTime"
- $endCounter = 0
- $CustomObjs | foreach {
- If ($endCounter -eq 33) {
- Add-Content $srtName "$($_.ID)`n$($_.Time)`n$($_.Text)" -NoNewline
- }
- Else {
- Add-Content $srtName "$($_.ID)`n$($_.Time)`n$($_.Text)`n"
- }
- $endCounter = $endCounter + 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement