From 8e6546f468904290b291c16deb2485a0366080fe Mon Sep 17 00:00:00 2001 From: aloslider <53711835+aloslider@users.noreply.github.com> Date: Thu, 16 Jul 2026 18:09:08 +0300 Subject: [PATCH] [niri|scripts|zsh] Add more scripts - Move scripts folder - Add discord scripts for niri - Add yt-dlp script --- dot_config/niri/cfg/keybinds.kdl | 4 + dot_config/zsh/dot_zshrc | 3 + .../executable_focus-discord-toggle-deafen.sh | 21 + .../executable_focus-discord-toggle-mute.sh | 21 + .../ffmpeg/executable_compress-video.sh | 461 ++++++++++++++++++ .../ffmpeg/executable_convert-gif-to-mp4.sh | 281 +++++++++++ .../scripts/yt-dlp/executable_download.sh | 4 - .../share/applications/discord-canary.desktop | 11 - 8 files changed, 791 insertions(+), 15 deletions(-) create mode 100644 dot_local/scripts/discord/executable_focus-discord-toggle-deafen.sh create mode 100644 dot_local/scripts/discord/executable_focus-discord-toggle-mute.sh create mode 100644 dot_local/scripts/ffmpeg/executable_compress-video.sh create mode 100644 dot_local/scripts/ffmpeg/executable_convert-gif-to-mp4.sh rename dot_config/zsh/scripts/executable_yt-dlp.sh => dot_local/scripts/yt-dlp/executable_download.sh (97%) delete mode 100644 dot_local/share/applications/discord-canary.desktop diff --git a/dot_config/niri/cfg/keybinds.kdl b/dot_config/niri/cfg/keybinds.kdl index 6c9c0ae..151b68e 100644 --- a/dot_config/niri/cfg/keybinds.kdl +++ b/dot_config/niri/cfg/keybinds.kdl @@ -103,4 +103,8 @@ binds { CTRL+ALT+Delete { quit; } Mod+Shift+P { power-off-monitors; } Mod+O repeat=false { toggle-overview; } + + // --- Discord keybinds dirty trick --- + CTRL+BracketLeft { spawn "~/.local/scripts/discord/focus-discord-toggle-mute.sh"; } + CTRL+BracketRight { spawn "~/.local/scripts/discord/focus-discord-toggle-deafen.sh"; } } diff --git a/dot_config/zsh/dot_zshrc b/dot_config/zsh/dot_zshrc index bd8655c..de0f30f 100644 --- a/dot_config/zsh/dot_zshrc +++ b/dot_config/zsh/dot_zshrc @@ -33,6 +33,9 @@ fi # Aliases alias imgedit=gthumb alias disk=ncdu +alias dl-yt="bash $HOME/.local/scripts/yt-dlp/download.sh" +alias compress-video="bash $HOME/.local/scripts/ffmpeg/compress-video.sh" +alias convert-gif="bash $HOME/.local/scripts/ffmpeg/convert-gif-to-mp4.sh" # lazy lg() { diff --git a/dot_local/scripts/discord/executable_focus-discord-toggle-deafen.sh b/dot_local/scripts/discord/executable_focus-discord-toggle-deafen.sh new file mode 100644 index 0000000..248ded2 --- /dev/null +++ b/dot_local/scripts/discord/executable_focus-discord-toggle-deafen.sh @@ -0,0 +1,21 @@ +#!/bin/sh +APP_NAME="discord-canary" +PREV_ID=$(niri msg focused-window 2>/dev/null | awk ' + /Window ID/ { gsub(":", "", $3); print $3; exit } +') +DISCORD_ID=$(niri msg windows 2>/dev/null | awk -v app="$APP_NAME" ' + /^Window ID/ { id = $3; sub(":", "", id) } + $0 ~ "App ID: \"" app "\"" { print id; exit } +') + +if [ -z "$DISCORD_ID" ]; then + notify-send "Discord not found" "Could not find $APP_NAME window" + exit 1 +fi + +niri msg action focus-window --id "$DISCORD_ID" +wtype -M ctrl -M shift -k d -m shift -m ctrl # default discord keybind + +if [ -n "$PREV_ID" ]; then + niri msg action focus-window --id "$PREV_ID" +fi diff --git a/dot_local/scripts/discord/executable_focus-discord-toggle-mute.sh b/dot_local/scripts/discord/executable_focus-discord-toggle-mute.sh new file mode 100644 index 0000000..2bc1bd9 --- /dev/null +++ b/dot_local/scripts/discord/executable_focus-discord-toggle-mute.sh @@ -0,0 +1,21 @@ +#!/bin/sh +APP_NAME="discord-canary" +PREV_ID=$(niri msg focused-window 2>/dev/null | awk ' + /Window ID/ { gsub(":", "", $3); print $3; exit } +') +DISCORD_ID=$(niri msg windows 2>/dev/null | awk -v app="$APP_NAME" ' + /^Window ID/ { id = $3; sub(":", "", id) } + $0 ~ "App ID: \"" app "\"" { print id; exit } +') + +if [ -z "$DISCORD_ID" ]; then + notify-send "Discord not found" "Could not find $APP_NAME window" + exit 1 +fi + +niri msg action focus-window --id "$DISCORD_ID" +wtype -M ctrl -M shift -k m -m shift -m ctrl # default discord keybind + +if [ -n "$PREV_ID" ]; then + niri msg action focus-window --id "$PREV_ID" +fi diff --git a/dot_local/scripts/ffmpeg/executable_compress-video.sh b/dot_local/scripts/ffmpeg/executable_compress-video.sh new file mode 100644 index 0000000..f5e10bc --- /dev/null +++ b/dot_local/scripts/ffmpeg/executable_compress-video.sh @@ -0,0 +1,461 @@ +#!/usr/bin/env bash + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +RESET='\033[0m' + +if ! command -v ffmpeg &> /dev/null; then + echo -e "${RED}Error: ffmpeg is not installed.${RESET}" + exit 1 +fi + +input="$1" +if [[ -z "$input" ]]; then + echo -e "${RED}Usage: $0 /path/to/video.mp4 [optional_output.mp4_or_.gif]${RESET}" + exit 1 +fi +if [[ ! -f "$input" ]]; then + echo -e "${RED}Error: Input file not found: $input${RESET}" + exit 1 +fi + +is_gif=false +if [[ "$input" == *.gif ]]; then + is_gif=true +fi + +if [[ -n "$2" ]]; then + output_file="$2" + if $is_gif; then + if [[ "$output_file" != *.gif ]]; then output_file="${output_file}.gif"; fi + else + if [[ "$output_file" != *.mp4 ]]; then output_file="${output_file}.mp4"; fi + fi + auto_index=false +else + base=$(basename "$input" | sed 's/\.[^.]*$//') + if $is_gif; then + ext="gif" + else + ext="mp4" + fi + i=0 + while [[ -f "${base}-${i}.${ext}" ]]; do + ((i++)) + done + output_file="${base}-${i}.${ext}" + auto_index=true +fi + +if $is_gif; then + fps=15 + width="" + start_time="" + dur="" + loop_infinite=true + dither="bayer" + bayer_scale=3 + stats_mode="full" +else + codec="libx264" + crf=26 + preset="medium" + audio_bitrate="96k" + fps="" + width="" + start_time="" + dur="" + faststart=true +fi + +function show_current_settings() { + echo -e "${CYAN}Current Settings${RESET}" + if $is_gif; then + echo -e "Input type: ${GREEN}GIF (re-encoding)${RESET}" + echo -e "FPS: ${GREEN}${fps}${RESET}" + echo -e "Scale width: ${GREEN}${width:-keep original}${RESET}" + echo -e "Start time: ${GREEN}${start_time:-from beginning}${RESET}" + echo -e "Duration: ${GREEN}${dur:-to end}${RESET}" + echo -e "Loop: ${GREEN}$(if $loop_infinite; then echo 'infinite'; else echo 'once'; fi)${RESET}" + echo -e "Dither: ${GREEN}${dither}${RESET}" + if [[ "$dither" == "bayer" ]]; then + echo -e "Bayer scale: ${GREEN}${bayer_scale}${RESET}" + fi + else + echo -e "Input type: ${GREEN}Video${RESET}" + echo -e "Codec: ${GREEN}${codec}${RESET}" + echo -e "CRF (quality): ${GREEN}${crf}${RESET} (lower = better quality, bigger file)" + echo -e "Preset (speed): ${GREEN}${preset}${RESET} (slow = better compression)" + echo -e "Audio bitrate: ${GREEN}${audio_bitrate}${RESET} (or 'copy' to keep original)" + echo -e "FPS: ${GREEN}${fps:-keep original}${RESET}" + echo -e "Scale width: ${GREEN}${width:-keep original}${RESET}" + echo -e "Start time: ${GREEN}${start_time:-from beginning}${RESET}" + echo -e "Duration: ${GREEN}${dur:-to end}${RESET}" + echo -e "Faststart: ${GREEN}$(if $faststart; then echo 'yes (-movflags +faststart)'; else echo 'no'; fi)${RESET}" + fi + echo -e "Output file: ${GREEN}${output_file}${RESET}" +} + +function build_vf() { + vf="" + if [[ -n "$fps" ]]; then + vf="fps=${fps}" + fi + if [[ -n "$width" ]]; then + if [[ -n "$vf" ]]; then vf+=","; fi + vf+="scale=${width}:-1:flags=lanczos" + fi + echo "$vf" +} + +function build_command_string() { + cmd="ffmpeg -y" + if [[ -n "$start_time" ]]; then + cmd+=" -ss ${start_time}" + fi + cmd+=" -i \"${input}\"" + if [[ -n "$dur" ]]; then + cmd+=" -t ${dur}" + fi + + if $is_gif; then + vf="$(build_vf)" + if [[ -n "$vf" ]]; then + cmd+=" -vf \"${vf},split[s0][s1];[s0]palettegen=stats_mode=${stats_mode}[p];[s1][p]paletteuse=dither=${dither}" + if [[ "$dither" == "bayer" ]]; then + cmd+=":bayer_scale=${bayer_scale}" + fi + cmd+="\"" + else + cmd+=" -vf \"split[s0][s1];[s0]palettegen=stats_mode=${stats_mode}[p];[s1][p]paletteuse=dither=${dither}" + if [[ "$dither" == "bayer" ]]; then + cmd+=":bayer_scale=${bayer_scale}" + fi + cmd+="\"" + fi + if $loop_infinite; then + cmd+=" -loop 0" + else + cmd+=" -loop 1" + fi + else + vf="$(build_vf)" + if [[ -n "$vf" ]]; then + cmd+=" -vf \"$vf\"" + fi + cmd+=" -c:v ${codec} -crf ${crf} -preset ${preset}" + if [[ "$audio_bitrate" == "copy" ]]; then + cmd+=" -c:a copy" + else + cmd+=" -c:a aac -b:a ${audio_bitrate}" + fi + if $faststart; then + cmd+=" -movflags +faststart" + fi + fi + cmd+=" \"${output_file}\"" + echo "$cmd" +} + +function configure_settings() { + while true; do + echo -e "\n${YELLOW}Press Enter to keep default shown in [brackets]. Type new value to change.${RESET}" + echo -e "${CYAN}Configuration${RESET}" + + if $is_gif; then + read -p "FPS [${fps}]: " val + if [[ -n "$val" ]]; then fps="$val"; fi + + read -p "Scale width in px (e.g. 480 or 640, empty=keep): " val + if [[ -n "$val" ]]; then width="$val"; fi + + read -p "Start time (e.g. 00:00:05 or 5, empty=from start): " val + start_time="$val" + + read -p "Duration in sec or HH:MM:SS (empty=to end): " val + dur="$val" + + read -p "Loop infinitely? (y/n) [y]: " val + if [[ "$val" == "n" || "$val" == "N" ]]; then loop_infinite=false; else loop_infinite=true; fi + + read -p "Dither (bayer / floyd_steinberg / none) [bayer]: " val + if [[ -n "$val" ]]; then dither="$val"; fi + + if [[ "$dither" == "bayer" ]]; then + read -p "Bayer scale 1-5 [${bayer_scale}]: " val + if [[ -n "$val" ]]; then bayer_scale="$val"; fi + fi + else + read -p "Codec (libx265 or libx264) [${codec}]: " val + if [[ -n "$val" ]]; then codec="$val"; fi + + read -p "CRF quality [${crf}]: " val + if [[ -n "$val" ]]; then crf="$val"; fi + + read -p "Preset (ultrafast|superfast|veryfast|fast|medium|slow|veryslow) [${preset}]: " val + if [[ -n "$val" ]]; then preset="$val"; fi + + read -p "Audio bitrate in k (e.g. 96k or 128k, or 'copy') [${audio_bitrate}]: " val + if [[ -n "$val" ]]; then audio_bitrate="$val"; fi + + read -p "Target FPS (empty=keep original, e.g. 30): " val + fps="$val" + + read -p "Scale width in px (e.g. 1280, empty=keep original): " val + width="$val" + + read -p "Start time (e.g. 00:00:05 or 5, empty=from start): " val + start_time="$val" + + read -p "Duration in sec or HH:MM:SS (empty=to end): " val + dur="$val" + + read -p "Enable faststart? (y/n) [y]: " val + if [[ "$val" == "n" || "$val" == "N" ]]; then + faststart=false + else + faststart=true + fi + fi + + echo "" + show_current_settings + echo -e "\n${YELLOW}Preview command:${RESET}" + build_command_string + + echo -e "\n${CYAN}Options now:${RESET}" + echo "1) Execute with these settings" + echo "2) Restart configuration from defaults" + echo "3) Change one specific setting" + echo "4) Exit without compressing" + read -p "Your choice [1]: " choice + choice=${choice:-1} + + case $choice in + 1) return 0 ;; + 2) + if $is_gif; then + fps=15 + width="" + start_time="" + dur="" + loop_infinite=true + dither="bayer" + bayer_scale=3 + else + codec="libx264" + crf=26 + preset="medium" + audio_bitrate="96k" + fps="" + width="" + start_time="" + dur="" + faststart=true + fi + ;; + 3) + echo -e "${CYAN}Which setting to change?${RESET}" + if $is_gif; then + echo "a) FPS b) Scale width c) Start time d) Duration e) Loop f) Dither g) Bayer scale" + else + echo "a) Codec b) CRF c) Preset d) Audio bitrate e) FPS f) Scale width" + echo "g) Start time h) Duration i) Faststart (movflags)" + fi + read -p "Letter: " letter + if $is_gif; then + case $letter in + a) read -p "New FPS: " val; [[ -n "$val" ]] && fps="$val" ;; + b) read -p "New width: " val; width="$val" ;; + c) read -p "New start time: " val; start_time="$val" ;; + d) read -p "New duration: " val; dur="$val" ;; + e) if $loop_infinite; then loop_infinite=false; else loop_infinite=true; fi ;; + f) read -p "New dither: " val; [[ -n "$val" ]] && dither="$val" ;; + g) if [[ "$dither" == "bayer" ]]; then read -p "New bayer scale: " val; [[ -n "$val" ]] && bayer_scale="$val"; fi ;; + esac + else + case $letter in + a) read -p "New codec (libx265/libx264): " val; [[ -n "$val" ]] && codec="$val" ;; + b) read -p "New CRF: " val; [[ -n "$val" ]] && crf="$val" ;; + c) read -p "New preset: " val; [[ -n "$val" ]] && preset="$val" ;; + d) read -p "New audio bitrate or 'copy': " val; [[ -n "$val" ]] && audio_bitrate="$val" ;; + e) read -p "New FPS (empty=keep): " val; fps="$val" ;; + f) read -p "New width (empty=keep): " val; width="$val" ;; + g) read -p "New start time: " val; start_time="$val" ;; + h) read -p "New duration: " val; dur="$val" ;; + i) if $faststart; then faststart=false; else faststart=true; fi ;; + esac + fi + ;; + 4) echo -e "${YELLOW}Exiting.${RESET}"; exit 0 ;; + *) ;; + esac + done +} + +configure_settings + +echo -e "\n${GREEN}Starting compression...${RESET}" +echo -e "${YELLOW}Command: $(build_command_string)${RESET}\n" + +cmd_array=(ffmpeg -y) +if [[ -n "$start_time" ]]; then + cmd_array+=(-ss "$start_time") +fi +cmd_array+=(-i "$input") +if [[ -n "$dur" ]]; then + cmd_array+=(-t "$dur") +fi + +if $is_gif; then + vf="$(build_vf)" + if [[ -n "$vf" ]]; then + full_vf="${vf},split[s0][s1];[s0]palettegen=stats_mode=${stats_mode}[p];[s1][p]paletteuse=dither=${dither}" + if [[ "$dither" == "bayer" ]]; then + full_vf+=":bayer_scale=${bayer_scale}" + fi + cmd_array+=(-vf "$full_vf") + else + full_vf="split[s0][s1];[s0]palettegen=stats_mode=${stats_mode}[p];[s1][p]paletteuse=dither=${dither}" + if [[ "$dither" == "bayer" ]]; then + full_vf+=":bayer_scale=${bayer_scale}" + fi + cmd_array+=(-vf "$full_vf") + fi + if $loop_infinite; then + cmd_array+=(-loop 0) + else + cmd_array+=(-loop 1) + fi +else + vf="$(build_vf)" + if [[ -n "$vf" ]]; then + cmd_array+=(-vf "$vf") + fi + cmd_array+=(-c:v "$codec" -crf "$crf" -preset "$preset") + if [[ "$audio_bitrate" == "copy" ]]; then + cmd_array+=(-c:a copy) + else + cmd_array+=(-c:a aac -b:a "$audio_bitrate") + fi + if $faststart; then + cmd_array+=(-movflags +faststart) + fi +fi +cmd_array+=("$output_file") + +"${cmd_array[@]}" + +if [[ -f "$output_file" ]]; then + size=$(du -h "$output_file" | awk '{print $1}') + echo -e "\n${GREEN}✓ Compression finished!${RESET}" + echo -e "File: ${GREEN}${output_file}${RESET}" + echo -e "Size: ${GREEN}${size}${RESET}" +else + echo -e "${RED}Error: Output file was not created.${RESET}" + exit 1 +fi + +while true; do + echo -e "\n${CYAN}Select option:${RESET}" + echo "1) Change settings and create a NEW file (next available index)" + echo "2) Redo with current settings (will overwrite ${output_file})" + echo "q) Exit" + read -p "Choice: " post_choice + + case $post_choice in + 1) + if $auto_index; then + base=$(basename "$output_file" | sed "s/-[0-9]*\.${ext}$//") + i=0 + while [[ -f "${base}-${i}.${ext}" ]]; do + ((i++)) + done + output_file="${base}-${i}.${ext}" + else + base=$(basename "$output_file" | sed "s/\.${ext}$//") + i=0 + while [[ -f "${base}-${i}.${ext}" ]]; do + ((i++)) + done + output_file="${base}-${i}.${ext}" + fi + echo -e "New output file will be: ${YELLOW}${output_file}${RESET}" + configure_settings + echo -e "\n${GREEN}Starting new compression...${RESET}" + cmd_array=(ffmpeg -y) + if [[ -n "$start_time" ]]; then cmd_array+=(-ss "$start_time"); fi + cmd_array+=(-i "$input") + if [[ -n "$dur" ]]; then cmd_array+=(-t "$dur"); fi + if $is_gif; then + vf="$(build_vf)" + if [[ -n "$vf" ]]; then + full_vf="${vf},split[s0][s1];[s0]palettegen=stats_mode=${stats_mode}[p];[s1][p]paletteuse=dither=${dither}" + if [[ "$dither" == "bayer" ]]; then full_vf+=":bayer_scale=${bayer_scale}"; fi + cmd_array+=(-vf "$full_vf") + else + full_vf="split[s0][s1];[s0]palettegen=stats_mode=${stats_mode}[p];[s1][p]paletteuse=dither=${dither}" + if [[ "$dither" == "bayer" ]]; then full_vf+=":bayer_scale=${bayer_scale}"; fi + cmd_array+=(-vf "$full_vf") + fi + if $loop_infinite; then cmd_array+=(-loop 0); else cmd_array+=(-loop 1); fi + else + vf="$(build_vf)" + if [[ -n "$vf" ]]; then cmd_array+=(-vf "$vf"); fi + cmd_array+=(-c:v "$codec" -crf "$crf" -preset "$preset") + if [[ "$audio_bitrate" == "copy" ]]; then cmd_array+=(-c:a copy); else cmd_array+=(-c:a aac -b:a "$audio_bitrate"); fi + if $faststart; then cmd_array+=(-movflags +faststart); fi + fi + cmd_array+=("$output_file") + "${cmd_array[@]}" + if [[ -f "$output_file" ]]; then + size=$(du -h "$output_file" | awk '{print $1}') + echo -e "\n${GREEN}New file created!${RESET} File: ${GREEN}${output_file}${RESET} Size: ${GREEN}${size}${RESET}" + fi + ;; + 2) + echo -e "${YELLOW}Will overwrite ${output_file} on next run.${RESET}" + configure_settings + echo -e "\n${GREEN}Starting compression (overwrite mode)...${RESET}" + cmd_array=(ffmpeg -y) + if [[ -n "$start_time" ]]; then cmd_array+=(-ss "$start_time"); fi + cmd_array+=(-i "$input") + if [[ -n "$dur" ]]; then cmd_array+=(-t "$dur"); fi + if $is_gif; then + vf="$(build_vf)" + if [[ -n "$vf" ]]; then + full_vf="${vf},split[s0][s1];[s0]palettegen=stats_mode=${stats_mode}[p];[s1][p]paletteuse=dither=${dither}" + if [[ "$dither" == "bayer" ]]; then full_vf+=":bayer_scale=${bayer_scale}"; fi + cmd_array+=(-vf "$full_vf") + else + full_vf="split[s0][s1];[s0]palettegen=stats_mode=${stats_mode}[p];[s1][p]paletteuse=dither=${dither}" + if [[ "$dither" == "bayer" ]]; then full_vf+=":bayer_scale=${bayer_scale}"; fi + cmd_array+=(-vf "$full_vf") + fi + if $loop_infinite; then cmd_array+=(-loop 0); else cmd_array+=(-loop 1); fi + else + vf="$(build_vf)" + if [[ -n "$vf" ]]; then cmd_array+=(-vf "$vf"); fi + cmd_array+=(-c:v "$codec" -crf "$crf" -preset "$preset") + if [[ "$audio_bitrate" == "copy" ]]; then cmd_array+=(-c:a copy); else cmd_array+=(-c:a aac -b:a "$audio_bitrate"); fi + if $faststart; then cmd_array+=(-movflags +faststart); fi + fi + cmd_array+=("$output_file") + "${cmd_array[@]}" + if [[ -f "$output_file" ]]; then + size=$(du -h "$output_file" | awk '{print $1}') + echo -e "\n${GREEN}Overwritten!${RESET} File: ${GREEN}${output_file}${RESET} Size: ${GREEN}${size}${RESET}" + fi + ;; + q) + echo -e "${GREEN}Done.${RESET}" + exit 0 + ;; + *) + echo -e "${RED}Invalid choice.${RESET}" + ;; + esac +done + diff --git a/dot_local/scripts/ffmpeg/executable_convert-gif-to-mp4.sh b/dot_local/scripts/ffmpeg/executable_convert-gif-to-mp4.sh new file mode 100644 index 0000000..9aafec0 --- /dev/null +++ b/dot_local/scripts/ffmpeg/executable_convert-gif-to-mp4.sh @@ -0,0 +1,281 @@ +#!/usr/bin/env bash + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +RESET='\033[0m' + +if ! command -v ffmpeg &> /dev/null; then + echo -e "${RED}Error: ffmpeg is not installed.${RESET}" + exit 1 +fi + +input="$1" +if [[ -z "$input" ]]; then + echo -e "${RED}Usage: $0 /path/to/video.mp4 [optional_output.gif]${RESET}" + exit 1 +fi +if [[ ! -f "$input" ]]; then + echo -e "${RED}Error: Input file not found: $input${RESET}" + exit 1 +fi + +if [[ -n "$2" ]]; then + output_file="$2" + if [[ "$output_file" != *.gif ]]; then + output_file="${output_file}.gif" + fi + auto_index=false +else + base=$(basename "$input" | sed 's/\.[^.]*$//') + i=0 + while [[ -f "${base}-${i}.gif" ]]; do + ((i++)) + done + output_file="${base}-${i}.gif" + auto_index=true +fi + +fps=25 +width="" +start_time="" +dur="" +loop_infinite=true +dither="bayer" +bayer_scale=3 +stats_mode="full" + +function show_current_settings() { + echo -e "${CYAN}Current Settings=${RESET}" + echo -e "FPS: ${GREEN}${fps}${RESET}" + echo -e "Scale width: ${GREEN}${width:-keep original}${RESET}" + echo -e "Start time: ${GREEN}${start_time:-from beginning}${RESET}" + echo -e "Duration: ${GREEN}${dur:-to end}${RESET}" + echo -e "Loop: ${GREEN}$(if $loop_infinite; then echo 'infinite (-loop 0)'; else echo 'once (-loop 1)'; fi)${RESET}" + echo -e "Dither: ${GREEN}${dither}${RESET}" + if [[ "$dither" == "bayer" ]]; then + echo -e "Bayer scale: ${GREEN}${bayer_scale}${RESET}" + fi + echo -e "Output file: ${GREEN}${output_file}${RESET}" +} + +function build_vf() { + vf="fps=${fps}" + if [[ -n "$width" ]]; then + vf+=",scale=${width}:-1:flags=lanczos" + fi + vf+=",split[s0][s1];[s0]palettegen=stats_mode=${stats_mode}[p];[s1][p]paletteuse=dither=${dither}" + if [[ "$dither" == "bayer" ]]; then + vf+=":bayer_scale=${bayer_scale}" + fi + echo "$vf" +} + +function build_command_string() { + cmd="ffmpeg -y" + if [[ -n "$start_time" ]]; then + cmd+=" -ss ${start_time}" + fi + cmd+=" -i \"${input}\"" + if [[ -n "$dur" ]]; then + cmd+=" -t ${dur}" + fi + cmd+=" -vf \"$(build_vf)\"" + if $loop_infinite; then + cmd+=" -loop 0" + else + cmd+=" -loop 1" + fi + cmd+=" \"${output_file}\"" + echo "$cmd" +} + +function configure_settings() { + while true; do + echo -e "\n${YELLOW}Press Enter to keep default shown in [brackets]. Type new value to change.${RESET}" + echo -e "${CYAN}Configuration:${RESET}" + + read -p "FPS [${fps}]: " val + if [[ -n "$val" ]]; then fps="$val"; fi + + read -p "Scale width in px (e.g. 640 or 800, empty=keep original): " val + if [[ -n "$val" ]]; then width="$val"; fi + + read -p "Start time (e.g. 00:00:05 or 5, empty=from start): " val + start_time="$val" + + read -p "Duration in sec or HH:MM:SS (empty=to end): " val + dur="$val" + + read -p "Loop infinitely? (y/n) [y]: " val + if [[ "$val" == "n" || "$val" == "N" ]]; then + loop_infinite=false + else + loop_infinite=true + fi + + read -p "Dither method (bayer / floyd_steinberg / none) [bayer]: " val + if [[ -n "$val" ]]; then dither="$val"; fi + + if [[ "$dither" == "bayer" ]]; then + read -p "Bayer scale 1-5 (higher=more dither pattern) [${bayer_scale}]: " val + if [[ -n "$val" ]]; then bayer_scale="$val"; fi + fi + + echo "" + show_current_settings + echo -e "\n${YELLOW}Preview command:${RESET}" + build_command_string + + echo -e "\n${CYAN}Options now:${RESET}" + echo "1) Execute with these settings" + echo "2) Restart configuration from defaults" + echo "3) Change one specific setting" + echo "4) Exit without converting" + read -p "Your choice [1]: " choice + choice=${choice:-1} + + case $choice in + 1) return 0 ;; + 2) + fps=25 + width="" + start_time="" + dur="" + loop_infinite=true + dither="bayer" + bayer_scale=3 + ;; + 3) + echo -e "${CYAN}Which setting to change?${RESET}" + echo "a) FPS" + echo "b) Scale width" + echo "c) Start time" + echo "d) Duration" + echo "e) Loop" + echo "f) Dither method" + echo "g) Bayer scale (if bayer)" + read -p "Letter: " letter + case $letter in + a) read -p "New FPS: " val; [[ -n "$val" ]] && fps="$val" ;; + b) read -p "New width (empty to keep original): " val; width="$val" ;; + c) read -p "New start time: " val; start_time="$val" ;; + d) read -p "New duration: " val; dur="$val" ;; + e) if $loop_infinite; then loop_infinite=false; else loop_infinite=true; fi ;; + f) read -p "New dither (bayer/floyd_steinberg/none): " val; [[ -n "$val" ]] && dither="$val" ;; + g) if [[ "$dither" == "bayer" ]]; then read -p "New bayer scale: " val; [[ -n "$val" ]] && bayer_scale="$val"; fi ;; + esac + ;; + 4) echo -e "${YELLOW}Exiting.${RESET}"; exit 0 ;; + *) ;; + esac + done +} + +configure_settings + +echo -e "\n${GREEN}Starting conversion...${RESET}" +echo -e "${YELLOW}Command: $(build_command_string)${RESET}\n" + +cmd_array=(ffmpeg -y) +if [[ -n "$start_time" ]]; then + cmd_array+=(-ss "$start_time") +fi +cmd_array+=(-i "$input") +if [[ -n "$dur" ]]; then + cmd_array+=(-t "$dur") +fi +vf="$(build_vf)" +cmd_array+=(-vf "$vf") +if $loop_infinite; then + cmd_array+=(-loop 0) +else + cmd_array+=(-loop 1) +fi +cmd_array+=("$output_file") + +"${cmd_array[@]}" + +if [[ -f "$output_file" ]]; then + size=$(du -h "$output_file" | awk '{print $1}') + echo -e "\n${GREEN}✓ Conversion finished!${RESET}" + echo -e "File: ${GREEN}${output_file}${RESET}" + echo -e "Size: ${GREEN}${size}${RESET}" +else + echo -e "${RED}Error: Output file was not created.${RESET}" + exit 1 +fi + +while true; do + echo -e "\n${CYAN}Select option:${RESET}" + echo "1) Change settings and create a NEW file (next available index)" + echo "2) Redo with current settings (will overwrite ${output_file})" + echo "q) Exit" + read -p "Choice: " post_choice + + case $post_choice in + 1) + if $auto_index; then + base=$(basename "$output_file" | sed 's/-[0-9]*\.gif$//') + i=0 + while [[ -f "${base}-${i}.gif" ]]; do + ((i++)) + done + output_file="${base}-${i}.gif" + else + base=$(basename "$output_file" | sed 's/\.gif$//') + i=0 + while [[ -f "${base}-${i}.gif" ]]; do + ((i++)) + done + output_file="${base}-${i}.gif" + fi + echo -e "New output file will be: ${YELLOW}${output_file}${RESET}" + configure_settings + echo -e "\n${GREEN}Starting new conversion...${RESET}" + cmd_array=(ffmpeg -y) + if [[ -n "$start_time" ]]; then cmd_array+=(-ss "$start_time"); fi + cmd_array+=(-i "$input") + if [[ -n "$dur" ]]; then cmd_array+=(-t "$dur"); fi + vf="$(build_vf)" + cmd_array+=(-vf "$vf") + if $loop_infinite; then cmd_array+=(-loop 0); else cmd_array+=(-loop 1); fi + cmd_array+=("$output_file") + "${cmd_array[@]}" + if [[ -f "$output_file" ]]; then + size=$(du -h "$output_file" | awk '{print $1}') + echo -e "\n${GREEN}New file created!${RESET} File: ${GREEN}${output_file}${RESET} Size: ${GREEN}${size}${RESET}" + fi + ;; + 2) + echo -e "${YELLOW}Will overwrite ${output_file} on next run.${RESET}" + configure_settings + echo -e "\n${GREEN}Starting conversion (overwrite mode)...${RESET}" + cmd_array=(ffmpeg -y) + + if [[ -n "$start_time" ]]; then cmd_array+=(-ss "$start_time"); fi + cmd_array+=(-i "$input") + + if [[ -n "$dur" ]]; then cmd_array+=(-t "$dur"); fi + vf="$(build_vf)" + cmd_array+=(-vf "$vf") + + if $loop_infinite; then cmd_array+=(-loop 0); else cmd_array+=(-loop 1); fi + cmd_array+=("$output_file") + "${cmd_array[@]}" + + if [[ -f "$output_file" ]]; then + size=$(du -h "$output_file" | awk '{print $1}') + echo -e "\n${GREEN}Overwritten!${RESET} File: ${GREEN}${output_file}${RESET} Size: ${GREEN}${size}${RESET}" + fi + ;; + q) + echo -e "${GREEN}Done.${RESET}" + exit 0 + ;; + *) + echo -e "${RED}Invalid choice.${RESET}" + ;; + esac +done diff --git a/dot_config/zsh/scripts/executable_yt-dlp.sh b/dot_local/scripts/yt-dlp/executable_download.sh similarity index 97% rename from dot_config/zsh/scripts/executable_yt-dlp.sh rename to dot_local/scripts/yt-dlp/executable_download.sh index 289a5c2..3c20ecd 100644 --- a/dot_config/zsh/scripts/executable_yt-dlp.sh +++ b/dot_local/scripts/yt-dlp/executable_download.sh @@ -73,9 +73,7 @@ colored_read() { echo "$val" } -# Helper for cookies selection (1-3 presets or direct custom value) select_cookies() { - # If current cookies looks like an old choice number, upgrade it to value case "$cookies" in 1) cookies="firefox:~/.config/librewolf/librewolf" ;; 2) cookies="firefox" ;; @@ -108,7 +106,6 @@ select_cookies() { cookies="" ;; *) - # anything else is treated as a full custom cookies value cookies="$cinput" ;; esac @@ -345,7 +342,6 @@ review_and_confirm() { } main() { - # Initialize to avoid pollution from previous runs / sourcing url="" cookies="" start_time="" diff --git a/dot_local/share/applications/discord-canary.desktop b/dot_local/share/applications/discord-canary.desktop deleted file mode 100644 index 6337be4..0000000 --- a/dot_local/share/applications/discord-canary.desktop +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Name=Discord Canary -StartupWMClass=discord-canary -Comment=All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone. -GenericName=Internet Messenger -Exec=env ELECTRON_OZONE_PLATFORM_HINT=discord /usr/bin/discord-canary --url -- %u -Icon=discord-canary -Type=Application -Categories=Network;InstantMessaging; -MimeType=x-scheme-handler/discord; -Path=/usr/bin