Skip to content

Instantly share code, notes, and snippets.

@seigler
Last active April 18, 2019 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seigler/648b52f00c21ba2432df4998ecef80db to your computer and use it in GitHub Desktop.
Save seigler/648b52f00c21ba2432df4998ecef80db to your computer and use it in GitHub Desktop.
Script to watch a movie on a Manjaro KDE wallpaper over the course of a month
#!/bin/bash
if [ -f "$1" ]
then
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
Duration=$(mediainfo --Inform="Video;%Duration%" "$1")
Now=$(date +%s)
BOM=$(date -d "$(date +"%Y-%m-01")" +%s)
EOM=$(date -d "$(date +"%Y-%m-01") + 1 month - 1 second" +%s)
Seek=$(echo "scale=2; $Duration*($Now-$BOM)/($EOM-$BOM)/1000" | bc)
mkdir -p /tmp/KSlowMoviePlayer
find /tmp/KSlowMoviePlayer/ -maxdepth 1 -type f -name '*.jpg' -delete
ImageFile=/tmp/KSlowMoviePlayer/$Now.jpg
if [ -f "$1.srt" ]
then
ffmpeg -loglevel panic -ss $Seek -copyts -i "$1" -vf subtitles="$1.srt" -frames:v 1 -c:v mjpeg -q:v 2 -y $ImageFile
else
ffmpeg -loglevel panic -ss $Seek -i "$1" -frames:v 1 -c:v mjpeg -q:v 2 -y $ImageFile
fi
wallpaper_set_script="var allDesktops = desktops();
print (allDesktops)
for (i=0;i<allDesktops.length;i++)
{
d = allDesktops[i];
d.wallpaperPlugin = 'org.kde.image';
d.currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
d.writeConfig('Image', 'file://$ImageFile')
}"
qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "${wallpaper_set_script}"
# Line below changes lockscreen image too
kwriteconfig5 --file kscreenlockerrc --group Greeter --group Wallpaper --group org.kde.image --group General --key Image "file://$ImageFile"
fi
@seigler
Copy link
Author

seigler commented Apr 17, 2019

Create a user cron job with crontab -e, call this script every minute.
* * * * * KSlowMoviePlayer ~/Videos/Wallpaper/*
I call it like this so I can put a different movie in the folder any time.

Dependencies: ffmpeg, bc
Only works in KDE, and distros other than Arch/Manjaro may need to alter the DBUS_SESSION_BUS_ADDRESS line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment