diff --git a/CHANGELOG.md b/CHANGELOG.md index 38a404d..253aa07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.0.6 +* Fixed invalid motion photo detection for Motion photo Top Shot. + ## 0.0.5 * Fixed invalid motion photo detection for Pixel Pro 8. diff --git a/assets/pixel_6_small_video.jpg b/assets/pixel_6_small_video.jpg new file mode 100644 index 0000000..b82dca4 Binary files /dev/null and b/assets/pixel_6_small_video.jpg differ diff --git a/example/pubspec.lock b/example/pubspec.lock index c954baf..f27780d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -166,7 +166,7 @@ packages: path: ".." relative: true source: path - version: "0.0.3" + version: "0.0.5" path: dependency: transitive description: diff --git a/lib/src/constants.dart b/lib/src/constants.dart index 80c397a..ac06b2d 100644 --- a/lib/src/constants.dart +++ b/lib/src/constants.dart @@ -9,6 +9,8 @@ class MotionPhotoConstants { ]; static String itemLengthOffsetKey = 'Item:Length'; + static String GCameraMotionPhoto = 'GCamera:MotionPhoto'; + static String ItemMimeType = 'Item:MimeType'; ///[fileOffsetKeys] XMP Key for a Motion Photo Video Offset static List fileOffsetKeys = [ diff --git a/lib/src/helpers.dart b/lib/src/helpers.dart index b3783f5..766371f 100644 --- a/lib/src/helpers.dart +++ b/lib/src/helpers.dart @@ -18,7 +18,8 @@ class MotionPhotoHelpers { if (xmpData.containsKey(offSetKey)) { final offsetFromEnd = int.parse(xmpData[offSetKey]); if (offSetKey == MotionPhotoConstants.itemLengthOffsetKey) { - if (offsetFromEnd + offsetFromEnd < size) { + if (offsetFromEnd + offsetFromEnd < size && + !hasMotionPhotoTags(xmpData)) { log('Found ${MotionPhotoConstants.itemLengthOffsetKey} but video length looks invalid'); continue; } @@ -31,4 +32,16 @@ class MotionPhotoHelpers { } return null; } + + static bool hasMotionPhotoTags(Map xmpData) { + if (xmpData.containsKey(MotionPhotoConstants.GCameraMotionPhoto)) { + return true; + } + if (xmpData.containsKey(MotionPhotoConstants.ItemMimeType)) { + return xmpData[MotionPhotoConstants.ItemMimeType] + .toString() + .startsWith('video'); + } + return false; + } } diff --git a/pubspec.yaml b/pubspec.yaml index 5b72618..a44e6c3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: motion_photos description: A Flutter package for detecting and extracting motionphotos from a image file. -version: 0.0.5 +version: 0.0.6 homepage: https://ente.io environment: diff --git a/test/motion_photos_test.dart b/test/motion_photos_test.dart index bb4369e..14ea1b0 100644 --- a/test/motion_photos_test.dart +++ b/test/motion_photos_test.dart @@ -15,6 +15,12 @@ void main() { expect(await motionPhotos.isMotionPhoto(), true); }); + // https://github.com/ente-io/photos-app/issues/1551 + test('Pixel 6 Top shot', () async { + final motionPhotos = MotionPhotos('assets/pixel_6_small_video.jpg'); + expect(await motionPhotos.isMotionPhoto(), true); + }); + test('Not a MotionPhoto', () async { final motionPhotos = MotionPhotos('assets/normalphoto.jpg'); expect(await motionPhotos.isMotionPhoto(), false);