def consolidate_metadata(info_mi, info):
 try:
  raw = info[u'xmp_metadata'].rstrip()
  if (not raw):
   return info_mi
  xmp_mi = metadata_from_xmp_packet(raw)
 except Exception:
  import traceback
  traceback.print_exc()
  return info_mi
 (info_title, info_authors, info_tags) = ((info_mi.title or _(u'Unknown')), list((info_mi.authors or ())), list((info_mi.tags or ())))
 info_mi.smart_update(xmp_mi, replace_metadata=True)
 prefer_info = False
 if ((u'ModDate' in info) and hasattr(xmp_mi, u'metadata_date')):
  try:
   info_date = parse_date(info[u'ModDate'])
  except Exception:
   pass
  else:
   prefer_info = (info_date > xmp_mi.metadata_date)
 if prefer_info:
  (info_mi.title, info_mi.authors, info_mi.tags) = (info_title, info_authors, info_tags)
 else:
  (info_mi.authors, info_mi.tags) = ((info_authors if xmp_mi.is_null(u'authors') else xmp_mi.authors), (xmp_mi.tags or info_tags))
 return info_mi

def consolidate_metadata ( info_mi , info ) : try : raw = info [ u'xmp_metadata' ] . rstrip ( ) if ( not raw ) : return info_mi xmp_mi = metadata_from_xmp_packet ( raw ) except Exception : import traceback traceback . print_exc ( ) return info_mi ( info_title , info_authors , info_tags ) = ( ( info_mi . title or _ ( u'Unknown' ) ) , list ( ( info_mi . authors or ( ) ) ) , list ( ( info_mi . tags or ( ) ) ) ) info_mi . smart_update ( xmp_mi , replace_metadata = True ) prefer_info = False if ( ( u'ModDate' in info ) and hasattr ( xmp_mi , u'metadata_date' ) ) : try : info_date = parse_date ( info [ u'ModDate' ] ) except Exception : pass else : prefer_info = ( info_date > xmp_mi . metadata_date ) if prefer_info : ( info_mi . title , info_mi . authors , info_mi . tags ) = ( info_title , info_authors , info_tags ) else : ( info_mi . authors , info_mi . tags ) = ( ( info_authors if xmp_mi . is_null ( u'authors' ) else xmp_mi . authors ) , ( xmp_mi . tags or info_tags ) ) return info_mi
when both the pdf info dict and xmp metadata are present .