Adding rclone sync with Google Photos
This commit is contained in:
33
index.js
33
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()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user