Skip to content

Raspberry Pi (offline)

Alex edited this page Mar 5, 2021 · 2 revisions

This article may be outdated

Copy new videos from one directory to another, deleting old videos to make room.

Example scenario

  1. A Pi is running jwb-offline, and has no internet.
  2. On a computer with internet, download videos with jwb-index to a USB stick.
    • Videos must be stored in the root directory of the USB stick.
    • Filenames must end with ".mp4".
  3. Now plug the USB stick into the Pi. The Pi will automatically
    • Stop playback of videos
    • Copy videos from the USB to the Pi
    • Delete old videos to make room for newer
    • Unmount the USB once finished
    • Resume playback

Example setup

To auto start the import, we use devmon (found in the udevil package). In Debian, udevil pulls down Zenity and GTK3, which you probably don't want. To circumvent this, run:

sudo apt-get install --no-install-recommends udevil pmount udisks2

Now create the script that will be run by devmon every time you plug in a USB.

In this example the user is pi and the videos are saved to /home/pi/jwb. Tweak it to suit your needs.

/usr/local/bin/jwb-auto-import

#!/bin/bash
# Args: DEVICE

# Set username and video directory here (no space in filename please)
user = pi
destination = /home/pi/jwb

mount "$1" /mnt
if [[ $(echo /mnt/*.mp4) = "/mnt/*.mp4" ]]; then
    # No videos found
    umount /mnt
    exit 0
fi
# Output everything to TTY
exec &>/dev/tty0
# Clear and wake up screen
clear; echo -e '\e[9;100]'
# Stop video playback so we can see
systemctl stop jwb-offline
# Import, unmount, play
su -c "jwb-offline-import --free 100 /mnt $destination" "$user"
umount /mnt
systemctl start jwb-offline
# Set screen timeout to 1 min
echo -e '\e[9;1]'

Create the service file that will start devmon.

/etc/systemd/system/jwb-auto-import.service

[Unit]
Description=Auto import JW videos

[Service]
ExecStart=/usr/bin/devmon --exec-on-drive "/usr/local/bin/jwb-auto-import %%f" --no-gui --no-mount

[Install]
WantedBy=multi-user.target

Enable and start the service

sudo systemctl enable jwb-auto-import
sudo systemctl start jwb-auto-import
Clone this wiki locally