mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-09-12 21:58:58 -04:00
refactor(search): confirm the motion photo video by type, not by name
This commit is contained in:
1 parent
ae9fd595d9
commit
8aebf80124
4 files changed
+22
-30
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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/")
|
||||
}
|
||||
@@ -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),
|
||||
)
|
||||
})
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user