diff --git a/services/search/pkg/content/tika.go b/services/search/pkg/content/tika.go index 7bcdae426e..abd7bdde39 100644 --- a/services/search/pkg/content/tika.go +++ b/services/search/pkg/content/tika.go @@ -82,7 +82,7 @@ func (t Tika) Extract(ctx context.Context, ri *provider.ResourceInfo) (Document, return doc, err } - var motionPhotoVideo bool + var embeddedVideo bool for _, meta := range metas { title, err := getFirstValue(meta, "dc:title") if err != nil { @@ -119,14 +119,13 @@ func (t Tika) Extract(ctx context.Context, ri *provider.ResourceInfo) (Document, if v := t.getMotionPhoto(meta); v != nil { doc.MotionPhoto = v } - if isMotionPhotoVideo(meta) { - motionPhotoVideo = true + if isVideo(meta) { + embeddedVideo = true } } - // the xmp alone does not prove the video is there, tika emitting it as an - // embedded attachment does - if !motionPhotoVideo { + // the xmp alone does not prove the video is there, tika extracting it does + if !embeddedVideo { doc.MotionPhoto = nil } diff --git a/services/search/pkg/content/tika_motion_photo.go b/services/search/pkg/content/tika_motion_photo.go index 113857bcf0..ced6942be1 100644 --- a/services/search/pkg/content/tika_motion_photo.go +++ b/services/search/pkg/content/tika_motion_photo.go @@ -7,11 +7,6 @@ import ( "strings" ) -// motionPhotoVideoName is the resource name tika gives the appended video when -// it emits it as an embedded attachment. The extension follows the detected -// type and is absent for legacy MicroVideo, which declares no mime type. -const motionPhotoVideoName = "motion-photo" - // getMotionPhoto reads Google Motion Photo XMP, which Tika exposes under the // canonical Camera/Container prefixes. It covers both the current MotionPhoto // scheme and the legacy MicroVideo scheme. videoSize (the embedded video's byte @@ -85,14 +80,11 @@ func motionPhotoVideoSize(meta map[string][]string) (int64, bool) { return 0, false } -// isMotionPhotoVideo reports whether meta describes the video tika extracted -// from a motion photo. Tika only emits it when the bytes the xmp advertises are -// really there, so its presence is what confirms the facet: a shared motion -// photo can keep the xmp and lose the appended video. -func isMotionPhotoVideo(meta map[string][]string) bool { - name, err := getFirstValue(meta, "tk:resource-name") - if err != nil { - return false - } - return name == motionPhotoVideoName || strings.HasPrefix(name, motionPhotoVideoName+".") +// isVideo reports whether meta describes a video. Tika emits the video appended +// to a motion photo as an embedded document, and it only does so when the bytes +// the xmp advertises are really there: a shared motion photo can keep the xmp +// and lose the video. +func isVideo(meta map[string][]string) bool { + v, err := getFirstValue(meta, "Content-Type") + return err == nil && strings.HasPrefix(v, "video/") } diff --git a/services/search/pkg/content/tika_motion_photo_test.go b/services/search/pkg/content/tika_motion_photo_test.go index 97ccbe25d8..62812130d1 100644 --- a/services/search/pkg/content/tika_motion_photo_test.go +++ b/services/search/pkg/content/tika_motion_photo_test.go @@ -77,15 +77,16 @@ var _ = Describe("getMotionPhoto", func() { }) }) -var _ = Describe("isMotionPhotoVideo", func() { - DescribeTable("recognizes the video tika emits as an embedded attachment", +var _ = Describe("isVideo", func() { + DescribeTable("recognizes the video tika extracted from a motion photo", func(meta map[string][]string, expected bool) { - Expect(isMotionPhotoVideo(meta)).To(Equal(expected)) + Expect(isVideo(meta)).To(Equal(expected)) }, - Entry("named attachment", map[string][]string{"tk:resource-name": {"motion-photo.mp4"}}, true), - Entry("no extension, as for MicroVideo", map[string][]string{"tk:resource-name": {"motion-photo"}}, true), - Entry("another attachment", map[string][]string{"tk:resource-name": {"cover.jpg"}}, false), - Entry("a name that only starts alike", map[string][]string{"tk:resource-name": {"motion-photography.mp4"}}, false), - Entry("the image itself", map[string][]string{"Camera:MotionPhoto": {"1"}}, false), + Entry("mp4", map[string][]string{"Content-Type": {"video/mp4"}}, true), + Entry("quicktime", map[string][]string{"Content-Type": {"video/quicktime"}}, true), + Entry("with parameters", map[string][]string{"Content-Type": {"video/mp4; codecs=avc1"}}, true), + Entry("the image itself", map[string][]string{"Content-Type": {"image/jpeg"}}, false), + Entry("another attachment", map[string][]string{"Content-Type": {"application/pdf"}}, false), + Entry("no content type", map[string][]string{"Camera:MotionPhoto": {"1"}}, false), ) }) diff --git a/services/search/pkg/content/tika_test.go b/services/search/pkg/content/tika_test.go index 154e4798e9..66120a593c 100644 --- a/services/search/pkg/content/tika_test.go +++ b/services/search/pkg/content/tika_test.go @@ -218,7 +218,7 @@ var _ = Describe("Tika", func() { }) It("keeps the motion photo facet when tika emits the video", func() { - fullResponse = `[{"Camera:MotionPhotoVersion": "1", "Container:Directory/Item[2]/Item:Semantic": "MotionPhoto", "Container:Directory/Item[2]/Item:Length": "40"}, {"tk:resource-name": "motion-photo.mp4", "Content-Type": "video/mp4"}]` + fullResponse = `[{"Camera:MotionPhotoVersion": "1", "Container:Directory/Item[2]/Item:Semantic": "MotionPhoto", "Container:Directory/Item[2]/Item:Length": "40"}, {"Content-Type": "video/mp4"}]` doc, err := tika.Extract(context.TODO(), &provider.ResourceInfo{ Type: provider.ResourceType_RESOURCE_TYPE_FILE,