Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Use Images from Google Photos album as screensaver on Linux

Introduction

I wanted to set up a (shared) Google Photos album as my screensaver on Devuan GNU/Linux. I accomplished this with the venerable xscreensaver and a useful tool named rclone which I was already using.

Downloading images from Google Photos

On my CentOS 7 server, I already am using rclone. Starting with version 1.49, rclone supports Google Photos. EPEL provides rclone but only version 1.47. So download the upstream rpm release: Downloads page or direct link. The utility comes with a cli-based configurator. Use rclone config and add a remote. I failed to save the output of when I configured it, but it's as easy following the prompts to add a Google Photos remote. Choose the headless option, and it will show you a link to open in a browser where you can authenticate to Google Photos and then approve this application to use a token tied to your account. The browser will show you a code you paste back into the configurator. In the end, what matters is that the ~/.config/rclone/rclone.conf includes a section like so:

[photos]
type = google photos
read_only = true
token = {"access_token":"za29.a0AfH6SMC9bVDgJTPZTPfvMd5MyplOehAgldvibfrlmMwOBFUSCATEDuDd6tMuWm13YOryXXpUWP4EkHO-oNoa92I6WN7rzrS4y6hquw3zPFXOayEZv-3uv9_NfYNUyctoBq_OUQ9lrqoH3U7J40crJW2NZ","token_type":"Bearer","refresh_token":"1//013Vdw5CGVJ3zCgZIARAAGAFSNwF-L9IricqZmAio2CqpFJ8nM0OuXmsorNlVHRmX5w_KeIgvwvrxsJl5hJT30jT9ET-9mh612-0","expiry":"2020-05-19T10:49:30.709779985-04:00"}

And then my sync script is this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh
# File: /etc/installed/sync-photos.sh
# Location: storage1:/etc/installed
# Author: bgstack15@gmail.com
# Startdate: 2020-05-19
# Title: Script that Pulls Down Album from Google Drive
# Purpose: Pull photos down for a screensaver for the living room HTPC
# History:
# Usage:
#    in a cron entry:
# References:
#    man rclone(1)
#    https://rclone.org/googlephotos/
# Dependencies:
#    ~/.config/rclone/rclone.conf with a section named "photos"
# Documentation:
#    --dry-run is useful. Sync command runs from left side to right side only.
REMOTE="photos"
INDIR="shared-album/Album Name"
OUTDIR=/mnt/public/Images/google-drive/photos
LOGFILE=/mnt/public/Support/Systems/storage1/var/log/sync-photos/rclone.photos.$( date "+%F" ).log
mkdir -p "$( dirname "${LOGFILE}" )"
PLECHO="$( which plecho 2>&1 || which cat )"
time rclone -v --gphotos-read-only sync "${REMOTE}:${INDIR}" "${OUTDIR}" 2>&1 | "${PLECHO}" | tee -a "${LOGFILE}"

The script itself ran great the first time, and downloaded all images (and videos) from the album. Upon second run though, the task seems stuck. Ah, well, I'll solve that over time. For a cron job to run this daily, add file /etc/cron.d/90_google-photos-sync.cron

# File: /etc/cron.d/90_google-photos-sync.cron
# for google photos album shared by another google user. Save down all images so that HTPC can use them in the screensaver.
45 04 *  *  *  root  /etc/installed/sync-photos.sh 1>/dev/null 2>&1

And as with all good cron jobs, suppress the standard output and standard error and use the job itself to store logs.

Using images in xscreensaver

On my Devuan GNU+Linux home theater PC, I use xscreensaver. To take advantage of a simple slideshow feature, make sure to have package xscreensaver-gl installed. Xscreensaver settings on main tab showing GLSlideshow
selected Select GLSlideshow and option "Only one screen saver." The Tesselimage screensaver was very entertaining when used on personal photos but not all end users agreed with me. Xscreensaver GLSlideshow settings page
showing sliders with useful
settings Adjust sliders as necessary. I found that on the default settings, the slideshow would fade out and back in, on the same photo, about three times, before finally moving on to the next image. So these sliders' positions were successful in always showing a new image on each fadeout, which was also slowed down. On the advanced settings tab of GLSlideshow, the sliders were instantiated as:

glslideshow -root -delay 30081 -duration 10 -pan 10

Xcreensaver settings on the advanced tab showing what directory to pull
random images from And of course, choose the destination directory (nfs mounted in my case) on the advanced settings. For the really hardcore users, some of the relevant .xscreensaver values I could find include:

chooseRandomImages: True
imageDirectory:   /mnt/public/Images/google-drive/photos
mode:    one
selected:       143
programs:                              \
- GL:             glslideshow -root -delay 30081 -duration      \
              10 -pan 10                \n\

It is worth noting that the glslideshow entry is 143 lines below the programs: line.

Extra thoughts

Even though a Google Photos album that is shared might be accessed anonymously, the rclone utility requires an account. Linux – keep it simple.

References

  1. https://rclone.org/docs/
  2. https://rclone.org/googlephotos/
  3. https://www.jwz.org/xscreensaver/faq.html#slideshow

Comments