update scripts

This commit is contained in:
2026-02-03 17:10:02 -08:00
committed by sudacode
parent bd6eefe084
commit 35357f1674
2 changed files with 46 additions and 46 deletions

View File

@@ -10,9 +10,9 @@ import sys
import requests import requests
# Configuration
OPENROUTER_API_KEY = os.environ.get("OPENROUTER_API_KEY", "") OPENROUTER_API_KEY = os.environ.get("OPENROUTER_API_KEY", "")
MODEL = os.environ.get("OPENROUTER_MODEL", "google/gemini-2.0-flash-001") # MODEL = os.environ.get("OPENROUTER_MODEL", "google/gemini-2.0-flash-001")
MODEL = os.environ.get("OPENROUTER_MODEL", "openai/gpt-oss-120b:free")
API_URL = "https://openrouter.ai/api/v1/chat/completions" API_URL = "https://openrouter.ai/api/v1/chat/completions"
# Try to load API key from file if not in environment # Try to load API key from file if not in environment

View File

@@ -7,74 +7,74 @@ VIDEO_EXTENSIONS="mkv|mp4|avi|webm|mov|flv|wmv|m4v|ts|m2ts"
# Parse command-line options first # Parse command-line options first
while getopts ":it:" opt; do while getopts ":it:" opt; do
case $opt in case $opt in
i) i)
COMMAND="$COMMAND --profile=immersion" COMMAND="$COMMAND --profile=immersion"
;; ;;
t) t)
THEME="$OPTARG" THEME="$OPTARG"
;; ;;
\?) \?)
echo "Invalid option: -$OPTARG" >&2 echo "Invalid option: -$OPTARG" >&2
exit 1 exit 1
;; ;;
:) :)
echo "Option -$OPTARG requires an argument." >&2 echo "Option -$OPTARG requires an argument." >&2
exit 1 exit 1
;; ;;
esac esac
done done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
find_videos() { find_videos() {
find "$PWD" -maxdepth 1 -type f -regextype posix-extended \ find "$PWD" -maxdepth 1 -type f -regextype posix-extended \
-iregex ".*\.($VIDEO_EXTENSIONS)$" 2>/dev/null | sort -V -iregex ".*\.($VIDEO_EXTENSIONS)$" 2> /dev/null | sort -V
} }
build_rofi_menu() { build_rofi_menu() {
while IFS= read -r video; do while IFS= read -r video; do
[ -z "$video" ] && continue [ -z "$video" ] && continue
local display_name local display_name
display_name=$(basename "$video") display_name=$(basename "$video")
printf '%s\0icon\x1fthumbnail://%s\n' "$display_name" "$video" printf '%s\0icon\x1fthumbnail://%s\n' "$display_name" "$video"
done < <(find_videos) done < <(find_videos)
} }
get_video_thumbnail() { get_video_thumbnail() {
local video="$1" local video="$1"
local thumb_dir="$HOME/.cache/thumbnails/large" local thumb_dir="$HOME/.cache/thumbnails/large"
local video_uri="file://$(realpath "$video")" local video_uri="file://$(realpath "$video")"
local thumb_hash=$(echo -n "$video_uri" | md5sum | cut -d' ' -f1) local thumb_hash=$(echo -n "$video_uri" | md5sum | cut -d' ' -f1)
local thumb_path="$thumb_dir/$thumb_hash.png" local thumb_path="$thumb_dir/$thumb_hash.png"
if [[ -f "$thumb_path" ]]; then if [[ -f "$thumb_path" ]]; then
echo "$thumb_path" echo "$thumb_path"
return 0 return 0
fi fi
local tmp_thumb="/tmp/rmpv-thumb-$$.jpg" local tmp_thumb="/tmp/rmpv-thumb-$$.jpg"
if command -v ffmpegthumbnailer &>/dev/null; then if command -v ffmpegthumbnailer &> /dev/null; then
ffmpegthumbnailer -i "$video" -o "$tmp_thumb" -s 512 -q 5 2>/dev/null && echo "$tmp_thumb" ffmpegthumbnailer -i "$video" -o "$tmp_thumb" -s 512 -q 5 2> /dev/null && echo "$tmp_thumb"
elif command -v ffmpeg &>/dev/null; then elif command -v ffmpeg &> /dev/null; then
ffmpeg -i "$video" -ss 00:00:30 -vframes 1 -vf "scale=512:-1" "$tmp_thumb" 2>/dev/null && echo "$tmp_thumb" ffmpeg -i "$video" -ss 00:00:30 -vframes 1 -vf "scale=512:-1" "$tmp_thumb" 2> /dev/null && echo "$tmp_thumb"
fi fi
} }
selection=$(build_rofi_menu | rofi -dmenu -i -show-icons -theme "$THEME" \ selection=$(build_rofi_menu | rofi -dmenu -i -show-icons -theme "$THEME" \
-theme-str 'listview {columns: 1; lines: 15;} window {width: 88%;}' -p "Choose Video ") -theme-str 'configuration {font: "JetBrainsMono Nerd Font 10";} listview {columns: 1; lines: 15;} window {width: 88%;}' -p "Choose Video ")
if [[ -z "$selection" ]]; then if [[ -z "$selection" ]]; then
echo "No video selected." echo "No video selected."
exit 1 exit 1
fi fi
choice="./$selection" choice="./$selection"
THUMBNAIL_PATH=$(get_video_thumbnail "$choice") THUMBNAIL_PATH=$(get_video_thumbnail "$choice")
if [[ -n "$THUMBNAIL_PATH" && -f "$THUMBNAIL_PATH" ]]; then if [[ -n "$THUMBNAIL_PATH" && -f "$THUMBNAIL_PATH" ]]; then
notify-send -i "$THUMBNAIL_PATH" "Playing Video" "$(basename "$choice")" notify-send -i "$THUMBNAIL_PATH" "Playing Video" "$(basename "$choice")"
else else
notify-send "Playing Video" "$(basename "$choice")" notify-send "Playing Video" "$(basename "$choice")"
fi fi
$COMMAND "$choice" & $COMMAND "$choice" &