ripcd: Use chardet to detect CD-TEXT encoding
parent
5dfd71b2fd
commit
3694f177df
9
ripcd.py
9
ripcd.py
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue