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