VideoHelp Forum
+ Reply to Thread
Results 1 to 7 of 7
Thread
  1. I have file "srt" I want to add alignment for each line


    Before

    SUB.English.srt

    Code:
    1
    00:03:33,680 --> 00:03:35,215
    - my car...
    - what is it doing?
    
    2
    00:03:36,549 --> 00:03:38,051
    What are you doing?
    
    3
    00:03:38,117 --> 00:03:39,953
    What are you driving?

    after

    output.srt

    Code:
    1
    00:03:33,680 --> 00:03:35,215
    {\an8}- my car...
    - what is it doing?
    
    2
    00:03:36,549 --> 00:03:38,051
    {\an8}What are you doing?
    
    3
    00:03:38,117 --> 00:03:39,953
    {\an8}What are you driving?


    All I need only. add alignment Using Python Any suggestions?
    Quote Quote  
  2. This might work, (not tested):
    Code:
    infile =  'orig.srt'
    outfile = 'output_file.srt'
    #formatting new line, where {0} gets formatted as original text
    new_line = '{{\\an8}}{0}\n'
    
    with open(outfile, 'w') as out_file:
        with open(infile) as in_file:
            rewrite = False
            for line in in_file:
                if rewrite:
                    #format new text line
                    out_file.write(new_line.format(line))
                else:
                    #just copy line
                    out_file.write(f'{line}\n')
                
                if '-->' in line:
                    rewrite = True
                else:
                    rewrite = False
    Quote Quote  
  3. Thanks it works. Is there a solution for empty spaces?
    https://forum.videohelp.com/images/imgfiles/v6iYfwG.jpg
    Quote Quote  
  4. Originally Posted by _Al_ View Post
    This might work, (not tested):
    Code:
    infile =  'orig.srt'
    outfile = 'output_file.srt'
    #formatting new line, where {0} gets formatted as original text
    new_line = '{{\\an8}}{0}\n'
    
    with open(outfile, 'w') as out_file:
        with open(infile) as in_file:
            rewrite = False
            for line in in_file:
                if rewrite:
                    #format new text line
                    out_file.write(new_line.format(line))
                else:
                    #just copy line
                    out_file.write(f'{line}\n')
                
                if '-->' in line:
                    rewrite = True
                else:
                    rewrite = False
    It works after removing
    \n

    Thanks again
    Quote Quote  
  5. ok, '\n' is a new line for printing. I thought that when reading lines that line variable string does not carry it at the end.
    Quote Quote  
  6. I remember that this already happened to me, and simply 're-saving as srt' in 'Subtitle Edit' was corrected ...
    責任者-MDX
    Quote Quote  
  7. Things like that are easier to do in apps that handle subtitles. But he mentioned in his earliest threads that he uses windows batch files to handle more subtitles at once or for some other reasons.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!