From 1e9b93175873bfeaec7a67550d34f93499a882db Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Wed, 19 Apr 2023 13:05:38 +0200 Subject: [PATCH] #598 support for Sony predictive capture as burst --- CHANGELOG.md | 4 ++++ lib/model/entry/extensions/multipage.dart | 12 +++--------- lib/model/settings/settings.dart | 1 + lib/ref/bursts.dart | 22 ++++++++++++++++++++-- test/ref/bursts_test.dart | 19 +++++++++++++++++++ 5 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 test/ref/bursts_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index e474e7a16..1ac202594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added + +- Collection: support for Sony predictive capture as burst + ## [v1.8.5] - 2023-04-18 ### Added diff --git a/lib/model/entry/extensions/multipage.dart b/lib/model/entry/extensions/multipage.dart index 977dd1733..2352b27f0 100644 --- a/lib/model/entry/extensions/multipage.dart +++ b/lib/model/entry/extensions/multipage.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:aves/model/entry/entry.dart'; import 'package:aves/model/multipage.dart'; +import 'package:aves/ref/bursts.dart'; import 'package:aves/ref/mime_types.dart'; import 'package:aves/services/common/services.dart'; import 'package:collection/collection.dart'; @@ -17,15 +18,8 @@ extension ExtraAvesEntryMultipage on AvesEntry { bool get isMotionPhoto => (catalogMetadata?.isMotionPhoto ?? false) || _isMotionPhotoLegacy; String? getBurstKey(List patterns) { - if (filenameWithoutExtension != null) { - for (final pattern in patterns) { - final match = RegExp(pattern).firstMatch(filenameWithoutExtension!); - if (match != null) { - return '$directory/${match.group(1)}'; - } - } - } - return null; + final key = BurstPatterns.getKeyForName(filenameWithoutExtension, patterns); + return key != null ? '$directory/$key' : null; } Future getMultiPageInfo() async { diff --git a/lib/model/settings/settings.dart b/lib/model/settings/settings.dart index 755ca9dbc..78a3a7441 100644 --- a/lib/model/settings/settings.dart +++ b/lib/model/settings/settings.dart @@ -309,6 +309,7 @@ class Settings extends ChangeNotifier { if (videoBackgroundMode == VideoBackgroundMode.pip && !device.supportPictureInPicture) { _set(videoBackgroundModeKey, null); } + collectionBurstPatterns = collectionBurstPatterns.where(BurstPatterns.options.contains).toList(); } // app diff --git a/lib/ref/bursts.dart b/lib/ref/bursts.dart index 727506b8c..51b587664 100644 --- a/lib/ref/bursts.dart +++ b/lib/ref/bursts.dart @@ -1,6 +1,8 @@ class BurstPatterns { - static const samsung = r'^(\d{8}_\d{6})_(\d+)$'; - static const sony = r'^DSC_\d+_BURST(\d{17})(_COVER)?$'; + static const _keyGroupName = 'key'; + + static const samsung = r'^(?\d{8}_\d{6})_(\d+)$'; + static const sony = r'^DSC(PDC)?_\d+_BURST(?\d{17})(_COVER)?$'; static final options = [ BurstPatterns.samsung, @@ -33,6 +35,22 @@ class BurstPatterns { _Manufacturers.samsung: samsung, _Manufacturers.sony: sony, }; + + static String? getKeyForName(String? filename, List patterns) { + if (filename != null) { + for (final pattern in patterns) { + final match = RegExp(pattern).firstMatch(filename); + if (match != null) { + if (match.groupNames.contains(_keyGroupName)) { + return match.namedGroup(_keyGroupName); + } + // fallback to fetching group by index for backward compatibility + return match.group(1); + } + } + } + return null; + } } // values as returned by `DeviceInfoPlugin().androidInfo` diff --git a/test/ref/bursts_test.dart b/test/ref/bursts_test.dart new file mode 100644 index 000000000..6efc1dfc5 --- /dev/null +++ b/test/ref/bursts_test.dart @@ -0,0 +1,19 @@ +import 'package:aves/ref/bursts.dart'; +import 'package:test/test.dart'; + +void main() { + test('Samsung burst', () { + expect(BurstPatterns.getKeyForName('20151021_072800_006', [BurstPatterns.samsung]), '20151021_072800'); + expect(BurstPatterns.getKeyForName('20151021_072800_007', [BurstPatterns.samsung]), '20151021_072800'); + }); + + test('Sony burst', () { + expect(BurstPatterns.getKeyForName('DSC_0006_BURST20151021072800123', [BurstPatterns.sony]), '20151021072800123'); + expect(BurstPatterns.getKeyForName('DSC_0007_BURST20151021072800123', [BurstPatterns.sony]), '20151021072800123'); + }); + + test('Sony predictive capture', () { + expect(BurstPatterns.getKeyForName('DSCPDC_0002_BURST20180619163426901', [BurstPatterns.sony]), '20180619163426901'); + expect(BurstPatterns.getKeyForName('DSCPDC_0003_BURST20180619163426901_COVER', [BurstPatterns.sony]), '20180619163426901'); + }); +}