locations.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const fileHash = require('../../util/backup_filehash')
  2. const apple_timestamp = require('../../util/apple_timestamp')
  3. const PHOTOS_DB = fileHash('Media/PhotoData/Photos.sqlite', 'CameraRollDomain')
  4. module.exports = {
  5. version: 4,
  6. name: 'photos.locations',
  7. description: `List all photo geotag's GPS locations`,
  8. requiresBackup: true,
  9. // Run on a v3 lib / backup object.
  10. run (lib, { backup }) {
  11. return getPhotoLocationHistory(backup)
  12. },
  13. // Manifest fields.
  14. output: {
  15. time: el => el.XFORMATTEDDATESTRING,
  16. latitude: el => el.ZLATITUDE,
  17. longitude: el => el.ZLONGITUDE,
  18. file: el => el.ZFILENAME
  19. }
  20. }
  21. function getPhotoLocationHistory (backup) {
  22. return new Promise((resolve, reject) => {
  23. backup.openDatabase(PHOTOS_DB)
  24. .then(db => {
  25. db.all(`SELECT
  26. ZDATECREATED,
  27. ZLATITUDE,
  28. ZLONGITUDE,
  29. ZFILENAME,
  30. ${apple_timestamp.parse('ZDATECREATED')} AS XFORMATTEDDATESTRING
  31. FROM ZGENERICASSET ORDER BY ZDATECREATED ASC`, function (err, rows) {
  32. if (err) reject(err)
  33. resolve(rows)
  34. })
  35. })
  36. .catch(reject)
  37. })
  38. }