def getJpegInfo(path): """ @summary: Gets jpeg information. @return: Tuple with exif info, exif2 info and comments. """ try: infoExif = jpeg.getExif(path) __log__.debug("Gets EXIF information %s" % infoExif) except Exception: __log__.warning("It could not get EXIF information from %s" % path) infoExif = None try: infoExif2 = jpeg.getExif2(path) __log__.debug("Gets EXIF2 information %s" % infoExif2) except Exception: __log__.warning("It could not get EXIF2 information from %s" % path) infoExif2 = None try: infoComments = jpeg.getComments(path) __log__.debug("Gets comments %s" % infoComments) except Exception: __log__.warning("It could not get comments information from %s" % path) infoComments = None return (infoExif, infoExif2, infoComments)
def save( self ): """Writes metadata out to photo comments.""" # load existing comments c = jpeg.getComments( self.fname ) # Find previous metadata and get comments that precede and follow # our metadata (so we don't nuke somebody else's comments). before = '' after = '' i = c.find( BEGIN_TAG ) if i == -1: # No previous tags before = c else: # Get before before = c[:i] # And get after i = c.find( END_TAG ) assert i != -1, "Bad metadata" after = c[i+len( END_TAG ):] # Generate metadata block meta = BEGIN_TAG for ( name, value ) in self.items(): meta = '%s<%s>%s</%s>' % ( meta, name, value, name ) meta = '%s%s' % ( meta, END_TAG ) # Write comments back out jpeg.setComments( '%s%s%s' % ( before, meta, after ), self.fname )
def pipp_jpeg_comment(context, src): ctx = context.processor.extensionParams[(NAMESPACE, 'context')] src = ctx.abs_in_path(Conversions.StringValue(src)) ctx.add_depends(src[len(ctx.in_root):]) return jpeg.getComments(src)
def _load( self ): """Loads photo metadata from file comments.""" # load comments from file c = jpeg.getComments( self.fname ) # look for our semaphore i = c.find( BEGIN_TAG ) if i == -1: # if it is not present, then we haven't tagged this file yet return # start parsing after semaphore i += len( BEGIN_TAG ) state = STATE_SCANNING tagname = None iTagname = -1 iTagbody = -1 closingTag = None while(True): if state==STATE_SCANNING: # Check for begin of tag name if c[i] == '<': # Check for end of tags if c[i:i+len(END_TAG)] == END_TAG: break # Start parsing tag name state = STATE_INTAGNAME iTagname = i+1 # else ignore i += 1 elif state==STATE_INTAGNAME: # Check for end of tag name if c[i] == '>': # Get tag name tagname = c[iTagname:i] closingTag = '</%s>' % tagname # Start parsing tag body state = STATE_INTAGBODY iTagbody = i+1 # else just keep trucking on the tag name i += 1 elif state==STATE_INTAGBODY: # Check for closing tag if c[i:i+len(closingTag)] == closingTag: # Store tag in metadata tagbody = c[iTagbody:i] tagbody = COMMENT_RE.sub('', tagbody) self[tagname] = tagbody state = STATE_SCANNING i += len(closingTag) # else keep on trucking on tag body else: i += 1 assert i < len(c), "Bad metadata" # In old metadata, absence of 'published' attribute was equivalent # to published == False if not 'published' in self: self['published'] = 'False'