-
-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add iOS Live Photo support and another format for guess_extractor #224
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,12 @@ final _commonDatetimePatterns = [ | |
r'(?<date>(20|19|18)\d{2}_(01|02|03|04|05|06|07|08|09|10|11|12)_[0-3]\d_\d{2}_\d{2}_\d{2})'), | ||
'YYYY_MM_DD_hh_mm_ss', | ||
], | ||
// example: 20190620_184109.jpg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this format of photos when going through my old photos |
||
[ | ||
RegExp( | ||
r'(20|19|18)\d{2}(01|02|03|04|05|06|07|08|09|10|11|12)[0-3]\d_\d{6}'), | ||
'YYYYMMDD_hhmmss' | ||
] | ||
]; | ||
|
||
/// Guesses DateTime from [file]s name | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'dart:io'; | ||
import 'package:gpth/date_extractors/json_extractor.dart'; | ||
import "package:path/path.dart" as p; | ||
|
||
/// Finds corresponding json file with info and gets 'photoTakenTime' from it | ||
Future<DateTime?> heicVideoExtractor(File file, {bool tryhard = false}) async { | ||
final fileNameWithoutExtension = p.basenameWithoutExtension(file.path); | ||
|
||
if (fileNameWithoutExtension.startsWith("IMG") && | ||
p.extension(file.path).toLowerCase() == ".mp4") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Photo from iPhone with Live Photo enabled when uploading to Google Photos will create three files:
The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that it doesn't always start with IMG, for example, one of mine is like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I too see other files. Perhaps instead try to probe whether the img file exists next to it by doing an |
||
final String parentPath = file.parent.path; | ||
// Is a valid iOS Live Photo video | ||
return tryGetDateTimeFromPossibleFileExtensions( | ||
parentPath, fileNameWithoutExtension); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
Future<DateTime?> tryGetDateTimeFromPossibleFileExtensions( | ||
String parentPath, String fileNameWithoutExtension, | ||
{bool tryhard = false}) async { | ||
final possibleFileExtensions = <String>[ | ||
"HEIC", | ||
"heic", | ||
"JPG", | ||
"jpg", | ||
"JPEG", | ||
"jpeg" | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have come across a few situations when the original image in the live photo pair is saved as a Sample directory of the files:
and...
|
||
|
||
for (final fileExtension in possibleFileExtensions) { | ||
final String possiblePhotoPath = | ||
p.join(parentPath, "$fileNameWithoutExtension.$fileExtension"); | ||
final result = | ||
await jsonExtractor(File(possiblePhotoPath), tryhard: tryhard); | ||
|
||
if (result != null) { | ||
return result; | ||
} | ||
} | ||
|
||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this extractor perhaps come before the
guessExtractor
? If it exits quickly when conditions are not met, it should be safe.