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()
path = f[len(prefix):]
data = media.metadata(f, from_)
print(path)
file = File.get_or_create(id, data, path)
item = file.item
if 'primaryid' in file.info:

View file

@ -107,7 +107,13 @@ def info(pdf):
if info:
for key in info:
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()
if xmp:
for key in dir(xmp):
@ -122,7 +128,6 @@ def info(pdf):
data[_key] = value
except:
logger.debug('FAILED TO PARSE %s', pdf, exc_info=1)
'''
cmd = ['pdfinfo', pdf]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)