handle utf-16 pdf info

This commit is contained in:
j 2014-11-15 00:57:49 +00:00
parent 89d9ab4f11
commit d722ae004b
2 changed files with 8 additions and 2 deletions

View File

@ -42,6 +42,7 @@ def add_file(id, f, prefix, from_=None):
user = state.user() user = state.user()
path = f[len(prefix):] path = f[len(prefix):]
data = media.metadata(f, from_) data = media.metadata(f, from_)
print(path)
file = File.get_or_create(id, data, path) file = File.get_or_create(id, data, path)
item = file.item item = file.item
if 'primaryid' in file.info: if 'primaryid' in file.info:

View File

@ -107,7 +107,13 @@ def info(pdf):
if info: if info:
for key in info: for key in info:
if info[key]: if info[key]:
data[key[1:].lower()] = info[key] try:
if isinstance(info[key], bytes):
info[key] = info[key].decode('utf-16')
data[key[1:].lower()] = info[key]
except:
pass
xmp = pdfreader.getXmpMetadata() xmp = pdfreader.getXmpMetadata()
if xmp: if xmp:
for key in dir(xmp): for key in dir(xmp):
@ -122,7 +128,6 @@ def info(pdf):
data[_key] = value data[_key] = value
except: except:
logger.debug('FAILED TO PARSE %s', pdf, exc_info=1) logger.debug('FAILED TO PARSE %s', pdf, exc_info=1)
''' '''
cmd = ['pdfinfo', pdf] cmd = ['pdfinfo', pdf]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)