[niri|scripts|zsh] Add more scripts
- Move scripts folder - Add discord scripts for niri - Add yt-dlp script
This commit is contained in:
1 parent
97dc31437a
commit
8e6546f468
8 files changed
+791
-15
No files matched your search
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,381 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
RESET='\033[0m'
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
MAGENTA='\033[0;35m'
|
||||
BOLD='\033[1m'
|
||||
|
||||
time_to_seconds() {
|
||||
local t="$1"
|
||||
if [[ "$t" == "inf" ]]; then
|
||||
echo 999999999
|
||||
return
|
||||
fi
|
||||
local sign=1
|
||||
if [[ "$t" == -* ]]; then
|
||||
sign=-1
|
||||
t="${t#-}"
|
||||
fi
|
||||
if [[ "$t" =~ ^[0-9]+$ ]]; then
|
||||
echo $(( sign * t ))
|
||||
return
|
||||
fi
|
||||
IFS=: read -ra parts <<< "$t"
|
||||
local secs=0
|
||||
local n=${#parts[@]}
|
||||
if [ $n -eq 3 ]; then
|
||||
secs=$(( ${parts[0]}*3600 + ${parts[1]}*60 + ${parts[2]} ))
|
||||
elif [ $n -eq 2 ]; then
|
||||
secs=$(( ${parts[0]}*60 + ${parts[1]} ))
|
||||
else
|
||||
secs=0
|
||||
fi
|
||||
echo $(( sign * secs ))
|
||||
}
|
||||
|
||||
is_valid_time_format() {
|
||||
local t="$1"
|
||||
if [[ "$t" == "inf" || "$t" =~ ^-?[0-9]+$ || "$t" =~ ^-?[0-9]+(:[0-9]+)+$ ]]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
validate_merge_format() {
|
||||
local fmt="$1"
|
||||
local allowed="avi flv mkv mov mp4 webm"
|
||||
for a in $allowed; do
|
||||
if [[ "$fmt" == "$a" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
colored_read() {
|
||||
local prompt="$1"
|
||||
local default="$2"
|
||||
local val
|
||||
if [ -n "$default" ]; then
|
||||
echo -e "${prompt} ${YELLOW}(current: $default)${RESET}" >&2
|
||||
read -p "New value (empty = keep): " val
|
||||
if [ -z "$val" ]; then
|
||||
val="$default"
|
||||
fi
|
||||
else
|
||||
echo -e "$prompt" >&2
|
||||
read -p "> " val
|
||||
fi
|
||||
echo "$val"
|
||||
}
|
||||
|
||||
select_cookies() {
|
||||
case "$cookies" in
|
||||
1) cookies="firefox:~/.config/librewolf/librewolf" ;;
|
||||
2) cookies="firefox" ;;
|
||||
3) cookies="chrome" ;;
|
||||
esac
|
||||
|
||||
echo -e "\n${MAGENTA}Browser cookies:${RESET}"
|
||||
echo " 1) Librewolf (firefox:~/.config/librewolf/librewolf)"
|
||||
echo " 2) Firefox (firefox)"
|
||||
echo " 3) Chrome (chrome)"
|
||||
echo " (or type a full custom value directly, e.g. firefox:Profile 1)"
|
||||
echo " (empty = none / keep current)"
|
||||
|
||||
local prompt="Select 1-3 or enter custom"
|
||||
if [ -n "$cookies" ]; then
|
||||
echo -e "${BLUE}${prompt}:${RESET} ${YELLOW}(current: $cookies)${RESET}" >&2
|
||||
else
|
||||
echo -e "${BLUE}${prompt}:${RESET}" >&2
|
||||
fi
|
||||
|
||||
local cinput
|
||||
read -r cinput
|
||||
|
||||
if [ -n "$cinput" ]; then
|
||||
case "$cinput" in
|
||||
1) cookies="firefox:~/.config/librewolf/librewolf" ;;
|
||||
2) cookies="firefox" ;;
|
||||
3) cookies="chrome" ;;
|
||||
0|none|clear)
|
||||
cookies=""
|
||||
;;
|
||||
*)
|
||||
cookies="$cinput"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
collect_inputs() {
|
||||
url=$(colored_read "${BLUE}Enter video URL:${RESET}" "$url")
|
||||
|
||||
select_cookies
|
||||
|
||||
echo -e "\n${MAGENTA}Clip / Download sections:${RESET}"
|
||||
echo "Use *START-END (e.g. *0:21-1:27 or *83-296)"
|
||||
echo "End can be 'inf' for to the end. Negative = from end of video."
|
||||
echo "*from-url also supported to use times from video URL."
|
||||
echo "Leave start/end empty to download full video."
|
||||
start_time=$(colored_read "${BLUE}Start time (e.g. 0:21 or 83, empty=skip):${RESET}" "$start_time")
|
||||
end_time=$(colored_read "${BLUE}End time (e.g. 1:27 or inf, empty=skip):${RESET}" "$end_time")
|
||||
|
||||
if [ -n "$start_time" ] || [ -n "$end_time" ]; then
|
||||
if [ -n "$start_time" ] && ! is_valid_time_format "$start_time"; then
|
||||
echo -e "${RED}Invalid start time format. Use number, MM:SS or HH:MM:SS${RESET}"
|
||||
start_time=""
|
||||
fi
|
||||
if [ -n "$end_time" ] && ! is_valid_time_format "$end_time"; then
|
||||
echo -e "${RED}Invalid end time format. Use number, MM:SS, HH:MM:SS or inf${RESET}"
|
||||
end_time=""
|
||||
fi
|
||||
if [ -n "$start_time" ] && [ -n "$end_time" ]; then
|
||||
ssec=$(time_to_seconds "$start_time")
|
||||
esec=$(time_to_seconds "$end_time")
|
||||
if [ "$ssec" -ge "$esec" ]; then
|
||||
echo -e "${RED}Start time must be strictly before end time.${RESET}"
|
||||
start_time=""
|
||||
end_time=""
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "\n${MAGENTA}Format selection:${RESET}"
|
||||
echo "Common presets:"
|
||||
echo "1) Best video+audio merged (bv+ba/b)"
|
||||
echo "2) Best MP4 video + best m4a audio"
|
||||
echo "3) Best video (any) + best audio (bv*+ba/b)"
|
||||
echo "4) Best video only + best audio only (separate files, no merge)"
|
||||
echo "5) Custom full -f string (advanced)"
|
||||
echo "6) Audio only as MP3 (bestaudio/best + extract to mp3)"
|
||||
format_choice=$(colored_read "${BLUE}Choose 1-6 or enter custom -f value directly:${RESET}" "$format_choice")
|
||||
|
||||
mp3_only=""
|
||||
case "$format_choice" in
|
||||
1) format_selector='bv+ba/b' ;;
|
||||
2) format_selector='bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]' ;;
|
||||
3) format_selector='bv*+ba/b' ;;
|
||||
4) format_selector='bv,ba' ;;
|
||||
5)
|
||||
echo "Examples:"
|
||||
echo ' bv+ba/b'
|
||||
echo ' bestvideo[ext=mp4]+bestaudio[ext=m4a]/best'
|
||||
echo ' bv[height<=720]+ba'
|
||||
echo ' ba[ext=m4a]/b'
|
||||
custom_f=$(colored_read "${BLUE}Enter full -f string:${RESET}" "")
|
||||
format_selector="$custom_f"
|
||||
;;
|
||||
6)
|
||||
format_selector='bestaudio/best'
|
||||
mp3_only="yes"
|
||||
;;
|
||||
*)
|
||||
if [ -n "$format_choice" ]; then
|
||||
format_selector="$format_choice"
|
||||
else
|
||||
format_selector=""
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$mp3_only" = "yes" ]; then
|
||||
echo -e "\n${YELLOW}MP3 audio only selected — merge format is not applicable.${RESET}"
|
||||
merge_format=""
|
||||
else
|
||||
echo -e "\n${MAGENTA}Merge output format:${RESET}"
|
||||
echo "Supported containers: avi, flv, mkv, mov, mp4, webm"
|
||||
echo "Ignored if no merge is needed (single format or separate files)."
|
||||
echo "Requires ffmpeg for merging."
|
||||
merge_format=$(colored_read "${BLUE}Merge format (e.g. mp4 or mkv, empty=skip):${RESET}" "$merge_format")
|
||||
|
||||
if [ -n "$merge_format" ] && ! validate_merge_format "$merge_format"; then
|
||||
echo -e "${RED}Invalid merge format. Allowed: avi flv mkv mov mp4 webm${RESET}"
|
||||
merge_format=""
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "\n${MAGENTA}Extra option:${RESET}"
|
||||
force_key=$(colored_read "${BLUE}Add --force-keyframes-at-cuts for exact cuts? (y/n):${RESET}" "$force_key")
|
||||
if [[ "$force_key" =~ ^[Yy] ]]; then
|
||||
force_key="y"
|
||||
force="--force-keyframes-at-cuts"
|
||||
else
|
||||
force_key="n"
|
||||
force=""
|
||||
fi
|
||||
}
|
||||
|
||||
build_command() {
|
||||
cmd_args=()
|
||||
[ -n "$cookies" ] && cmd_args+=("--cookies-from-browser" "$cookies")
|
||||
|
||||
if [ -n "$start_time" ] || [ -n "$end_time" ]; then
|
||||
section="*${start_time}-${end_time}"
|
||||
cmd_args+=("--download-sections" "$section")
|
||||
fi
|
||||
|
||||
if [ -n "$format_selector" ]; then
|
||||
cmd_args+=("-f" "$format_selector")
|
||||
fi
|
||||
|
||||
if [ "$mp3_only" = "yes" ]; then
|
||||
cmd_args+=(--extract-audio --audio-format mp3)
|
||||
elif [ -n "$merge_format" ]; then
|
||||
cmd_args+=("--merge-output-format" "$merge_format")
|
||||
fi
|
||||
|
||||
[ -n "$force" ] && cmd_args+=("$force")
|
||||
|
||||
[ -n "$url" ] && cmd_args+=("$url")
|
||||
}
|
||||
|
||||
review_and_confirm() {
|
||||
while true; do
|
||||
echo -e "\n${GREEN}${BOLD}Current Settings${RESET}"
|
||||
echo -e "${BLUE}URL:${RESET} ${url:-<not set>}"
|
||||
echo -e "${BLUE}Cookies:${RESET} ${cookies:-<none>}"
|
||||
echo -e "${BLUE}Start time:${RESET} ${start_time:-<full video>}"
|
||||
echo -e "${BLUE}End time:${RESET} ${end_time:-<full video>}"
|
||||
if [ "$mp3_only" = "yes" ]; then
|
||||
echo -e "${BLUE}Format:${RESET} MP3 audio only"
|
||||
echo -e "${BLUE}Merge format:${RESET} N/A (audio only)"
|
||||
else
|
||||
echo -e "${BLUE}Format:${RESET} ${format_selector:-<default>}"
|
||||
echo -e "${BLUE}Merge format:${RESET} ${merge_format:-<auto>}"
|
||||
fi
|
||||
echo -e "${BLUE}Force keyframes:${RESET} ${force_key:-n}"
|
||||
|
||||
echo -e "\n${YELLOW}Options:${RESET}"
|
||||
echo "1) Edit URL"
|
||||
echo "2) Edit cookies"
|
||||
echo "3) Edit start/end times"
|
||||
echo "4) Edit format"
|
||||
echo "5) Edit merge format"
|
||||
echo "6) Toggle force-keyframes"
|
||||
echo "r) Re-run all prompts with current values pre-filled"
|
||||
echo "run) Proceed to download (or just press Enter)"
|
||||
echo "q) Quit without running"
|
||||
read -p "Choose option: " review_opt
|
||||
|
||||
review_opt="${review_opt#"${review_opt%%[![:space:]]*}"}"
|
||||
review_opt="${review_opt%"${review_opt##*[![:space:]]}"}"
|
||||
|
||||
case "$review_opt" in
|
||||
1) url=$(colored_read "${BLUE}New URL:${RESET}" "$url") ;;
|
||||
2)
|
||||
select_cookies
|
||||
;;
|
||||
3)
|
||||
start_time=$(colored_read "${BLUE}New start time (empty=keep):${RESET}" "$start_time")
|
||||
end_time=$(colored_read "${BLUE}New end time (empty=keep):${RESET}" "$end_time")
|
||||
if [ -n "$start_time" ] && ! is_valid_time_format "$start_time"; then start_time=""; fi
|
||||
if [ -n "$end_time" ] && ! is_valid_time_format "$end_time"; then end_time=""; fi
|
||||
if [ -n "$start_time" ] && [ -n "$end_time" ]; then
|
||||
ssec=$(time_to_seconds "$start_time")
|
||||
esec=$(time_to_seconds "$end_time")
|
||||
if [ "$ssec" -ge "$esec" ]; then
|
||||
echo -e "${RED}Start must be before end. Cleared.${RESET}"
|
||||
start_time=""; end_time=""
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
4)
|
||||
echo "Format presets (same as before)..."
|
||||
format_choice=$(colored_read "${BLUE}New format choice 1-6 or custom:${RESET}" "")
|
||||
mp3_only=""
|
||||
case "$format_choice" in
|
||||
1) format_selector='bv+ba/b' ;;
|
||||
2) format_selector='bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]' ;;
|
||||
3) format_selector='bv*+ba/b' ;;
|
||||
4) format_selector='bv,ba' ;;
|
||||
5)
|
||||
custom_f=$(colored_read "${BLUE}Enter full -f string:${RESET}" "")
|
||||
format_selector="$custom_f"
|
||||
;;
|
||||
6)
|
||||
format_selector='bestaudio/best'
|
||||
mp3_only="yes"
|
||||
;;
|
||||
*) if [ -n "$format_choice" ]; then format_selector="$format_choice"; fi ;;
|
||||
esac
|
||||
if [ "$mp3_only" = "yes" ]; then
|
||||
merge_format=""
|
||||
fi
|
||||
;;
|
||||
5)
|
||||
if [ "$mp3_only" = "yes" ]; then
|
||||
echo -e "${YELLOW}Merge format not applicable for MP3 audio only.${RESET}"
|
||||
else
|
||||
merge_format=$(colored_read "${BLUE}New merge format (avi/flv/mkv/mov/mp4/webm):${RESET}" "$merge_format")
|
||||
if [ -n "$merge_format" ] && ! validate_merge_format "$merge_format"; then
|
||||
echo -e "${RED}Invalid. Cleared.${RESET}"
|
||||
merge_format=""
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
6)
|
||||
if [[ "$force_key" =~ ^[Yy]$ ]]; then
|
||||
force_key="n"; force=""
|
||||
else
|
||||
force_key="y"; force="--force-keyframes-at-cuts"
|
||||
fi
|
||||
;;
|
||||
r)
|
||||
echo -e "${YELLOW}Re-running all questions with current values...${RESET}"
|
||||
collect_inputs
|
||||
;;
|
||||
run|"")
|
||||
return 0
|
||||
;;
|
||||
q)
|
||||
echo -e "${RED}Aborted.${RESET}"
|
||||
exit 0
|
||||
;;
|
||||
*) echo -e "${RED}Invalid choice.${RESET}" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
url=""
|
||||
cookies=""
|
||||
start_time=""
|
||||
end_time=""
|
||||
format_selector=""
|
||||
mp3_only=""
|
||||
merge_format=""
|
||||
force=""
|
||||
force_key="n"
|
||||
|
||||
collect_inputs
|
||||
review_and_confirm
|
||||
build_command
|
||||
|
||||
echo -e "\n${GREEN}${BOLD}Final command:${RESET}"
|
||||
echo -e "${CYAN}yt-dlp${RESET} \c"
|
||||
printf '%q ' "${cmd_args[@]}"
|
||||
echo -e "${RESET}\n"
|
||||
|
||||
if ! command -v yt-dlp >/dev/null 2>&1; then
|
||||
echo -e "${RED}Error: yt-dlp not found in PATH.${RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -p "Run now? (y/n): " confirm_run
|
||||
confirm_run="${confirm_run//[[:space:]]/}"
|
||||
if [[ "$confirm_run" =~ ^[Yy]$ ]]; then
|
||||
echo -e "${GREEN}Starting download...${RESET}"
|
||||
yt-dlp "${cmd_args[@]}"
|
||||
else
|
||||
echo -e "${YELLOW}Command prepared but not executed.${RESET}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
main
|
||||
fi
|
||||
Reference in new issue
Block a user