Difference between revisions of "Fate/stay night:Clean .KS files"

From Baka-Tsuki
Jump to navigation Jump to search
(Split up in two parts)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
== Introduction ==
This program allow you to clean a .ks file from kirikiri script (@...) and word wrapping ([wrap text="..."]).<br>
 
  +
Decrypted *.ks-files contain not just decrypted text, but various service info as well (word wrapping tags, for example) that hinders translation process. To remove this service info and get text-only file, one can use:
I only left the [lineX] balise, because it make complain the editors if they find unfinished sentences, even if it's normal. ^^<br>
 
''Old versions can be found in Historic of this page.''
 
   
  +
*MS Word 2003 macro (to edit one given script file within Word). Requires MS Word 2003 or above.
=== How to use ===
 
  +
*Python script (for batch processing of all *.ks-files in a given directory). Requires Python 2.x and (sometimes) MS Applocale.
   
I wrote this program with .Net 3.5 so you need the .Net framework up-to-date on your PC.<br>
 
If you want, you can access to the source code with a simple .Net decompiler, I don't have protected this program.
 
   
  +
== MS Word 2003 Macro ==
  +
Requires MS Word 2003 or newer.<br>
  +
To use the following macro, you have to insert it into your Word document, save changes and run it. It will remove most frequent tags from your script (you can tell by looking).
  +
Press '''Alt+F11''' to insert a macro in your document, copy and paste the following code ('''Ctrl+C, Ctrl+V''') and save changes ('''Ctrl+S'''). Then run a macro via menu, usually '''Service - Macro'''. <!-- Translation may be wrong, please fix it in this case, if you have English version of MS Word-->
  +
<pre>Sub FSN_CleanUp()
  +
'
  +
' macro for MS Word 2003
  +
' created at 11.05.2008 by DMC
  +
'
  +
Selection.Find.ClearFormatting
  +
Selection.Find.Replacement.ClearFormatting
  +
With Selection.Find
  +
.Text = "\*page0*texton"
  +
.Replacement.Text = ""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchFuzzy = False
  +
.MatchWildcards = True
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
With Selection.Find
  +
.Text = "\[wrap text=*\]"
  +
.Replacement.Text = ""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchFuzzy = False
  +
.MatchWildcards = True
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
With Selection.Find
  +
.Text = "\[line*\]"
  +
.Replacement.Text = ""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchFuzzy = False
  +
.MatchWildcards = True
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
Selection.Find.ClearFormatting
  +
Selection.Find.Replacement.ClearFormatting
  +
With Selection.Find
  +
.Text = "[l][r]"
  +
.Replacement.Text = ""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchWildcards = False
  +
.MatchFuzzy = False
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
Selection.Find.ClearFormatting
  +
Selection.Find.Replacement.ClearFormatting
  +
With Selection.Find
  +
.Text = "\*page*|"
  +
.Replacement.Text = ""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchFuzzy = False
  +
.MatchWildcards = True
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
Selection.Find.ClearFormatting
  +
Selection.Find.Replacement.ClearFormatting
  +
With Selection.Find
  +
.Text = "@pgnl"
  +
.Replacement.Text = ""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchWildcards = False
  +
.MatchFuzzy = False
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
Selection.Find.ClearFormatting
  +
Selection.Find.Replacement.ClearFormatting
  +
With Selection.Find
  +
.Text = "\@textoff*texton^13"
  +
.Replacement.Text = ""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchFuzzy = False
  +
.MatchWildcards = True
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
Selection.Find.ClearFormatting
  +
Selection.Find.Replacement.ClearFormatting
  +
With Selection.Find
  +
.Text = "@pg"
  +
.Replacement.Text = ""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchWildcards = False
  +
.MatchFuzzy = False
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
Selection.Find.ClearFormatting
  +
Selection.Find.Replacement.ClearFormatting
  +
With Selection.Find
  +
.Text = "\@textoff*return^13"
  +
.Replacement.Text = ""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchFuzzy = False
  +
.MatchWildcards = True
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
Selection.Find.ClearFormatting
  +
Selection.Find.Replacement.ClearFormatting
  +
With Selection.Find
  +
.Text = "\@*^13"
  +
.Replacement.Text = ""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchFuzzy = False
  +
.MatchWildcards = True
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
Selection.Find.ClearFormatting
  +
Selection.Find.Replacement.ClearFormatting
  +
With Selection.Find
  +
.Text = """"""
  +
.Replacement.Text = """..."""
  +
.Forward = True
  +
.Wrap = wdFindContinue
  +
.Format = False
  +
.MatchCase = False
  +
.MatchWholeWord = False
  +
.MatchByte = False
  +
.MatchAllWordForms = False
  +
.MatchSoundsLike = False
  +
.MatchWildcards = False
  +
.MatchFuzzy = False
  +
End With
  +
Selection.Find.Execute Replace:=wdReplaceAll
  +
  +
End Sub
  +
</pre>
  +
Original version is [http://www.baka-tsuki.org/project/index.php?title=%D0%A1%D1%83%D0%B4%D1%8C%D0%B1%D0%B0/%D0%9D%D0%BE%D1%87%D1%8C_%D1%81%D1%85%D0%B2%D0%B0%D1%82%D0%BA%D0%B8:%D0%A7%D0%B8%D1%81%D1%82%D0%BA%D0%B0_%D1%81%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2 here] (Russian).
   
  +
== Python Batch Script ==
''You don't need to install this program, it is just a small executable, so just execute it!''<br>
 
  +
Requires Python 2.x ([http://www.python.org/download/ download]). MS Applocale ([http://www.microsoft.com/globaldev/tools/apploc.mspx download], [http://www.microsoft.com/downloads/info.aspx?na=90&p=&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=8c4e8e0d-45d1-4d9b-b7c0-8430c1ac89ab&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f5%2f6%2f8%2f568a8caf-29c4-43ec-a10f-97730f26977e%2fapploc.msi DDL] or [http://www.google.com/search?q=Applocale+download Google]) is required only if your .ks-files have Japanese characters in filenames.<br>
It will try to create/add-in a .config file (where ? In your User's AppData directory... I think :p) to save your settings (last directory used...) but it's not a critical file.
 
  +
The following script exports only text from all .ks-files in the directory it's run from. Text is saved in .txt-files that are created the same directory, one .txt per each .ks-file. Save the following code as text (*.txt) file, rename it into Python script (*.py) file and copy/move script file to a directory you have extracted .ks-files in. If you have Python installed, *.py-files can be run as other programs (e.g. by single or double-click).
   
  +
Python is bundled with many operating systems (Mac OS X, *nix and *BSD), <u>but not with OS from Microsoft</u>. To be able to use Python in Windows, you have to download and install Python 2.x (script isn't tested with Python 3.0 and above).
   
  +
If your Windows OS doesn't use Japanese local settings for programs that don't support Unicode, script won't work on .ks-files with Japanese characters in filenames. Hence you either should rename your *.ks-files in order for them to have only ASCII symbols in filenames (latin alphabet and/or digits) or run script under Microsoft Applocale. In latter case open command line console via Applocale (start Applocale and set it to run '''%windir%\system32\cmd.exe''' under Windows XP or 2003), change directory to the location of your *.ks-files and *.py-file (e.g. '''cd "C:\FSN Files\Scripts"'''), and run Python script (e.g by entering '''gettext.py''' in command line). Script file must contain the following (make sure you have indentation intact, Python is strict about this!):
For clean a .ks file, open it (with "File->Open", or just drag&drop your file on the white zone from the windows explorer) then go in "Edit->Clean a file".<br>
 
Then go save your file (File->Save) where you want, or just copy the text (you can select all text with Ctrl+A), on a web page for example.<br>
 
For clean an other file, close your file ("File->Close"), and open an other!
 
   
  +
<pre>import os
   
  +
def debrack(line):
''Well, clean files one by one isn't quick so, with the version 1.1, you can clean all .ks files of a folder by one click!''<br>
 
  +
linemark = line.find('[line')
Just click on "Edit->Clean a directory" select your directory '''and make sure you have a copy of this directory''' because that will ''replace files'', not make new!<br>
 
  +
if linemark+1:
Then click on OK and wait few seconds... That's done.
 
  +
line = line[:linemark]+'-----'+line[linemark+7:]
  +
start = line.find('[')
  +
end = line.find(']')
  +
if start == -1: return line
  +
if start < end: return line[:start]+line[end+1:]
  +
return ''
   
  +
files = []
 
  +
for file in os.listdir(os.getcwd()):
''With the version 1.2 you can clean just what you want!''<br>
 
  +
if file.endswith('.ks'): files.append(file)
With "Edit->Clean a file->Clean from Word-Wrap" you can unworp-wrap your .ks file to make an occidental .ks file look like original japanese .ks file (more readable outside of the game).<br>
 
  +
if len(files) == 0:
With "Edit->Clean a file-> Clean from Voice" you can unvoice your .ks file to make an unvoiced version.
 
  +
print 'No *.ks file(-s) to decode in current directory!'
 
  +
exit()
 
  +
for file in files:
''With version 1.3, you can make a translated file with script from a cleaned translated file and an english scripted file!''<br>
 
  +
print file,
Go in "Remake Script->Add Word-Wrap and Script to a cleaned file" and load the cleaned file, then the original file.
 
  +
raw = open(file, 'rb')
Then go in "File->Save" to make a save of the new scripted and translated file.
 
  +
res = open(file.replace('.ks', '.txt'), 'wb')
 
  +
for line in raw:
 
  +
if line.find('\x00[\x00w\x00r\x00a\x00p\x00 \x00t\x00e\x00x\x00t\x00=\x00"\x00"\x00]') >= 0:
''Version 1.4 is for some bug fix ( "[lineX] balise" in ReWord-Wrap function and other minor bugs).''
 
  +
line = line.replace('\x00', '')
 
  +
line = line.replace('[l]', '\r\n')
 
  +
templine = debrack(line)
''With version 1.5, you can add word-wrap to a KS file, without use "Remake Script" menu, all is in "File" menu.''
 
  +
for i in range (1,100):
So now you can open an english KS file, undo word-wrap, translate the text, and redo word-wrap without modificate the script part of the file.
 
  +
newline = debrack(templine)
It's not real friendly-translator but you can, if you don't want to undo all script and redo it with "Remake Script".
 
  +
if newline[2:4] == '""': break
This version also resolve some bugs in openning file and redo word-wrap, and upgrade performance.
 
  +
if newline == templine:
 
  +
res.write(newline[2:])
 
  +
break
 
  +
else:
If you have any question, request or bug, please [http://www.baka-tsuki.net/forums/ucp.php?i=pm&mode=compose&u=2556 PM me on the baka-tsuki forum].<br>
 
  +
templine = newline
--[[User:Bejarid|Bejarid]] 15:58, 6 March 2009 (UTC)
 
  +
if line.find('*page')+1: res.write('\r\n')
 
  +
raw.close()
=== Download ===
 
  +
res.close()
 
  +
print '-> '+file.replace('.ks', '.txt')</pre>
Direct Download with SkyDrive : [http://cid-9f7f142a41f7f1b9.skydrive.live.com/self.aspx/FSN/CleanerFSN%20v1.5.exe CleanerFSN v1.5] | [http://cid-9f7f142a41f7f1b9.skydrive.live.com/self.aspx/FSN/FSN%20VOSTA%20v3.2.rar English KS files for example]
 
  +
Original version is [http://www.baka-tsuki.org/project/index.php?title=%D0%A1%D1%83%D0%B4%D1%8C%D0%B1%D0%B0/%D0%9D%D0%BE%D1%87%D1%8C_%D1%81%D1%85%D0%B2%D0%B0%D1%82%D0%BA%D0%B8:%D0%A7%D0%B8%D1%81%D1%82%D0%BA%D0%B0_%D1%81%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2 here] (Russian). Use [http://www.baka-tsuki.org/project/index.php?title=Talk:Fate/stay_night:Clean_.KS_files&action=edit discussion page] for comments or PM [http://www.baka-tsuki.net/forums/ucp.php?i=pm&mode=compose&u=1335 Const2k] on B-T forum.

Latest revision as of 00:30, 23 March 2009

Introduction[edit]

Decrypted *.ks-files contain not just decrypted text, but various service info as well (word wrapping tags, for example) that hinders translation process. To remove this service info and get text-only file, one can use:

  • MS Word 2003 macro (to edit one given script file within Word). Requires MS Word 2003 or above.
  • Python script (for batch processing of all *.ks-files in a given directory). Requires Python 2.x and (sometimes) MS Applocale.


MS Word 2003 Macro[edit]

Requires MS Word 2003 or newer.
To use the following macro, you have to insert it into your Word document, save changes and run it. It will remove most frequent tags from your script (you can tell by looking). Press Alt+F11 to insert a macro in your document, copy and paste the following code (Ctrl+C, Ctrl+V) and save changes (Ctrl+S). Then run a macro via menu, usually Service - Macro.

Sub FSN_CleanUp()
'
' macro for MS Word 2003
' created at 11.05.2008 by DMC
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "\*page0*texton"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "\[wrap text=*\]"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "\[line*\]"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "[l][r]"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .MatchFuzzy = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "\*page*|"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "@pgnl"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .MatchFuzzy = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "\@textoff*texton^13"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "@pg"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .MatchFuzzy = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "\@textoff*return^13"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "\@*^13"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = """"""
        .Replacement.Text = """..."""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .MatchFuzzy = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
End Sub

Original version is here (Russian).

Python Batch Script[edit]

Requires Python 2.x (download). MS Applocale (download, DDL or Google) is required only if your .ks-files have Japanese characters in filenames.
The following script exports only text from all .ks-files in the directory it's run from. Text is saved in .txt-files that are created the same directory, one .txt per each .ks-file. Save the following code as text (*.txt) file, rename it into Python script (*.py) file and copy/move script file to a directory you have extracted .ks-files in. If you have Python installed, *.py-files can be run as other programs (e.g. by single or double-click).

Python is bundled with many operating systems (Mac OS X, *nix and *BSD), but not with OS from Microsoft. To be able to use Python in Windows, you have to download and install Python 2.x (script isn't tested with Python 3.0 and above).

If your Windows OS doesn't use Japanese local settings for programs that don't support Unicode, script won't work on .ks-files with Japanese characters in filenames. Hence you either should rename your *.ks-files in order for them to have only ASCII symbols in filenames (latin alphabet and/or digits) or run script under Microsoft Applocale. In latter case open command line console via Applocale (start Applocale and set it to run %windir%\system32\cmd.exe under Windows XP or 2003), change directory to the location of your *.ks-files and *.py-file (e.g. cd "C:\FSN Files\Scripts"), and run Python script (e.g by entering gettext.py in command line). Script file must contain the following (make sure you have indentation intact, Python is strict about this!):

import os

def debrack(line):
 linemark = line.find('[line')
 if linemark+1:
  line = line[:linemark]+'-----'+line[linemark+7:]
 start = line.find('[')
 end = line.find(']')
 if start == -1: return line
 if start < end: return line[:start]+line[end+1:]
 return ''

files = []
for file in os.listdir(os.getcwd()):
 if file.endswith('.ks'): files.append(file)
if len(files) == 0:
 print 'No *.ks file(-s) to decode in current directory!'
 exit()
for file in files:
 print file,
 raw = open(file, 'rb')
 res = open(file.replace('.ks', '.txt'), 'wb')
 for line in raw:
  if line.find('\x00[\x00w\x00r\x00a\x00p\x00 \x00t\x00e\x00x\x00t\x00=\x00"\x00"\x00]') >= 0:
   line = line.replace('\x00', '')
   line = line.replace('[l]', '\r\n')
   templine = debrack(line)
   for i in range (1,100):
    newline = debrack(templine)
    if newline[2:4] == '""': break
    if newline == templine:
     res.write(newline[2:])
     break
    else:
     templine = newline
  if line.find('*page')+1: res.write('\r\n')
 raw.close()
 res.close()
 print '-> '+file.replace('.ks', '.txt')

Original version is here (Russian). Use discussion page for comments or PM Const2k on B-T forum.