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,7 +1,7 @@
#!/bin/bash
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 " --input|-i Specify the input video file (required)."
echo " --crop|-c Specify the width:height for video cropping."
@@ -9,7 +9,7 @@ show_help() {
echo " --trim-end Specify the end timestamp for video trimming."
echo " --crf Specify the CRF value for video compressing."
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 " --remove-audio Suppress all audio and remove audio tracks."
echo " --audio-track-no Selects a specific audio track for the output"
@@ -23,7 +23,7 @@ remove_audio() {
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."
exit 1
fi
@@ -34,7 +34,7 @@ trim_start=""
trim_end=""
crf=""
new_fps=""
scale640=false
scale=""
merge_audio=false
remove_audio=false
audio_track_no=1
@@ -42,18 +42,54 @@ output_file=""
while [ "$#" -gt 0 ]; do
case "$1" in
--help|-h) show_help; exit ;;
--input|-i) input_file="$2"; shift 2 ;;
--crop|-c) crop="$2"; shift 2 ;;
--trim-start) trim_start="$2"; shift 2 ;;
--trim-end) trim_end="$2"; shift 2 ;;
--crf) crf="$2"; shift 2 ;;
--fps) new_fps="$2"; shift 2 ;;
--scale640) scale640=true; shift ;;
--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 ;;
--help | -h)
show_help
exit
;;
--input | -i)
input_file="$2"
shift 2
;;
--crop | -c)
crop="$2"
shift 2
;;
--trim-start)
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
@@ -68,7 +104,7 @@ if [ -z "$output_file" ]; then
exit 1
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."
exit 1
fi
@@ -83,8 +119,8 @@ if [ -n "$trim_end" ] && [ -z "$trim_start" ]; then
exit 1
fi
if [ -n "$crop" ] && [ "$scale640" = true ]; then
echo "Error: Cannot use both --crop and --scale640 together."
if [ -n "$crop" ] && [ "$scale" = true ]; then
echo "Error: Cannot use both --crop and --scale together."
exit 1
fi
@@ -122,15 +158,15 @@ if [ -n "$trim_start" ] && [ -n "$trim_end" ]; then
fi
if [ -n "$crf" ]; then
ffmpeg_command+=" -c:v libx264 -crf $crf"
ffmpeg_command+=" -c:v libx265 -crf $crf"
fi
if [ -n "$new_fps" ]; then
ffmpeg_command+=" -r $new_fps"
fi
if [ "$scale640" = true ]; then
ffmpeg_command+=" -vf scale=640:320"
if [ -n "$scale" ]; then
ffmpeg_command+=" -s $scale"
fi
if [ "$merge_audio" = true ]; then

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")
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() {
# 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 " --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"
@@ -11,8 +11,14 @@ show_help() {
filter_mode=false
while [ "$#" -gt 0 ]; do
case "$1" in
--help|-h) show_help; exit ;;
--filter-mode|-f) filter_mode=true; shift;;
--help | -h)
show_help
exit
;;
--filter-mode | -f)
filter_mode=true
shift
;;
*) shift ;;
esac
done
@@ -21,7 +27,7 @@ commands_to_check=(gallery-dl gdl.sh feh xdotool)
commands_not_found=()
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")
fi
done
@@ -36,8 +42,8 @@ if [ ${#commands_not_found[@]} -ne 0 ]; then
exit 1
fi
cur_dir=`pwd`
furry_commission_ideas_path=/mnt/e/home/documents/data-hoarding/furry-commission-ideas
cur_dir=$(pwd)
furry_commission_ideas_path=/mnt/e/home/documents/downloads-furry
furry_commission_ideas_urls_filename="urls.txt"
scripts_path=/home/cloud/repos/personal-devboot/scripts/shell
@@ -59,13 +65,13 @@ input_media_url() {
media_url=''
if ! $filter_mode; then
media_url=`input_media_url`
media_url=$(input_media_url)
while [ -z "$media_url" ]; do
media_url=`input_media_url`
media_url=$(input_media_url)
done
# remove trailing slashes
media_url=`sed 's:/*$::' <<< "$media_url"`
media_url=$(sed 's:/*$::' <<<"$media_url")
url_regex='(https?)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]'
if [[ ! $media_url =~ $url_regex ]]; then
@@ -83,8 +89,8 @@ filtered_existing_folders=()
# removing artists folder depth 2 only
for folder in "${existing_folders[@]}"; do
if [[ ! $folder =~ ^artists/[^/]+$ ]]; then
filtered_existing_folders+=( "$folder" )
fi;
filtered_existing_folders+=("$folder")
fi
done
existing_folders=("${filtered_existing_folders[@]}")
@@ -117,9 +123,9 @@ input_select_folder() {
read -p "[INFO] Please inform the desired option: " selected_option
if [ "$selected_option" == 'n' ]; then
selected_folder=`input_create_folder`
selected_folder=$(input_create_folder)
while [ -z "$selected_folder" ]; do
selected_folder=`input_create_folder`
selected_folder=$(input_create_folder)
done
mkdir --parents "$selected_folder"
@@ -142,9 +148,9 @@ if [ -z "$selected_folder" ]; then
printf "\n"
selected_folder=`input_select_folder`
selected_folder=$(input_select_folder)
while [ -z "$selected_folder" ]; do
selected_folder=`input_select_folder`
selected_folder=$(input_select_folder)
done
fi
@@ -154,11 +160,11 @@ function confirm() {
while true; do
read -n 1 yn
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
[Uu]* ) return 2;;
[Cc]* ) exit;;
* ) echo "Please answer YES, NO, or CANCEL.";;
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
[Uu]*) return 2 ;;
[Cc]*) exit ;;
*) echo "Please answer YES, NO, or CANCEL." ;;
esac
done
}
@@ -170,14 +176,14 @@ escape_string() {
# Iterate over each character in the input string
while IFS= read -r -n1 char; do
case "$char" in
' '|'\'|'$'|'`'|'!'|'&'|'|'|';'|'<'|'>'|'"'|"'"|'*'|'?'|'['|']'|'{'|'}'|'('|')'|'#')
' ' | '\' | '$' | '`' | '!' | '&' | '|' | ';' | '<' | '>' | '"' | "'" | '*' | '?' | '[' | ']' | '{' | '}' | '(' | ')' | '#')
escaped="${escaped}\\${char}"
;;
*)
escaped="${escaped}${char}"
;;
esac
done <<< "$input"
done <<<"$input"
echo "$escaped"
}
@@ -200,12 +206,12 @@ if $filter_mode; then
files_to_delete=()
files_count=${#files[@]}
for ((i = 0; i < files_count;)); do
for ((i = 0; i < files_count; )); do
file="${files[$i]}"
file="${file#./}"
echo ""
echo "($((i+1))/${files_count}) File: $file"
echo "($((i + 1))/${files_count}) File: $file"
echo -n "Should this file be deleted? (y/n): "
confirm
@@ -218,10 +224,9 @@ if $filter_mode; then
files_to_delete+=("$file")
fi
;;
1)
;;
1) ;;
2)
if (( i - 1 < 0 )); then
if ((i - 1 < 0)); then
echo ""
echo ""
echo "Can't undo because this is the first image"
@@ -229,7 +234,7 @@ if $filter_mode; then
else
((i--))
xdotool search --name feh key p
files_to_delete=("${files_to_delete[@]/$file}")
files_to_delete=("${files_to_delete[@]/$file/}")
continue
fi
;;
@@ -282,10 +287,9 @@ else
media_filenames+=$(basename "$filename")
done
for ((i = 0; i < ${#media_filenames[@]}; i++)); do
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
fi