mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-27 21:54:17 +01:00
subtitle: python3 fixes
This commit is contained in:
parent
08f47dcbd5
commit
6883f31550
@ -2,7 +2,7 @@ import xml.etree.ElementTree as ET
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from svtplay_dl.log import log
|
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.utils.io import StringIO
|
||||||
from svtplay_dl.output import output
|
from svtplay_dl.output import output
|
||||||
from requests import Session
|
from requests import Session
|
||||||
@ -40,7 +40,7 @@ class subtitle(object):
|
|||||||
def tt(self, subdata):
|
def tt(self, subdata):
|
||||||
i = 1
|
i = 1
|
||||||
data = ""
|
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")
|
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"))
|
plist = list(xml.findall("{http://www.w3.org/2006/10/ttaf1}p"))
|
||||||
for node in plist:
|
for node in plist:
|
||||||
@ -62,8 +62,8 @@ class subtitle(object):
|
|||||||
data = tt_text(node, data)
|
data = tt_text(node, data)
|
||||||
data += "\n"
|
data += "\n"
|
||||||
i += 1
|
i += 1
|
||||||
|
if is_py2:
|
||||||
data = data.encode('utf8')
|
data = data.encode("utf8")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def json(self, subdata):
|
def json(self, subdata):
|
||||||
@ -81,7 +81,7 @@ class subtitle(object):
|
|||||||
return subs
|
return subs
|
||||||
|
|
||||||
def sami(self, subdata):
|
def sami(self, subdata):
|
||||||
tree = ET.XML(subdata)
|
tree = ET.XML(subdata.encode("utf8"))
|
||||||
subt = tree.find("Font")
|
subt = tree.find("Font")
|
||||||
subs = ""
|
subs = ""
|
||||||
n = 0
|
n = 0
|
||||||
@ -97,13 +97,11 @@ class subtitle(object):
|
|||||||
if int(n) > 0:
|
if int(n) > 0:
|
||||||
subs += "%s\n" % i.text
|
subs += "%s\n" % i.text
|
||||||
|
|
||||||
|
if is_py2:
|
||||||
subs = subs.encode('utf8')
|
subs = subs.encode('utf8')
|
||||||
return subs
|
return subs
|
||||||
|
|
||||||
def smi(self, subdata):
|
def smi(self, subdata):
|
||||||
if is_py3:
|
|
||||||
subdata = subdata.decode("latin1")
|
|
||||||
ssubdata = StringIO(subdata)
|
ssubdata = StringIO(subdata)
|
||||||
timea = 0
|
timea = 0
|
||||||
number = 1
|
number = 1
|
||||||
@ -129,7 +127,7 @@ class subtitle(object):
|
|||||||
data = text.group(1)
|
data = text.group(1)
|
||||||
recomp = re.compile(r'\r')
|
recomp = re.compile(r'\r')
|
||||||
text = bad_char.sub('-', recomp.sub('', subs)).replace('"', '"')
|
text = bad_char.sub('-', recomp.sub('', subs)).replace('"', '"')
|
||||||
if is_py3:
|
if is_py2:
|
||||||
return text.encode("utf-8")
|
return text.encode("utf-8")
|
||||||
return text
|
return text
|
||||||
|
|
||||||
@ -176,7 +174,7 @@ class subtitle(object):
|
|||||||
sub = re.sub('<[^>]*>', '', i)
|
sub = re.sub('<[^>]*>', '', i)
|
||||||
srt += sub.lstrip()
|
srt += sub.lstrip()
|
||||||
|
|
||||||
if is_py3:
|
if is_py2:
|
||||||
return srt.encode("utf-8")
|
return srt.encode("utf-8")
|
||||||
return srt
|
return srt
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user