1

I want to apply "Full inverse" so srt files maminly in arabic, I am able to read the file and store it in a list :


file1 = open('myFile.txt', 'r')
Lines = file1.readlines()
 
count = 0
strings=[]
# Strips the newline character
for line in Lines:
    count += 1
    #print("Line{}: {}".format(count, line.strip()))
    strings.append(line)

the issue is what could be the solution to apply the full inverse to only the text from the file and not the time stamp or the numbered line like this pic srt file

the pattern with srt files is that first it has the numbered line for example " 1 " then the next line has the time " 00:00:00,166 --> 00:00:02,233 ", then it has the text it self, but the after the first line all srt has empty line then it start with number "2", what i though of is to skip 2 lines always and inverse the third but this patter not valid. Any idea ?

I tried to apply a pattern of skipping 2-3 lines then inverse the third but that patter is not valid

  • I would tend to detect if a line was predominately Arabic script, if so, process the line. Although I am uncertain why you want t reverse the lines anyway, since it would just complicate any additional processing you would do. – Andj Aug 24 '23 at 12:19

1 Answers1

0

what i though of is to skip 2 lines always and inverse the third but this patter not valid

Between two successive Arabic lines, there are 3 lines you're not interested in:

  • an empty line
  • a counter line
  • a time-range line

So if you change your approach to skip 3 and invert the fourth, that might work.

But my advice would be to not simply skip lines, but confirm (e.g., assert) that these lines have the expected form. That way, you'll find out immediately if the file doesn't meet your expectations. (For example, there might be a bug in the process that creates the file, or your understanding of the file format might be incomplete.)

Michael Dyck
  • 2,153
  • 1
  • 14
  • 18