In short, during conversion of an srt file, I use the codecs module with an open command
Code is:
with codecs.open(myFile + '.tmpPlex', "w", "utf-8") as targetFile:
However, on Windows, I get hit by the fact, that the codecs module only takes two parameters!?
And takers, and do either give me a hint here, or even better, fork and fix, and help me in this walk up the hill, making Plex the next best thing since sliced bread
I looks like it actually bugs out on opening the file to read. Seems like it might be a bug in Plex itself.
codecs.py is calling __builtin__.open with 3 arguments and not 2.
File "C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-ins\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api\agentkit.py", line 970, in _update
agent.update(obj, media, lang, force)
File "C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-ins\SRT2UTF-8.bundle\Contents\Code\__init__.py", line 37, in update
FindSRT(part)
File "C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-ins\SRT2UTF-8.bundle\Contents\Code\__init__.py", line 78, in FindSRT
GetEnc(sSource)
File "C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-ins\SRT2UTF-8.bundle\Contents\Code\__init__.py", line 93, in GetEnc
ConvertFile(myFile, soup.originalEncoding)
File "C:\Users\Administrator\AppData\Local\Plex Media Server\Plug-ins\SRT2UTF-8.bundle\Contents\Code\__init__.py", line 113, in ConvertFile
with codecs.open(myFile, 'r') as sourceFile:
File "C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\codecs.py", line 881, in open
file = __builtin__.open(filename, mode, buffering)
TypeError: builtins_open() takes at most 2 arguments (3 given)
First a bug in GetEnc you didn't close the file. So, insert the following at line 89:
f.close()
I rewrote ConvertFile to use io.open instead of codecs.open. I think codecs.open may be better, but obviously won't work in Windows. This at least does work on Windows and Linux.
def ConvertFile(myFile, enc):
Log.Debug('Converting file %s with an encoding of %s' %(myFile, enc))
sourceFile = io.open(myFile, 'r', encoding=enc)
targetFile = io.open(myFile + '.tmpPlex', 'w', encoding="utf-8")
while True:
contents = sourceFile.read()
if not contents:
break
targetFile.write(contents)
sourceFile.close()
targetFile.close()
# Remove the original file
os.remove(myFile)
# Name tmp file as the original file name
os.rename(myFile + '.tmpPlex', myFile)
Log.Debug('Successfully converted %s to utf-8' %(myFile))