1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00

subtitle: python3 fixes

This commit is contained in:
Johan Andersson 2015-08-31 23:19:01 +02:00
parent 08f47dcbd5
commit 6883f31550

View File

@ -2,7 +2,7 @@ import xml.etree.ElementTree as ET
import json
import re
from svtplay_dl.log import log
from svtplay_dl.utils import is_py2, is_py3
from svtplay_dl.utils import is_py2
from svtplay_dl.utils.io import StringIO
from svtplay_dl.output import output
from requests import Session
@ -40,7 +40,7 @@ class subtitle(object):
def tt(self, subdata):
i = 1
data = ""
tree = ET.ElementTree(ET.fromstring(subdata))
tree = ET.XML(subdata.encode("utf8"))
xml = tree.find("{http://www.w3.org/2006/10/ttaf1}body").find("{http://www.w3.org/2006/10/ttaf1}div")
plist = list(xml.findall("{http://www.w3.org/2006/10/ttaf1}p"))
for node in plist:
@ -62,8 +62,8 @@ class subtitle(object):
data = tt_text(node, data)
data += "\n"
i += 1
data = data.encode('utf8')
if is_py2:
data = data.encode("utf8")
return data
def json(self, subdata):
@ -81,7 +81,7 @@ class subtitle(object):
return subs
def sami(self, subdata):
tree = ET.XML(subdata)
tree = ET.XML(subdata.encode("utf8"))
subt = tree.find("Font")
subs = ""
n = 0
@ -97,13 +97,11 @@ class subtitle(object):
if int(n) > 0:
subs += "%s\n" % i.text
subs = subs.encode('utf8')
if is_py2:
subs = subs.encode('utf8')
return subs
def smi(self, subdata):
if is_py3:
subdata = subdata.decode("latin1")
ssubdata = StringIO(subdata)
timea = 0
number = 1
@ -129,7 +127,7 @@ class subtitle(object):
data = text.group(1)
recomp = re.compile(r'\r')
text = bad_char.sub('-', recomp.sub('', subs)).replace('"', '"')
if is_py3:
if is_py2:
return text.encode("utf-8")
return text
@ -176,7 +174,7 @@ class subtitle(object):
sub = re.sub('<[^>]*>', '', i)
srt += sub.lstrip()
if is_py3:
if is_py2:
return srt.encode("utf-8")
return srt