Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2924,11 +2924,16 @@ def xmltv():
data = f.read()
f.close()

match = re.search('<\?xml.*?encoding="(.*?)"',data,flags=(re.I|re.DOTALL))
match = re.search(r'<\?xml.*?encoding=["\'](.*?)["\']',data,flags=(re.I|re.DOTALL))
if match:
encoding = match.group(1)
else:
chardet_encoding = chardet.detect(data)
# Improve performance by limiting the detection of the encoding
# to the first 50k characters if the XML file is bigger
if len(data) > 50000:
chardet_encoding = chardet.detect(data[:50000])
else:
chardet_encoding = chardet.detect(data)
encoding = chardet_encoding['encoding']
data = data.decode(encoding)

Expand Down Expand Up @@ -3013,11 +3018,16 @@ def xmltv():
data = f.read()
f.close()

match = re.search('<\?xml.*?encoding="(.*?)"',data,flags=(re.I|re.DOTALL))
match = re.search(r'<\?xml.*?encoding=["\'](.*?)["\']',data,flags=(re.I|re.DOTALL))
if match:
encoding = match.group(1)
else:
chardet_encoding = chardet.detect(data)
# Improve performance by limiting the detection of the encoding
# to the first 50k characters if the XML file is bigger
if len(data) > 50000:
chardet_encoding = chardet.detect(data[:50000])
else:
chardet_encoding = chardet.detect(data)
encoding = chardet_encoding['encoding']
data = data.decode(encoding)

Expand Down