func mergeImage(old_img *store.Item, new_img *store.Item) *store.Item { if old_img != nil { if len(new_img.Keywords) == 0 { // Did not find keywords in the image, use old ones, but filter some. for _, kwd := range old_img.Keywords { kwd = strings.Replace(kwd, "\n", "", -1) if len(kwd) > 0 { new_img.Keywords = append(new_img.Keywords, kwd) } } } if new_img.ItemTimestamp == nil { // Did not find item timestamp in image, use old one. new_img.ItemTimestamp = old_img.ItemTimestamp } if old_img.Image != nil { if old_img.Image.Stereo != nil { new_img.Image.Stereo = old_img.Image.Stereo } if old_img.Image.RotateDegrees != nil { new_img.Image.RotateDegrees = old_img.Image.RotateDegrees } if old_img.Image.Height != nil { new_img.Image.Height = old_img.Image.Height } if old_img.Image.Width != nil { new_img.Image.Width = old_img.Image.Width } } } return new_img }
func mergeVideo(old_vid *store.Item, new_vid *store.Item) *store.Item { if old_vid != nil { new_vid.Keywords = old_vid.Keywords new_vid.ItemTimestamp = old_vid.ItemTimestamp } return new_vid }
func LoadImageFile(file string, image *store.Item) error { fi, err := os.Open(file) if err != nil { log.Printf("Error: %s\n", err.Error()) return err } defer fi.Close() found_time := false var image_time time.Time ex, err := exif.Decode(bufio.NewReader(fi)) if err == nil { dto, err := tagTime(ex, exif.DateTimeOriginal) if err == nil { image_time = dto found_time = true } if !found_time { dtd, err := tagTime(ex, exif.DateTimeDigitized) if err == nil { log.Printf("Using DateTimeDigitized for: %s (%s)\n", file, dtd) image_time = dtd found_time = true } } if !found_time { dt, err := tagTime(ex, exif.DateTime) if err == nil { log.Printf("Using DateTime for: %s (%s)\n", file, dt) image_time = dt found_time = true } } } if !found_time { log.Printf("Using file time for: %s\n", file) image_time = ProtoToTime(*image.FileTimestamp) } its := TimeToProto(image_time) image.ItemTimestamp = &its height, width, kwds, err := getImageInfo(file) if err == nil { if kwds != nil && len(kwds) > 0 { image.Keywords = kwds } image.Image = new(store.Image) image.Image.Height = proto.Int32(int32(height)) image.Image.Width = proto.Int32(int32(width)) } else { log.Printf("Info got error %s: %s", file, err.Error()) } return nil }