728x90

srt 자막을 좀 깔끔하게 정리하려고 만들어고 있는 코드이다.

SE(subtitle edit) 자막툴에서는 제공하는 기능도 있지만 없는 기능도 추가를 해서 만들었다.

두사람의 대화 하이픈 처리하는 것도 추가를 했다. 하지만 영상을 보면서 잘못된 것은 직접 수정해야 할 수도 있다.


Sub srt_error_correct()
'// 자막 오류 수정
    Dim rngC, rngAll As Range
    Dim msg As String                           '// 팝업 메시지 변수
    Dim i, k, n, r, cnt, C, sd, ds As Long
    Dim strU As String
       
    Application.ScreenUpdating = False
    Set rngAll = Range([A2], Cells(Rows.Count, "A").End(3))

    i = 0: k = 0: n = 0: sd = 0: ds = 0   '// 초기값 0
    For r = rngAll.Rows.Count + 1 To 2 Step -1    '// 마지막행부터 위로 올라가면서 삭제처리
'        Cells(r, "A").Select
        If InStr(Cells(r, "A"), "-->") > 0 Then     '// 타임코드 행을 만나면
            If Cells(r + 1, "A") = vbNullString Then    '// 바로 아래 행이 빈줄이면
                If IsNumeric(Cells(r + 2, "A")) Then    '// 그 아랫줄이 행을 나타내는 숫자인가?
                    Range(Cells(r - 1, "A"), Cells(r + 1, "A")).Resize(, 3).Delete
                    r = r - 1   '// 셀이 삭제되므로 1 만 감소시켜야 함
                    sd = sd + 1     '// delete 한 빈자막 숫자 카운트
                Else
                    r = r - 1
                End If
            Else
                r = r - 1
            End If
        Else
            If Left(Cells(r, "A"), 1) = "(" And Right(Cells(r, "A"), 1) = ")" Then
                Cells(r, "A").Resize(, 3).Delete   '// Shift:=xlUp
                i = i + 1
           
            ElseIf Left(Cells(r, "A"), 2) = "-(" And Right(Cells(r, "A"), 1) = ")" Then
                Cells(r, "A").Resize(, 3).Delete      '// Shift:=xlUp
                i = i + 1
           
            ElseIf InStr(Cells(r, "A"), ":") And InStr(Cells(r, "A"), "-->") = 0 Then   '// 사람 구분을 위한 식별자 : 가 들어간
                strU = Trim(Split(Cells(r, "A"), ":")(0))
                If InStr(Cells(r, "A"), "http://") = 0 Then
                    Cells(r, "A") = Trim(Split(Cells(r, "A"), ":")(1))      '// : 가 들어간 오른쪽만 저장(사람 식별자는 지움)
                    k = k + 1
                End If
           
            ElseIf InStr(Cells(r, "A"), "(") Then
                If InStr(Cells(r, "A"), ")") Then
                    Cells(r, "A") = Trim(Split(Cells(r, "A"), "(")(0)) & Trim(Split(Cells(r, "A"), ")")(1))     '// ( 괄호안의 내용은 제외
                    n = n + 1
                End If
       
            ElseIf InStr(Cells(r, "A"), "[") Then
                If InStr(Cells(r, "A"), "]") Then
                    Cells(r, "A") = Trim(Split(Cells(r, "A"), "[")(0)) & Trim(Split(Cells(r, "A"), "]")(1))     '// [ 괄호안의 내용은 제외
                    n = n + 1
                End If
           
            ElseIf Left(Cells(r, "A"), 1) = "-" And Mid(Cells(r, "A"), 1, 2) <> "- " Then   '// - 다음에 공백이 아니면
                Cells(r, "A") = "- " & Mid(Cells(r, "A"), 2, Len(Cells(r, "A")) - 1)    '// - 다음에 공백을 하나 넣어라
                ds = ds + 1
               
            ElseIf Mid(Cells(r, "A"), 1, 2) = "- " Then     '// 윗줄에는 - 가 들어가 있고 아랫줄에는 - 가 없으면
                If Cells(r + 1, "A") <> vbNullString And Left(Cells(r + 1, "A"), 1) <> "-" Then     '// - 가 없으면
                    Cells(r + 1, "A") = "- " & Cells(r + 1, "A")
                    ds = ds + 1
                End If
               
            ElseIf Left(Cells(r, "A"), 1) <> "-" And Mid(Cells(r + 1, "A"), 1, 2) = "- " Then   '// 윗줄 - 가 없고 아랫줄 - 가 있을 경우
                Cells(r, "A") = "- " & Cells(r, "A")
                ds = ds + 1
               
            ElseIf Left(Cells(r, "A"), 1) = "-" And Cells(r + 1, "A") = vbNullString And Cells(r + 2, "A") <> vbNullString Then
                Cells(r, "A") = Trim(Mid(Cells(r, "A"), 2, Len(Cells(r, "A")) - 1))
            End If
        End If
    Next
   
    Set rngAll = Nothing
    cnt = i + k + n + sd + ds
    msg = "청각자막 = " & i & " 개" & vbCr
    msg = msg & "대사 : 있는 것 = " & k & " 개" & vbCr
    msg = msg & "괄호문자 = " & n & " 개" & vbCr
    msg = msg & "빈자막 = " & sd & " 개" & vbCr
    msg = msg & "대쉬처리 = " & ds & " 개" & vbCr
    msg = msg & "총 " & cnt & " 개 자막수정 처리했음" & vbCr
    msg = msg & "총 Line 수 = " & Cells(Rows.Count, "A").End(3).Row - 1
    MsgBox msg
End Sub

블로그 이미지

Link2Me

,