From 6e929c6c900e8a23184bd9272ebe090d49ea0561 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 3 Apr 2025 09:22:53 -0600 Subject: [PATCH] Adding rclone sync with Google Photos --- .gitignore | 1 + index.js | 33 +++++++++++++-- package-lock.json | 104 +++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 + 4 files changed, 135 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d1fd6f2..9f9fbfa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +gallery node_modules output.png diff --git a/index.js b/index.js index a641f41..0db1fae 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,29 @@ +const rclone = require('rclone.js') +const schedule = require('node-schedule') const fs = require('fs') const sharp = require('sharp') const inky = require('@aeroniemi/inky') + const frame = new inky.Impression73() -const folder = '../album/' +const folder = './gallery/' + +var ticker = false var filelist = false +function downloadImgs() { + console.log('Starting download from Google Photos...') + const sync = rclone.sync('gphotos:album/Family Room Photo Frame', folder) + + sync.stdout.on('data', function(data) { + console.log(data.toString()) + }) + + sync.on('exit', function() { + console.log('Synchronized from Google Photos. Loading images...') + loadImgs() + }) +} + function loadImgs() { fs.readdir(folder, (err, files) => { if (err || files.length == 0) { @@ -25,7 +44,7 @@ function displayAlbum() { imgfile = filelist.splice(imgref, 1)[0] console.log('Randomly displaying image ' + (imgref + 1) + ' of ' + (filelist.length + 1) + ' remaining: ' + imgfile) displayImage(imgfile) - setTimeout(displayAlbum, 900000) + ticker = setTimeout(displayAlbum, 1800000) } } @@ -38,4 +57,12 @@ function displayImage(filename) { }) } -loadImgs() +// We start by downloading images. Other functions will be called if this is successful... +downloadImgs() + +// Define a cron-job to restart everything at 1:30am (including a refresh of the album).... +schedule.scheduleJob('0 30 1 * * *', function() { + clearTimeout(ticker) + console.log('Resetting...') + downloadImgs() +}) diff --git a/package-lock.json b/package-lock.json index 7282c84..6b84c51 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,17 @@ { "name": "pictureframe", - "version": "1.0.0", + "version": "0.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pictureframe", - "version": "1.0.0", + "version": "0.0.1", "license": "ISC", "dependencies": { "@aeroniemi/inky": "^0.2.0", + "node-schedule": "^2.1.1", + "rclone.js": "^0.6.6", "sharp": "^0.33.5" } }, @@ -614,6 +616,15 @@ "node": ">= 10" } }, + "node_modules/adm-zip": { + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.16.tgz", + "integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ==", + "license": "MIT", + "engines": { + "node": ">=12.0" + } + }, "node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -695,6 +706,18 @@ "simple-swizzle": "^0.2.2" } }, + "node_modules/cron-parser": { + "version": "4.9.0", + "resolved": "https://registry.npmjs.org/cron-parser/-/cron-parser-4.9.0.tgz", + "integrity": "sha512-p0SaNjrHOnQeR8/VnfGbmg9te2kfyYSQ7Sc/j/6DtPL3JQvKxmjO9TSjNFpujqV3vEYYBvNNvXSxzyksBWAx1Q==", + "license": "MIT", + "dependencies": { + "luxon": "^3.2.1" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/detect-libc": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", @@ -725,12 +748,50 @@ "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==", "license": "MIT" }, + "node_modules/long-timeout": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/long-timeout/-/long-timeout-0.1.1.tgz", + "integrity": "sha512-BFRuQUqc7x2NWxfJBCyUrN8iYUYznzL9JROmRz1gZ6KlOIgmoD+njPVbb+VNn2nGMKggMsK79iUNErillsrx7w==", + "license": "MIT" + }, + "node_modules/luxon": { + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.6.1.tgz", + "integrity": "sha512-tJLxrKJhO2ukZ5z0gyjY1zPh3Rh88Ej9P7jNrZiHMUXHae1yvI2imgOZtL1TO8TW6biMMKfTtAOoEJANgtWBMQ==", + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/mri": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", + "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/nan": { "version": "2.22.2", "resolved": "https://registry.npmjs.org/nan/-/nan-2.22.2.tgz", "integrity": "sha512-DANghxFkS1plDdRsX0X9pm0Z6SJNN6gBdtXfanwoZ8hooC5gosGFSBGRYHUVPz1asKA/kMRqDRdHrluZ61SpBQ==", "license": "MIT" }, + "node_modules/node-schedule": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/node-schedule/-/node-schedule-2.1.1.tgz", + "integrity": "sha512-OXdegQq03OmXEjt2hZP33W2YPs/E5BcFQks46+G2gAxs4gHOIVD1u7EqlYLYSKsaIpyKCK9Gbk0ta1/gjRSMRQ==", + "license": "MIT", + "dependencies": { + "cron-parser": "^4.2.0", + "long-timeout": "0.1.1", + "sorted-array-functions": "^1.3.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/pngjs": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-7.0.0.tgz", @@ -740,6 +801,39 @@ "node": ">=14.19.0" } }, + "node_modules/rclone.js": { + "version": "0.6.6", + "resolved": "https://registry.npmjs.org/rclone.js/-/rclone.js-0.6.6.tgz", + "integrity": "sha512-Dxh34cab/fNjFq5SSm0fYLNkGzG2cQSBy782UW9WwxJCEiVO4cGXkvaXcNlgv817dK8K8PuQ+NHUqSAMMhWujQ==", + "cpu": [ + "arm", + "arm64", + "mips", + "mipsel", + "x32", + "x64" + ], + "hasInstallScript": true, + "license": "MIT", + "os": [ + "darwin", + "freebsd", + "linux", + "openbsd", + "sunos", + "win32" + ], + "dependencies": { + "adm-zip": "^0.5.9", + "mri": "^1.2.0" + }, + "bin": { + "rclone": "bin/rclone.js" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/rpio": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/rpio/-/rpio-2.4.2.tgz", @@ -814,6 +908,12 @@ "is-arrayish": "^0.3.1" } }, + "node_modules/sorted-array-functions": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/sorted-array-functions/-/sorted-array-functions-1.3.0.tgz", + "integrity": "sha512-2sqgzeFlid6N4Z2fUQ1cvFmTOLRi/sEDzSQ0OKYchqgoPmQBVyM3959qYx3fpS6Esef80KjmpgPeEr028dP3OA==", + "license": "MIT" + }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", diff --git a/package.json b/package.json index 48d0698..8149833 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ }, "dependencies": { "@aeroniemi/inky": "^0.2.0", + "node-schedule": "^2.1.1", + "rclone.js": "^0.6.6", "sharp": "^0.33.5" } }