Adds video background scripts

Jonathan Hodgson 4 years ago
parent 89ee310534
commit 0fbdab9881
  1. 110
      bin/.bin/background
  2. 84
      bin/.bin/randomVideoFrame

@ -0,0 +1,110 @@
#!/usr/bin/env bash
NOTIFY="FALSE"
# The download script will append an extention
file="/tmp/background"
function notification(){
notify-send "$( jq -r '.name' /tmp/backgroundinfo.json)"
}
function get_random_earth_slug(){
curl -s "https://earthview.withgoogle.com/" | hq 'a.intro__explore' attr href
}
function download_earth_image(){
local slug=$(get_random_earth_slug)
file="$file.jpg"
curl -s "https://earthview.withgoogle.com/_api${slug}.json" > /tmp/backgroundinfo.json
image=$( jq -r '.photoUrl' /tmp/backgroundinfo.json )
curl -s -o "$file" "$image"
}
function get_film_image(){
videoFolder="$HOME/Videos/wallpaper-candidates/"
file="$file.png"
args=()
while [[ "$1" == "--"* ]]; do
case "$1" in
"--effect")
args+=("--effect")
shift
;;
*)
echo "Unknown option $1"
shift
esac
done
if [ -f "$1" ]; then
randomVideoFrame -o "$file" "$1"
else
if [ -d "$1" ]; then
videoFolder="$1"
elif [ -d "${videoFolder}$1" ]; then
videoFolder="${videoFolder}$1"
fi
find -L "$videoFolder" -type f \( -name "*.mp4" -o -name "*.mkv" -o -name "*.avi" \) | multigrep "$@"| shuf | head -n 1 | xargs randomVideoFrame "${args[@]}" -o "$file"
fi
}
function set_background(){
if command -v nitrogen > /dev/null; then
nitrogen --set-zoom-fill "$file"
elif command -v nitrogen > /dev/null; then
feh --bg-fill "$file"
else
echo "No wallpaper tools found"
fi
if [ "$NOTIFY" == "TRUE" ]; then
notification
fi
}
function rand(){
case "$( seq 1 2 | shuf | head -n 1)" in
"1")
download_earth_image
set_background
;;
"2")
get_film_image
set_background
;;
esac
}
while [ -n "$1" ]; do
case "$1" in
"--notify")
NOTIFY="TRUE"
shift
;;
"--only-notify")
notification
shift
exit 0
;;
"--earth")
download_earth_image
set_background
shift
exit 0
;;
"--film")
shift
get_film_image "$@"
set_background
exit 0
;;
"--random")
rand
exit 0
;;
*)
echo "Hopefully don't get here"
shift
exit 1
esac
done
set_image

@ -0,0 +1,84 @@
#!/usr/bin/env bash
# Largely taken from here: https://gitlab.com/uoou/dotfiles/-/blob/master/stow/bin/home/drew/bin/movwp_halftone
# However, changed to have options and to remove credits (hopefully)
output="/tmp/frame.png"
file=""
EFFECT="FALSE"
while [ -n "$1" ]; do
case "$1" in
"-o"|"--output")
output="$2"
shift
shift
;;
"--effect")
EFFECT="TRUE"
shift
;;
*)
if [ -z "$file" ]; then
file="$1"
shift
else
echo "Too many arguments"
exit 1
fi
;;
esac
done
if [ -z "$file" ]; then
echo "You need to specify a file"
exit 1
fi
if [ ! -f "$file" ]; then
echo "$file is not a file"
exit 1
fi
output="${output%.png}.png"
# Uses ffmpeg to get the duration
duration=$(ffmpeg -i "$file" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,)
seconds=$(echo "$duration" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
seconds=${seconds%.*}
if [ "$seconds" -le 0 ];then
echo "Doesn't appear to be a video"
exit 1
fi
if [[ "$seconds" -gt $(( 50 * 60 )) ]]; then
# If the video is more than 50 minutes log, assume it is a film and ignore 5 minutes at the end (credits)
seconds="$(($seconds - 300 ))"
elif [[ "$seconds" -gt $(( 10 * 60 )) ]]; then
# If the video is more than 10 minutes log, assume it is a tv episode and ignore 1 minute at the end (credits)
seconds="$(($seconds - 60 ))"
fi
randpoint=$((1 + RANDOM % "$seconds"))
if [ "$EFFECT" == "TRUE" ]; then
echo "I lastly get here"
ffmpeg -ss "$randpoint" -i "$file" -vf hue=h=310:s=2.8:b=3,eq=contrast=4 -vframes 1 "$output" -y >> /dev/null 2>&1 &&
convert "$output" \
-set option:distort:viewport '%wx%h+0+0' \
-colorspace CMYK -separate null: \
\( -size 3x3 xc: \( +clone -negate \) \
+append \( +clone -negate \) -append \) \
-virtual-pixel tile -filter gaussian \
\( +clone -distort SRT 60 \) +swap \
\( +clone -distort SRT 30 \) +swap \
\( +clone -distort SRT 45 \) +swap \
\( +clone -fill black -colorize 100 -distort SRT 0 \) +swap +delete \
-compose Overlay -layers composite \
-set colorspace CMYK -combine -colorspace RGB \
"$output" &&
convert "$output" \
-virtual-pixel edge -channel M -fx "p[-5,-1]" \
"$output"
else
ffmpeg -ss "$randpoint" -i "$file" -vframes 1 "$output" -y >> /dev/null 2>&1
fi
Loading…
Cancel
Save