ripcd: Use chardet to detect CD-TEXT encoding

master
Dustin 2016-07-10 17:25:52 -05:00
parent 5dfd71b2fd
commit 3694f177df
1 changed files with 6 additions and 3 deletions

View File

@ -3,6 +3,7 @@ from lxml import etree
import asyncio
import aiohttp
import argparse
import chardet
import fnmatch
import functools
import glob
@ -25,7 +26,8 @@ class TocProtocol(asyncio.SubprocessProtocol):
self.done = asyncio.Future()
def pipe_data_received(self, fd, data):
for line in data.decode().splitlines():
detected = chardet.detect(data)
for line in data.decode(detected['encoding']).splitlines():
if not line:
continue
if line.startswith('Album title:'):
@ -115,13 +117,14 @@ class Track(object):
basename = os.path.splitext(self.filename)[0]
infname = '{}.inf'.format(basename)
try:
inf = open(infname)
inf = open(infname, 'rb')
except OSError as e:
sys.stderr.write('Could not read track info: {}\n'.format(e))
return
with inf:
for line in inf:
line = line.split('#')[0]
detected = chardet.detect(line)
line = line.decode(detected['encoding']).split('#')[0]
if not line:
continue
try: