I need to convert .ass subtitles file into .xml file. So far I did it by hand, but I have to do more and more of it.
That’s how process looks like:
Input .ass file:
Dialogue: 0,0:00:08.03,0:00:10.57,Default,,0000,0000,0000,,Actor says something
Dialogue: 0,0:00:11.28,0:00:21.05,Default,,0000,0000,0000,,Actor says something
etc.
Output .xml file:
<p begin="00:00:08.03" end="00:00:10.57">Actor says something</p>
<p begin="00:00:11.28" end="00:00:21.05">Actor says something</p>
etc.
I dodn’t know how to solve this task.
First, you should extract the relevant information from your source file. As the data is
,-seperated, you can use the python csv module or do a simplesplit(',').This is an example method of how it could look like:
The next step if to convert your extracted data to the desired xml format. A function that plays well with the data from the first method could look like this (using simple string formatting):
Finally, opening the files and use the methods to write your output:
While you could of course make this smaller (less LOC), it is a readable approach IMHO.