Update to use exiftool

pull/37/head
Varun Patil 2022-08-17 21:45:01 +00:00
parent cb5487065e
commit 0e99d887d8
2 changed files with 34 additions and 8 deletions

View File

@ -4,12 +4,15 @@
## How is this different?
* **📸 Photo and Video Timeline**: Sorts photos by date taken.
* **📸 Photo and Video Timeline**: Sorts photos by date taken, parsed from Exif data.
* **🤔 Quick Recap**: Jump to anywhere in the timeline instantly.
* **🖼️ Albums**: Browse your and shared folders with a similar, efficient timeline.
* **🎦 Slideshow**: View photos from your timeline and albums easily.
## 🚀 Installation
1. ☁ Clone this into your `apps` folder of your Nextcloud.
1. ⚒️ Install `exiftool` (`sudo apt install exiftool`).
1. Run `php ./occ polaroid:index` to generate metadata indices for existing photos.
1. Consider installing the [preview generator](https://github.com/rullzer/previewgenerator) for pre-generating thumbnails.

View File

@ -14,16 +14,39 @@ class Util {
$this->connection = $connection;
}
private static function getExif($data, $field) {
$pipes = [];
$proc = proc_open('exiftool -b -' . $field . ' -', [
0 => array('pipe', 'rb'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
], $pipes);
fwrite($pipes[0], $data);
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
proc_close($proc);
return $stdout;
}
public static function getDateTaken(File $file) {
// Attempt to read exif data
if (in_array($file->getMimeType(), Application::IMAGE_MIMES)) {
$exif = exif_read_data($file->fopen('rb'));
$dt = $exif['DateTimeOriginal'];
// Assume it exists in the first 256 kb of the file
$handle = $file->fopen('rb');
$data = stream_get_contents($handle, 256 * 1024);
fclose($handle);
// Try different formats
$dt = self::getExif($data, 'DateTimeOriginal');
if (empty($dt)) {
$dt = self::getExif($data, 'CreateDate');
}
// Check if found something
if (!empty($dt)) {
$dt = \DateTime::createFromFormat('Y:m:d H:i:s', $dt);
if ($dt) {
$dt = \DateTime::createFromFormat('Y:m:d H:i:s', $dt);
if ($dt) {
return $dt->getTimestamp();
}
return $dt->getTimestamp();
}
}