feat: rofi video menu select

This commit is contained in:
hesam-init 2024-02-26 21:26:26 +03:30
parent e2f226fe6c
commit 39e03203ea
2 changed files with 33 additions and 11 deletions

View file

@ -24,7 +24,7 @@ fi
random_video=${video_files[$RANDOM % ${#video_files[@]}]}
if [[ $(pidof mpvpaper) ]]; then
pkill -f mpvpaper
pkill mpvpaper
fi
mpvpaper -o "loop-file" "*" $random_video

View file

@ -4,26 +4,24 @@ source $HOME/.config/environments/env.sh
dir="$HOME/.config/rofi/wallpaper/type-1"
theme='style-8'
thumbnail_dir="$LIVE_WALLPAPERS_DIR/thumbs"
rofi_cmd() {
rofi -dmenu -theme "${dir}/${theme}.rasi"
}
show_image_preview() {
find "$WALLPAPERS_DIR" -maxdepth 1 -type f \( -iname \*.jpg -o -iname \*.jpeg -o -iname \*.png -o -iname \*.gif \) -exec basename {} \; | while read -r A; do
echo -en "$A\x00icon\x1f$WALLPAPERS_DIR/$A\n"
done
}
show_video_preview() {
find "$LIVE_WALLPAPERS_DIR" -maxdepth 1 -type f \( -iname \*.mp4 \) -exec basename {} \; | while read -r A; do
echo -en "$A\x00icon\x1f$LIVE_WALLPAPERS_DIR/$A\n"
for image in "$WALLPAPERS_DIR"/*.{jpg,jpeg,png,gif}; do
[[ -e $image ]] || continue
filename=$(basename "$image")
echo -en "$filename\x00icon\x1f$WALLPAPERS_DIR/$filename\n"
done
}
set_wallpaper() {
if [ $WALLPAPER_DAEMON == "mpvpaper" ]; then
local wallpaper="$LIVE_WALLPAPERS_DIR/$1"
local base_name=$(basename "$1" .png)
local wallpaper="$LIVE_WALLPAPERS_DIR/$base_name.mp4"
else
local wallpaper="$WALLPAPERS_DIR/$1"
fi
@ -72,14 +70,38 @@ set_wallpaper() {
fi
}
generate_video_thumbnails() {
mkdir -p "$thumbnail_dir"
total_files=$(find "$LIVE_WALLPAPERS_DIR" -maxdepth 1 -type f \( -iname \*.mp4 \) | wc -l)
processed_files=0
shopt -s nullglob
for video in "$LIVE_WALLPAPERS_DIR"/*.mp4; do
thumbnail="$LIVE_WALLPAPERS_DIR/thumbs/$(basename "$video" .mp4).png"
if [ ! -f "$thumbnail" ]; then
dunstify -u low -t 1000 "Thumbnail Generation"
sleep 1 && ffmpeg -ss 00:00:02 -i "$video" -frames:v 1 "$thumbnail"
fi
done
}
show_video_preview() {
for image in "$thumbnail_dir"/*.{jpg,jpeg,png,gif}; do
[[ -e $image ]] || continue
filename=$(basename "$image")
echo -en "$filename\x00icon\x1f$thumbnail_dir/$filename\n"
done
}
if [ $WALLPAPER_DAEMON == "mpvpaper" ]; then
generate_video_thumbnails
choice=$(show_video_preview | rofi_cmd)
else
choice=$(show_image_preview | rofi_cmd)
fi
if [ -n "$choice" ]; then
echo $choice
set_wallpaper "$choice"
else
echo "No wallpaper selected."