Script updates

This commit is contained in:
Matheus Albino
2024-08-09 19:21:28 -03:00
parent fe8e760d37
commit e5e4128458
5 changed files with 215 additions and 170 deletions

View File

@@ -0,0 +1,2 @@
# vencord stuff
cp '/mnt/c/Users/cloud/AppData/Roaming/Vencord/settings/settings.json' '/mnt/e/home/clouds/google-drive/backup'

View File

@@ -0,0 +1,3 @@
#!/bin/bash
ffmpeg -i $1 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p"

View File

@@ -1,31 +1,31 @@
#!/bin/bash #!/bin/bash
show_help() { show_help() {
echo "Usage: `basename $0` [--input|-i input_file] [--crop|-c width:height] [--trim-start start] [--trim-end end] [--crf crf_value] [--fps new_fps] [--scale640] [--merge-audio] [--remove-audio] --output|-o output_file" echo "Usage: $(basename $0) [--input|-i input_file] [--crop|-c width:height] [--trim-start start] [--trim-end end] [--crf crf_value] [--fps new_fps] [--scale new_video_resolution] [--merge-audio] [--remove-audio] --output|-o output_file"
echo "Options:" echo "Options:"
echo " --input|-i Specify the input video file (required)." echo " --input|-i Specify the input video file (required)."
echo " --crop|-c Specify the width:height for video cropping." echo " --crop|-c Specify the width:height for video cropping."
echo " --trim-start Specify the start timestamp for video trimming." echo " --trim-start Specify the start timestamp for video trimming."
echo " --trim-end Specify the end timestamp for video trimming." echo " --trim-end Specify the end timestamp for video trimming."
echo " --crf Specify the CRF value for video compressing." echo " --crf Specify the CRF value for video compressing."
echo " --fps Specify the new frames per second for the video." echo " --fps Specify the new frames per second for the video."
echo " --scale640 Scale the video to 640x320." echo " --scale Scale the video to a new resolution."
echo " --merge-audio Merge all audio tracks into the main track." echo " --merge-audio Merge all audio tracks into the main track."
echo " --remove-audio Suppress all audio and remove audio tracks." echo " --remove-audio Suppress all audio and remove audio tracks."
echo " --audio-track-no Selects a specific audio track for the output" echo " --audio-track-no Selects a specific audio track for the output"
echo " --output|-o Specify the output filename (required)." echo " --output|-o Specify the output filename (required)."
} }
remove_audio() { remove_audio() {
input_file="$1" input_file="$1"
output_file="$2" output_file="$2"
ffmpeg -i "$input_file" -an "$output_file" ffmpeg -i "$input_file" -an "$output_file"
} }
if ! command -v ffmpeg &> /dev/null; then if ! command -v ffmpeg &>/dev/null; then
echo "Error: 'ffmpeg' command not found. Please install ffmpeg." echo "Error: 'ffmpeg' command not found. Please install ffmpeg."
exit 1 exit 1
fi fi
input_file="" input_file=""
@@ -34,73 +34,109 @@ trim_start=""
trim_end="" trim_end=""
crf="" crf=""
new_fps="" new_fps=""
scale640=false scale=""
merge_audio=false merge_audio=false
remove_audio=false remove_audio=false
audio_track_no=1 audio_track_no=1
output_file="" output_file=""
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
case "$1" in case "$1" in
--help|-h) show_help; exit ;; --help | -h)
--input|-i) input_file="$2"; shift 2 ;; show_help
--crop|-c) crop="$2"; shift 2 ;; exit
--trim-start) trim_start="$2"; shift 2 ;; ;;
--trim-end) trim_end="$2"; shift 2 ;; --input | -i)
--crf) crf="$2"; shift 2 ;; input_file="$2"
--fps) new_fps="$2"; shift 2 ;; shift 2
--scale640) scale640=true; shift ;; ;;
--merge-audio) merge_audio=true; shift ;; --crop | -c)
--remove-audio) remove_audio=true; shift;; crop="$2"
--audio-track-no) audio_track_no="$2"; shift;; shift 2
--output|-o) output_file="$2"; shift 2 ;; ;;
*) shift ;; --trim-start)
esac trim_start="$2"
shift 2
;;
--trim-end)
trim_end="$2"
shift 2
;;
--crf)
crf="$2"
shift 2
;;
--fps)
new_fps="$2"
shift 2
;;
--scale)
scale="$2"
shift 2
;;
--merge-audio)
merge_audio=true
shift
;;
--remove-audio)
remove_audio=true
shift
;;
--audio-track-no)
audio_track_no="$2"
shift
;;
--output | -o)
output_file="$2"
shift 2
;;
*) shift ;;
esac
done done
if [ -z "$input_file" ]; then if [ -z "$input_file" ]; then
echo "Error: Input filename (--input or -i) is required." echo "Error: Input filename (--input or -i) is required."
exit 1 exit 1
fi fi
if [ -z "$output_file" ]; then if [ -z "$output_file" ]; then
echo "Error: Output filename (--output or -o) is required." echo "Error: Output filename (--output or -o) is required."
exit 1 exit 1
fi fi
if [ -z "$crop" ] && [ -z "$trim_start" ] && [ -z "$trim_end" ] && [ -z "$crf" ] && [ -z "$new_fps" ] && [ "$merge_audio" = false ] && [ "$scale640" = false ] && [ "$remove_audio" = false ]; then if [ -z "$crop" ] && [ -z "$trim_start" ] && [ -z "$trim_end" ] && [ -z "$crf" ] && [ -z "$new_fps" ] && [ "$merge_audio" = false ] && [ -z "$scale" ] && [ "$remove_audio" = false ]; then
echo "Error: At least one optional parameter is required." echo "Error: At least one optional parameter is required."
exit 1 exit 1
fi fi
if [ -n "$trim_start" ] && [ -z "$trim_end" ]; then if [ -n "$trim_start" ] && [ -z "$trim_end" ]; then
echo "Error: If using --trim-start, you must also specify --trim-end." echo "Error: If using --trim-start, you must also specify --trim-end."
exit 1 exit 1
fi fi
if [ -n "$trim_end" ] && [ -z "$trim_start" ]; then if [ -n "$trim_end" ] && [ -z "$trim_start" ]; then
echo "Error: If using --trim-end, you must also specify --trim-start." echo "Error: If using --trim-end, you must also specify --trim-start."
exit 1 exit 1
fi fi
if [ -n "$crop" ] && [ "$scale640" = true ]; then if [ -n "$crop" ] && [ "$scale" = true ]; then
echo "Error: Cannot use both --crop and --scale640 together." echo "Error: Cannot use both --crop and --scale together."
exit 1 exit 1
fi fi
if [ "$merge_audio" = true ] && [ "$remove_audio" = true ]; then if [ "$merge_audio" = true ] && [ "$remove_audio" = true ]; then
echo "Error: Cannot use both --merge-audio and --remove-audio together." echo "Error: Cannot use both --merge-audio and --remove-audio together."
exit 1 exit 1
fi fi
if [ "$merge_audio" = true ] && [ "$audio_track_no" != 1 ]; then if [ "$merge_audio" = true ] && [ "$audio_track_no" != 1 ]; then
echo "Error: Cannot use both --merge-audio and --audio-track-no together." echo "Error: Cannot use both --merge-audio and --audio-track-no together."
exit 1 exit 1
fi fi
if [ "$remove_audio" = true ] && [ "$audio_track_no" != 1 ]; then if [ "$remove_audio" = true ] && [ "$audio_track_no" != 1 ]; then
echo "Error: Cannot use both --remove-audio and --audio-track-no together." echo "Error: Cannot use both --remove-audio and --audio-track-no together."
exit 1 exit 1
fi fi
ffmpeg_command="ffmpeg -i \"$input_file\"" ffmpeg_command="ffmpeg -i \"$input_file\""
@@ -110,36 +146,36 @@ ffmpeg_command="ffmpeg -i \"$input_file\""
# fi # fi
if [ "$remove_audio" = true ]; then if [ "$remove_audio" = true ]; then
ffmpeg_command+=" -an" ffmpeg_command+=" -an"
fi fi
if [ -n "$crop" ]; then if [ -n "$crop" ]; then
ffmpeg_command+=" -vf crop=$crop" ffmpeg_command+=" -vf crop=$crop"
fi fi
if [ -n "$trim_start" ] && [ -n "$trim_end" ]; then if [ -n "$trim_start" ] && [ -n "$trim_end" ]; then
ffmpeg_command+=" -ss $trim_start -to $trim_end" ffmpeg_command+=" -ss $trim_start -to $trim_end"
fi fi
if [ -n "$crf" ]; then if [ -n "$crf" ]; then
ffmpeg_command+=" -c:v libx264 -crf $crf" ffmpeg_command+=" -c:v libx265 -crf $crf"
fi fi
if [ -n "$new_fps" ]; then if [ -n "$new_fps" ]; then
ffmpeg_command+=" -r $new_fps" ffmpeg_command+=" -r $new_fps"
fi fi
if [ "$scale640" = true ]; then if [ -n "$scale" ]; then
ffmpeg_command+=" -vf scale=640:320" ffmpeg_command+=" -s $scale"
fi fi
if [ "$merge_audio" = true ]; then if [ "$merge_audio" = true ]; then
num_audio_streams=$(ffprobe -loglevel error -select_streams a -show_entries stream=codec_type -of csv=p=0 "$input_file" | wc -l) num_audio_streams=$(ffprobe -loglevel error -select_streams a -show_entries stream=codec_type -of csv=p=0 "$input_file" | wc -l)
ffmpeg_command+=" -filter_complex amerge=inputs=$num_audio_streams" ffmpeg_command+=" -filter_complex amerge=inputs=$num_audio_streams"
fi fi
if [ "$audio_track_no" != 1 ]; then if [ "$audio_track_no" != 1 ]; then
ffmpeg_command+=" -map 0:0 -map 0:$audio_track_no" ffmpeg_command+=" -map 0:0 -map 0:$audio_track_no"
fi fi
ffmpeg_command+=" \"$output_file\"" ffmpeg_command+=" \"$output_file\""

View File

@@ -8,4 +8,4 @@ video_res=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,heig
video_framerate=$(ffmpeg -i $file_to_convert 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p") video_framerate=$(ffmpeg -i $file_to_convert 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p")
ffmpeg -y -i $file_to_convert -vf palettegen $pallete_file ffmpeg -y -i $file_to_convert -vf palettegen $pallete_file
ffmpeg -y -i $file_to_convert -i $pallete_file -filter_complex paletteuse "${file_to_convert%"$file_to_convert_extension"}.gif" ffmpeg -y -i $file_to_convert -i $pallete_file -filter_complex fps=20,paletteuse "${file_to_convert%".$file_to_convert_extension"}.gif"

View File

@@ -2,7 +2,7 @@
show_help() { show_help() {
# echo "Usage: `basename $0` [--no-abort-on-found] [--parallel] [--custom-grep-search|-c <string>]" # echo "Usage: `basename $0` [--no-abort-on-found] [--parallel] [--custom-grep-search|-c <string>]"
echo "Usage: `basename $0` [--help|-h] [--filter-mode|-f]" echo "Usage: $(basename $0) [--help|-h] [--filter-mode|-f]"
echo "Options:" echo "Options:"
echo " --help | -h (optional) Display script's help text" echo " --help | -h (optional) Display script's help text"
echo " --filter-mode | -f (optional) The script iterate over the files of a selected folder and store the ones that should be deleted" echo " --filter-mode | -f (optional) The script iterate over the files of a selected folder and store the ones that should be deleted"
@@ -11,9 +11,15 @@ show_help() {
filter_mode=false filter_mode=false
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
case "$1" in case "$1" in
--help|-h) show_help; exit ;; --help | -h)
--filter-mode|-f) filter_mode=true; shift;; show_help
*) shift ;; exit
;;
--filter-mode | -f)
filter_mode=true
shift
;;
*) shift ;;
esac esac
done done
@@ -21,56 +27,56 @@ commands_to_check=(gallery-dl gdl.sh feh xdotool)
commands_not_found=() commands_not_found=()
for command in ${commands_to_check[@]}; do for command in ${commands_to_check[@]}; do
if ! command -v "$command" &> /dev/null; then if ! command -v "$command" &>/dev/null; then
commands_not_found+=("$command") commands_not_found+=("$command")
fi fi
done done
if [ ${#commands_not_found[@]} -ne 0 ]; then if [ ${#commands_not_found[@]} -ne 0 ]; then
echo 'The following commands are necessary in order to run the script, but were not found:' echo 'The following commands are necessary in order to run the script, but were not found:'
for command in ${commands_not_found[@]}; do for command in ${commands_not_found[@]}; do
echo " \"$command\"" echo " \"$command\""
done done
exit 1 exit 1
fi fi
cur_dir=`pwd` cur_dir=$(pwd)
furry_commission_ideas_path=/mnt/e/home/documents/data-hoarding/furry-commission-ideas furry_commission_ideas_path=/mnt/e/home/documents/downloads-furry
furry_commission_ideas_urls_filename="urls.txt" furry_commission_ideas_urls_filename="urls.txt"
scripts_path=/home/cloud/repos/personal-devboot/scripts/shell scripts_path=/home/cloud/repos/personal-devboot/scripts/shell
if [ ! -d $furry_commission_ideas_path ]; then if [ ! -d $furry_commission_ideas_path ]; then
echo "[ERROR] The images folder was not found (\"$furry_commission_ideas_path\")" echo "[ERROR] The images folder was not found (\"$furry_commission_ideas_path\")"
exit 1 exit 1
fi fi
if [ ! -d $scripts_path ]; then if [ ! -d $scripts_path ]; then
echo "[ERROR] The scripts folder was not found (\"$scripts_path\")" echo "[ERROR] The scripts folder was not found (\"$scripts_path\")"
exit 1 exit 1
fi fi
input_media_url() { input_media_url() {
read -p "[INFO] Please inform the media's url: " media_url read -p "[INFO] Please inform the media's url: " media_url
echo "$media_url" echo "$media_url"
} }
media_url='' media_url=''
if ! $filter_mode; then if ! $filter_mode; then
media_url=`input_media_url` media_url=$(input_media_url)
while [ -z "$media_url" ]; do while [ -z "$media_url" ]; do
media_url=`input_media_url` media_url=$(input_media_url)
done done
# remove trailing slashes # remove trailing slashes
media_url=`sed 's:/*$::' <<< "$media_url"` media_url=$(sed 's:/*$::' <<<"$media_url")
url_regex='(https?)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' url_regex='(https?)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]'
if [[ ! $media_url =~ $url_regex ]]; then if [[ ! $media_url =~ $url_regex ]]; then
echo "The URL informed is not valid." echo "The URL informed is not valid."
exit 1 exit 1
fi fi
fi fi
@@ -82,70 +88,70 @@ filtered_existing_folders=()
# removing artists folder depth 2 only # removing artists folder depth 2 only
for folder in "${existing_folders[@]}"; do for folder in "${existing_folders[@]}"; do
if [[ ! $folder =~ ^artists/[^/]+$ ]]; then if [[ ! $folder =~ ^artists/[^/]+$ ]]; then
filtered_existing_folders+=( "$folder" ) filtered_existing_folders+=("$folder")
fi; fi
done done
existing_folders=("${filtered_existing_folders[@]}") existing_folders=("${filtered_existing_folders[@]}")
input_create_folder() { input_create_folder() {
read -p "[INFO] Please create one: " new_foldername read -p "[INFO] Please create one: " new_foldername
echo "$new_foldername" echo "$new_foldername"
} }
selected_folder='' selected_folder=''
if [ -z "${existing_folders}" ]; then if [ -z "${existing_folders}" ]; then
echo "[INFO] There are no folders in the 'furry-commission-ideas' folder." echo "[INFO] There are no folders in the 'furry-commission-ideas' folder."
new_foldername=$(input_create_folder)
while [ -z "$new_foldername" ]; do
new_foldername=$(input_create_folder) new_foldername=$(input_create_folder)
while [ -z "$new_foldername" ]; do done
new_foldername=$(input_create_folder)
done
mkdir --parents "$new_foldername" mkdir --parents "$new_foldername"
selected_folder="$new_foldername" selected_folder="$new_foldername"
fi fi
input_create_folder() { input_create_folder() {
read -p "[INFO] Please informe a name for the new folder: " new_foldername read -p "[INFO] Please informe a name for the new folder: " new_foldername
echo "$new_foldername" echo "$new_foldername"
} }
input_select_folder() { input_select_folder() {
read -p "[INFO] Please inform the desired option: " selected_option read -p "[INFO] Please inform the desired option: " selected_option
if [ "$selected_option" == 'n' ]; then if [ "$selected_option" == 'n' ]; then
selected_folder=`input_create_folder` selected_folder=$(input_create_folder)
while [ -z "$selected_folder" ]; do while [ -z "$selected_folder" ]; do
selected_folder=`input_create_folder` selected_folder=$(input_create_folder)
done done
mkdir --parents "$selected_folder" mkdir --parents "$selected_folder"
else else
selected_folder=${existing_folders[$selected_option]} selected_folder=${existing_folders[$selected_option]}
fi fi
echo "$selected_folder" echo "$selected_folder"
} }
if [ -z "$selected_folder" ]; then if [ -z "$selected_folder" ]; then
printf "\n" printf "\n"
echo "[INFO] Folders:" echo "[INFO] Folders:"
for ((i = 0; i < ${#existing_folders[@]}; i++)); do for ((i = 0; i < ${#existing_folders[@]}; i++)); do
foldername=${existing_folders[$i]} foldername=${existing_folders[$i]}
echo " $i) $foldername" echo " $i) $foldername"
done done
echo " n) (create a new folder)" echo " n) (create a new folder)"
printf "\n" printf "\n"
selected_folder=`input_select_folder` selected_folder=$(input_select_folder)
while [ -z "$selected_folder" ]; do while [ -z "$selected_folder" ]; do
selected_folder=`input_select_folder` selected_folder=$(input_select_folder)
done done
fi fi
cd $selected_folder cd $selected_folder
@@ -154,11 +160,11 @@ function confirm() {
while true; do while true; do
read -n 1 yn read -n 1 yn
case $yn in case $yn in
[Yy]* ) return 0;; [Yy]*) return 0 ;;
[Nn]* ) return 1;; [Nn]*) return 1 ;;
[Uu]* ) return 2;; [Uu]*) return 2 ;;
[Cc]* ) exit;; [Cc]*) exit ;;
* ) echo "Please answer YES, NO, or CANCEL.";; *) echo "Please answer YES, NO, or CANCEL." ;;
esac esac
done done
} }
@@ -170,14 +176,14 @@ escape_string() {
# Iterate over each character in the input string # Iterate over each character in the input string
while IFS= read -r -n1 char; do while IFS= read -r -n1 char; do
case "$char" in case "$char" in
' '|'\'|'$'|'`'|'!'|'&'|'|'|';'|'<'|'>'|'"'|"'"|'*'|'?'|'['|']'|'{'|'}'|'('|')'|'#') ' ' | '\' | '$' | '`' | '!' | '&' | '|' | ';' | '<' | '>' | '"' | "'" | '*' | '?' | '[' | ']' | '{' | '}' | '(' | ')' | '#')
escaped="${escaped}\\${char}" escaped="${escaped}\\${char}"
;; ;;
*) *)
escaped="${escaped}${char}" escaped="${escaped}${char}"
;; ;;
esac esac
done <<< "$input" done <<<"$input"
echo "$escaped" echo "$escaped"
} }
@@ -200,12 +206,12 @@ if $filter_mode; then
files_to_delete=() files_to_delete=()
files_count=${#files[@]} files_count=${#files[@]}
for ((i = 0; i < files_count;)); do for ((i = 0; i < files_count; )); do
file="${files[$i]}" file="${files[$i]}"
file="${file#./}" file="${file#./}"
echo "" echo ""
echo "($((i+1))/${files_count}) File: $file" echo "($((i + 1))/${files_count}) File: $file"
echo -n "Should this file be deleted? (y/n): " echo -n "Should this file be deleted? (y/n): "
confirm confirm
@@ -213,26 +219,25 @@ if $filter_mode; then
should_undo=false should_undo=false
case $confirm_result in case $confirm_result in
0) 0)
if [[ ! ${files_to_delete[@]} =~ $file ]]; then if [[ ! ${files_to_delete[@]} =~ $file ]]; then
files_to_delete+=("$file") files_to_delete+=("$file")
fi fi
;; ;;
1) 1) ;;
;; 2)
2) if ((i - 1 < 0)); then
if (( i - 1 < 0 )); then echo ""
echo "" echo ""
echo "" echo "Can't undo because this is the first image"
echo "Can't undo because this is the first image" continue
continue else
else ((i--))
((i--)) xdotool search --name feh key p
xdotool search --name feh key p files_to_delete=("${files_to_delete[@]/$file/}")
files_to_delete=("${files_to_delete[@]/$file}") continue
continue fi
fi ;;
;;
esac esac
xdotool search --name feh key n xdotool search --name feh key n
@@ -265,10 +270,10 @@ if $filter_mode; then
done done
else else
if [ -f "$furry_commission_ideas_urls_filename" ] && grep -qE "$media_url" -i "$furry_commission_ideas_urls_filename"; then if [ -f "$furry_commission_ideas_urls_filename" ] && grep -qE "$media_url" -i "$furry_commission_ideas_urls_filename"; then
printf "\n" printf "\n"
echo "[INFO] This folder already has the media informed." echo "[INFO] This folder already has the media informed."
echo "[INFO] Exiting..." echo "[INFO] Exiting..."
exit 0 exit 0
fi fi
if ! command_output=$($scripts_path/gdl.sh $media_url); then if ! command_output=$($scripts_path/gdl.sh $media_url); then
@@ -278,14 +283,13 @@ else
media_filenames=() media_filenames=()
for ((i = 0; i < ${#command_output[@]}; i++)); do for ((i = 0; i < ${#command_output[@]}; i++)); do
filename=${command_output[$i]} filename=${command_output[$i]}
media_filenames+=$(basename "$filename") media_filenames+=$(basename "$filename")
done done
for ((i = 0; i < ${#media_filenames[@]}; i++)); do for ((i = 0; i < ${#media_filenames[@]}; i++)); do
media_filename=${media_filenames[$i]} media_filename=${media_filenames[$i]}
echo "$media_filename: $media_url" >> $furry_commission_ideas_urls_filename echo "$media_filename: $media_url" >>$furry_commission_ideas_urls_filename
done done
fi fi