mirror of
https://github.com/ksyasuda/dotfiles.git
synced 2025-12-05 02:53:38 -08:00
107 lines
3.2 KiB
Bash
Executable File
107 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
THEME="${THEME:-$HOME/.config/rofi/launchers/type-2/style-2.rasi}"
|
|
THUMBNAIL_PATH="/tmp/rmpv-thumbnail.jpg"
|
|
FONTCONFIG_FILE=$HOME/.config/mpv/mpv-fonts.conf
|
|
COMMAND=mpv
|
|
|
|
# Parse command-line options first
|
|
while getopts ":it:" opt; do
|
|
case $opt in
|
|
i)
|
|
COMMAND="$COMMAND --profile=immersion"
|
|
;;
|
|
t)
|
|
THEME="$OPTARG"
|
|
;;
|
|
\?)
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
exit 1
|
|
;;
|
|
:)
|
|
echo "Option -$OPTARG requires an argument." >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
shift $((OPTIND - 1))
|
|
|
|
generate_thumbnail() {
|
|
local video_file="$1"
|
|
local temp_thumb="/tmp/rmpv-thumbnail-$$.jpg"
|
|
local thumbnail_file="${video_file%.*}.jpg"
|
|
|
|
# Clean up previous thumbnail
|
|
rm -f "$THUMBNAIL_PATH"
|
|
|
|
# Validate input
|
|
if [[ -z "$video_file" ]]; then
|
|
echo "Error: No video file specified" >&2
|
|
return 1
|
|
fi
|
|
|
|
if [[ ! -f "$video_file" ]]; then
|
|
echo "Error: Video file '$video_file' not found" >&2
|
|
return 1
|
|
fi
|
|
|
|
# Check if it's a video file
|
|
if ! file "$video_file" | grep -qE "(video|Video)"; then
|
|
echo "Error: '$video_file' doesn't appear to be a video file" >&2
|
|
return 1
|
|
fi
|
|
|
|
# Generate thumbnail if it doesn't exist
|
|
if [[ ! -f "$thumbnail_file" ]]; then
|
|
echo "Generating thumbnail for $(basename "$video_file")..."
|
|
# Try generating thumbnail side-by-side
|
|
if ! ffmpeg -ss 00:00:01 -i "$video_file" \
|
|
-vf "scale=320:240:force_original_aspect_ratio=decrease,pad=320:240:(ow-iw)/2:(oh-ih)/2" \
|
|
-frames:v 1 \
|
|
-q:v 4 \
|
|
"$thumbnail_file" \
|
|
-loglevel error -y 2>/dev/null; then
|
|
|
|
# Fallback to temp file if side-by-side fails (e.g. read-only fs)
|
|
echo "Warning: Failed to write to $thumbnail_file, trying temp location" >&2
|
|
thumbnail_file="$temp_thumb"
|
|
|
|
if ! ffmpeg -ss 00:00:01 -i "$video_file" \
|
|
-vf "scale=320:240:force_original_aspect_ratio=decrease,pad=320:240:(ow-iw)/2:(oh-ih)/2" \
|
|
-frames:v 1 \
|
|
-q:v 4 \
|
|
"$thumbnail_file" \
|
|
-loglevel error -y 2>/dev/null; then
|
|
echo "Error: Failed to generate thumbnail" >&2
|
|
return 1
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Copy to consistent location for notify-send
|
|
# We use a fixed path so notify-send always finds it
|
|
if cp "$thumbnail_file" "$THUMBNAIL_PATH" 2>/dev/null; then
|
|
echo "Thumbnail ready at: $THUMBNAIL_PATH"
|
|
ls -l "$THUMBNAIL_PATH"
|
|
file "$THUMBNAIL_PATH"
|
|
else
|
|
echo "Error: Failed to copy thumbnail to $THUMBNAIL_PATH" >&2
|
|
fi
|
|
}
|
|
|
|
choice="$(find . -iname "*[.mkv|.mp4]" | sort -h | rofi -dmenu -i -theme "$THEME" -theme-str 'listview {columns: 1; lines: 15;} window {width: 88%;}' -p "Choose Video")"
|
|
if [[ -z "$choice" ]]; then
|
|
echo "No video selected."
|
|
exit 1
|
|
fi
|
|
|
|
generate_thumbnail "$choice"
|
|
if [[ ! -f "$THUMBNAIL_PATH" ]]; then
|
|
echo "Warning: Thumbnail not created, notification will have no icon" >&2
|
|
fi
|
|
notify-send -i "$THUMBNAIL_PATH" "Playing Video" "$(basename "$choice")"
|
|
$COMMAND "$choice" &
|
|
|
|
# vim: ft=sh
|
|
|