From 3694f177df89f4d25c7ec98a677a2aad4dcfdc53 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 10 Jul 2016 17:25:52 -0500 Subject: [PATCH] ripcd: Use chardet to detect CD-TEXT encoding --- ripcd.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ripcd.py b/ripcd.py index b95f8ba..68ffefd 100755 --- a/ripcd.py +++ b/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: