photos: Add bambulab timelapse fetcher
This commit is contained in:
parent
fedc15a1d7
commit
7911bc0d7d
5 changed files with 84 additions and 0 deletions
37
roles/photos/tasks/bambulab-fetch.yaml
Normal file
37
roles/photos/tasks/bambulab-fetch.yaml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
---
|
||||||
|
- name: Install dependencies
|
||||||
|
apt:
|
||||||
|
name: curl
|
||||||
|
|
||||||
|
- name: Install fetch script
|
||||||
|
template:
|
||||||
|
src: bambulab-fetch.sh
|
||||||
|
dest: /opt/bambulab-fetch.sh
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
|
- name: Install service
|
||||||
|
template:
|
||||||
|
src: bambulab-fetch.service
|
||||||
|
dest: /etc/systemd/system/bambulab-fetch.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
notify: daemon reload
|
||||||
|
|
||||||
|
- name: Install timer
|
||||||
|
template:
|
||||||
|
src: bambulab-fetch.timer
|
||||||
|
dest: /etc/systemd/system/bambulab-fetch.timer
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
notify: daemon reload
|
||||||
|
|
||||||
|
- name: Enable timer
|
||||||
|
systemd:
|
||||||
|
name: bambulab-fetch
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
daemon_reload: true
|
|
@ -4,3 +4,6 @@
|
||||||
|
|
||||||
- tags: photos_mqtt
|
- tags: photos_mqtt
|
||||||
import_tasks: photos2mqtt.yaml
|
import_tasks: photos2mqtt.yaml
|
||||||
|
|
||||||
|
- tags: bambulab-fetch
|
||||||
|
import_tasks: bambulab-fetch.yaml
|
||||||
|
|
10
roles/photos/templates/bambulab-fetch.service
Normal file
10
roles/photos/templates/bambulab-fetch.service
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=BambuLab Timelapse Fetcher
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/opt/bambulab-fetch.sh
|
||||||
|
Type=oneshot
|
||||||
|
User=wip
|
||||||
|
Group=wip
|
26
roles/photos/templates/bambulab-fetch.sh
Normal file
26
roles/photos/templates/bambulab-fetch.sh
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
host={{ bambulab_host }}
|
||||||
|
pass={{ bambulab_key }}
|
||||||
|
dir={{ photos_path }}
|
||||||
|
|
||||||
|
files=$(curl -ksl "ftps://bblp:$pass@$host:990/timelapse/" | grep ^video_)
|
||||||
|
|
||||||
|
for file in $files; do
|
||||||
|
# $file is formatted like 'video_2024-06-27_22-50-12.mp4'
|
||||||
|
echo $file
|
||||||
|
|
||||||
|
day=$(echo $file | sed -nr 's/^video_([0-9]+)-([0-9]+)-([0-9]+)_.*/\1\2\3/p')
|
||||||
|
time=$(echo $file | sed -nr 's/^video_[^_]+_([^\.]+)\.mp4/\1/p')
|
||||||
|
ofile="$dir/$day/bambu_timelapse_$time.mp4"
|
||||||
|
echo $ofile
|
||||||
|
|
||||||
|
if [ ! -e "$ofile" ]; then
|
||||||
|
mkdir -p "$(dirname $ofile)"
|
||||||
|
curl -ks "ftps://bblp:$pass@$host:990/timelapse/$file" -o "$ofile"
|
||||||
|
fi
|
||||||
|
done
|
8
roles/photos/templates/bambulab-fetch.timer
Normal file
8
roles/photos/templates/bambulab-fetch.timer
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Run every 15 minutes
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*:5/10
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
Loading…
Add table
Reference in a new issue