def dfxpconv(filename=str, ckeep=bool): fsrt = open(filename, "r", encoding='utf-8', errors='ignore') srtcont = fsrt.read() fdfxp = open(filename.replace(".srt", ".dfxp"), "wb") # Super Netflix Compatibility # Converter that is used (DFXPWriter) uses a different set of rules # than what Super Netflix (and Netflix) wants. # Doing this will avoid the "M7034" error. # It will also remove any formatting as there is no such thing as formatting # in the Netflix Player. dfxpedit = DFXPWriter().write(SRTReader().read(srtcont)) dfxpedit = dfxpedit.replace( "<tt xml:lang=\"en\" xmlns:=\"http://www.w3.org/ns/ttml\" " "xmlns:tts=\"http://www.w3.org/ns/ttml#styling\">", "<tt xml:lang='en' xmlns='http://www.w3.org/2006/10/ttaf1' " "xmlns:tts='http://www.w3.org/2006/10/ttaf1#style'>") dfxpedit = dfxpedit.replace("<div region=\"bottom\" xml:lang=\"en-US\">", "<div xml:id=\"captions\">") dfxpedit = dfxpedit.replace( "<font face=\"Open Sans Semibold\" size=\"36\">", "") dfxpedit = dfxpedit.replace("</font>", "") dfxpedit = dfxpedit.replace(" region=\"bottom\" style=\"default\"", "") dfxpedit = dfxpedit.replace("<b>", "") dfxpedit = dfxpedit.replace("</b>", "") dfxpedit = dfxpedit.replace("<i>", "") dfxpedit = dfxpedit.replace("</i>", "") dfxpedit = dfxpedit.replace("{\\an8}", "") dfxpedit = dfxpedit.encode('utf-8', errors='replace') fdfxp.write(dfxpedit) fsrt.close() fdfxp.close() if ckeep: return if not ckeep: os.remove(filename) return