General Enhancements (#51)

* Fix website not being trashed during reseed.

* Fix port flags.

* Fix errors about comments by being sneaky.

* Add `encfs`.

* Leave the audio alone when compressing videos unless explicitly requested.

* ffmpeg seems to default to 128k audio, raise it to 192k.

* Handle `time` not being installed more gracefully.

* Add audio normlization per Cahlen Lee.

* Try preventing directories from being renamed.

* Add ability to resize videos, similar to process-video in my Termux project's bashrc.

* Add an -A parameter similar to compress_image.sh.

* Handle uppercase extensions, use TRASH for old compressed copies if it exists, print the FFMPEG command.

* Add datestamps around the conversion.

* Maxrate has been working well in Termux project, use it on desktop too, but don't worry about 2-pass.

* Automatically source Docker environment for using manage.sh if user is root and file exists.

* Add android studio.

* Add missing pipes.

* Stop including Nix, inclue TTT, add git stash to reset.
This commit is contained in:
Hyperling 2024-05-16 10:00:49 -07:00 committed by GitHub
parent 04a980a7a3
commit 742f225de1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 95 additions and 34 deletions

View File

@ -20,6 +20,7 @@
microcode_amd: amd64-microcode
microcode_intel: intel-microcode
cron: cron
encfs: encfs
when: ansible_pkg_mgr == "apt"
- name: General | Facts | Package | pacman
@ -29,6 +30,7 @@
microcode_amd: linux-firmware
microcode_intel: intel-ucode
cron: cronie
encfs: encfs
when: ansible_pkg_mgr == "pacman"
- name: General | Facts | Package | FreeBSD
@ -40,6 +42,7 @@
tar: htop # tar already provided in FreeBSD
microcode_amd: htop # TODO
microcode_intel: htop # TODO
encfs: fusefs-encfs
when: ansible_system == "FreeBSD"
- name: General | Facts | Package | dnf
@ -50,6 +53,7 @@
microcode_amd: microcode_ctl
microcode_intel: microcode_ctl
cron: cronie
encfs: fuse-encfs
when: ansible_pkg_mgr == "dnf"
- name: General | Facts | Package | zypper
@ -59,6 +63,7 @@
microcode_amd: ucode-amd
microcode_intel: ucode-intel
cron: cronie
encfs: encfs
when: ansible_pkg_mgr == "zypper"

View File

@ -106,14 +106,23 @@ $search "$location" | sort | while read image; do
continue
fi
new_image="${image//.$extension/}.$tag-$date_YYYYMMDD.$extension"
## Clean Filename ##
# Prevent directory from having its name cleaned too.
image_dirname="`dirname $new_image`"
image_basename="`basename $new_image`"
# Clean the filename of extra junk so that they can be chronological order.
new_image_clean="${new_image//IMG/}"
new_image_clean="${image_basename//IMG/}"
new_image_clean="${new_image_clean//_/}"
new_image_clean="${new_image_clean//-/}"
new_image_clean="${new_image_clean// /}"
# Add directory back to the full path.
new_image_clean="$image_dirname/$new_image_clean"
# Delete the existing shrunk image if we are forcing a new compression.
if [[ -n "$force" && (-e "$new_image" || -e $new_image_clean) ]]; then
echo -n " FORCE: "
@ -131,9 +140,9 @@ $search "$location" | sort | while read image; do
new_image="$new_image_clean"
fi
### TBD Instead of this, only alter the file names, and set a dirname var?
# Create a new directory if the directory names were altered.
mkdir -pv "`dirname "$new_image"`"
###### TBD Instead of this, only alter the file names, and set a dirname var?
#### Create a new directory if the directory names were altered.
###mkdir -pv "`dirname "$new_image"`"
# This modifies the image to be $size at its longest end, not be a square.
$convert_exe "$image" -resize ${size}x${size} "$new_image"

View File

@ -2,6 +2,11 @@
# 2023-06-13 Hyperling
# Compress a video to good-enough quality for high quality streaming.
## FFMpeg Notes ##
# 2024-02-08
# -af parameter comes from Cahlen Lee's recommendation:
# https://odysee.com/@HyperVegan:2/20240205_DesertSilence-Campfire:3?lc=a2439b26d9fe89a950e0a47ec1d110d7156f596843039b4b76a4a2f327afcd2f
## Setup ##
DIR="$(dirname -- "${BASH_SOURCE[0]}")"
@ -17,7 +22,7 @@ large_created=".$PROG.large_created.true"
function usage {
echo -n "Usage: $PROG [-i file/folder] [-v bitrate] [-a bitrate] [-c vcodec]"
echo " [-r] [-f] [-d] [-m] [-V] [-x] [-h]"
echo " [-s size] [-r] [-f] [-d] [-A] [-m] [-V] [-x] [-h]"
cat <<- EOF
Reduce the filesize of a video file to make it stream well. It also
helps with the file size for placing the file into a backup system.
@ -26,12 +31,17 @@ function usage {
Parameters:
-i input : The input file or folder with which to search for video files.
If nothing is provided, current directory (.) is assumed.
-v bitrate : The video bitrate to convert to, defaults to 2000k.
-a bitrate : The audio bitrate to convert to, defaults to 128k.
-v bitrate : The video bitrate to convert to.
Defaults to '2000k'.
-a bitrate : The audio bitrate to convert to.
Defaults to '192k'.
-c vcodec : The video codec you'd like to use, such as libopenh264.
-s size : The video size such as 1080 or 720, or1280 for vertical 720p.
Defaults to '720'.
-r : Recurse the entire directory structure, compressing all video files.
-f : Force recompressing any files by deleting it if it already exists.
-d : Delete the original video if the compressed version is smaller.
-A : Recursively Force and Delete.
-m : Measure the time it takes to compress each video and do the loop.
-V : Add verbosity, such as printing all the variable values.
-x : Set the shell's x flag to display every action which is taken.
@ -42,7 +52,7 @@ function usage {
## Parameters ##
while getopts ":i:v:a:c:rfdmVxh" opt; do
while getopts ":i:v:a:c:s:rfdAmVxh" opt; do
case $opt in
i) input="$OPTARG"
;;
@ -50,7 +60,9 @@ while getopts ":i:v:a:c:rfdmVxh" opt; do
;;
a) audio_bitrate="$OPTARG"
;;
c) codec="-vcodec $OPTARG"
c) codec="$OPTARG"
;;
s) size="$OPTARG"
;;
r) search_command="find"
;;
@ -58,7 +70,9 @@ while getopts ":i:v:a:c:rfdmVxh" opt; do
;;
d) delete="Y"
;;
m) time_command="time -p"
A) search_command="find" && force="Y" && delete="Y"
;;
m) time_command="`which time`"
;;
V) verbose="Y"
;;
@ -77,20 +91,24 @@ if [[ "$set_x" == "Y" ]]; then
fi
if [[ -z "$input" ]]; then
echo "WARNING: Program was not passed an input. Using current directory."
echo "WARNING: Program was not passed an input. Using current directory." >&2
input="."
fi
if [[ -z "$video_bitrate" ]]; then
video_bitrate="2000k"
fi
video_bitrate="-maxrate $video_bitrate"
if [[ -z "$audio_bitrate" ]]; then
audio_bitrate="128k"
audio_bitrate="192k"
fi
audio_bitrate="-b:a $audio_bitrate"
if [[ -z "$codec" ]]; then
codec=""
else
codec="-vcodec $codec"
fi
if [[ -z "$search_command" ]]; then
@ -99,8 +117,15 @@ fi
if [[ -z "$time_command" ]]; then
time_command=""
else
time_command="$time_command -p"
fi
if [[ -z $size ]]; then
size="720"
fi
size="-filter:v scale=-1:$size"
## Main ##
if [[ "$verbose" == "Y" ]]; then
@ -130,8 +155,12 @@ $search_command "$input" | sort | while read file; do
date
fi
typeset -l extension_lower
extension="${file##*.}"
extension_lower="$extension"
# Exception checks for the existing file.
if [[ "$file" != *'.mp4' ]]; then
if [[ "$extension_lower" != "mp4" ]]; then
echo "SKIP: Not an MP4."
continue
fi
@ -141,20 +170,22 @@ $search_command "$input" | sort | while read file; do
fi
# Build the new filename to signify it is different than the original.
extension="${file##*.}"
newfile="${file//$extension/$filename_flag-$date_YYYYMMDD.$extension}"
newfile="${file//$extension/$filename_flag-$date_YYYYMMDD.$extension_lower}"
#### Convert spaces to underscores.
###newfile="${newfile// /_}"
###
#### Ensure any directories that had spaces get recreated without them.
###mkdir -pv "`dirname "$newfile"`"
if [[ $newfile == $file ]]; then
echo "ERROR: The new calculated filename matches the old, skipping." >&2
continue
fi
# More exception checks based on the new file.
if [[ -e "$newfile" ]]; then
if [[ "$force" == "Y" ]]; then
echo "FORCE: Removing '$newfile'."
rm -vf "$newfile"
if [[ -d ~/TRASH ]]; then
mv -v "$newfile" ~/TRASH/
else
rm -v "$newfile"
fi
else
echo "SKIP: Already has a compressed version ($newfile)."
continue
@ -163,10 +194,16 @@ $search_command "$input" | sort | while read file; do
# Convert the file.
echo "Converting to '$newfile'."
echo "*** `date` ***"
set -x
$time_command bash -c "ffmpeg -nostdin -hide_banner -loglevel quiet \
-i '$file' -b:v $video_bitrate -b:a $audio_bitrate \
$vcodec -movflags +faststart '$newfile'"
-i '$file' $size $video_bitrate $audio_bitrate \
-af 'dynaudnorm=f=33:g=65:p=0.66:m=33.3' \
$vcodec -movflags +faststart \
'$newfile'"
status="$?"
set +x
echo "*** `date` ***"
if [[ "$status" != 0 ]]; then
echo "SKIP: ffmpeg returned a status of '$status'."
continue
@ -186,7 +223,7 @@ $search_command "$input" | sort | while read file; do
if [[ -e "$newfile" ]]; then
echo "Conversion succeeded, file has been compressed."
else
echo "ERROR: Converted file '$newfile' could not be found. Aborting."
echo "ERROR: Converted file '$newfile' could not be found. Aborting." >&2
break
fi

View File

@ -69,17 +69,17 @@ if [[ -n $input ]]; then
if [[ $receive == "N" ]]; then
echo -n "Sending '$input' from localhost to '$user@$destination' "
echo " at '$output' using port '$port'."
scp -r -p$port "$user@[$destination]":"$input" "$output"
scp -r -P$port "$user@[$destination]":"$input" "$output"
elif [[ $receive == "Y" ]]; then
echo -n "Receiving '$input' from '$user@$destination' "
echo " to '$output' on localhost using port '$port'."
scp -r -p$port "$input" "$user@[$destination]":"$output"
scp -r -P$port "$input" "$user@[$destination]":"$output"
else
echo "ERROR: Receive variable is screwed up. $receive" >&2
fi
else
echo "No input file provided, connecting to destination."
ssh -t $user@$destination
ssh -t -p$port $user@$destination
fi
date

View File

@ -1,7 +1,8 @@
// Needs saved as:
// ~/.var/app/com.visualstudio.code-oss/config/Code - OSS/{{ user_desc }}/settings.json
// ~/.var/app/com.vscodium.codium/config/VSCodium/{{ user_desc }}/settings.json
{
"BEGIN_COMMENTS": "",
"save_loc1": "~/.var/app/com.visualstudio.code-oss/config/Code - OSS/{{ user_desc }}/settings.json",
"save_loc2": "~/.var/app/com.vscodium.codium/config/VSCodium/{{ user_desc }}/settings.json",
"END_COMMENTS": "",
"workbench.startupEditor": "none",
"editor.rulers": [
80, 120, 200

View File

@ -397,6 +397,7 @@
ls -d ~/Code/* | while read project
do echo "*** `basename $project` ***"
cd $project
git stash
git switch main
git pull
git branch -D dev
@ -407,7 +408,7 @@
alias code-reseed='
unseed_dir="$HOME/TRASH/`date +%Y-%m-%d`_UnseededCodeProjects"
mkdir -pv "$unseed_dir"
mv -v ~/Code/*{ansible,docker,nix,break,habit}* \
mv -v ~/Code/*{ansible,docker,nix,break,website,www,tictactoe,-dev}* \
"$unseed_dir"/ 2>/dev/null
git clone git@github.com:Hyperling/Ansible \
--branch dev ~/Code/ansible-dev
@ -415,10 +416,10 @@
--branch dev ~/Code/docker-dev
git clone git@github.com:Hyperling/Website \
--branch dev ~/Code/website-dev
git clone git@github.com:Hyperling/NixOS \
--branch dev ~/Code/nixos-dev
git clone git@github.com:Hyperling/BreakTheHabit \
--branch dev ~/Code/breakthehabit-dev
git clone git@github.com:Hyperling/TicTacToeAndroid \
--branch dev ~/Code/tictactoe-dev
'
function_clean_filenames: |
function clean-filenames() {
@ -451,10 +452,15 @@
}
alias_clone: |
alias clone="rsync -auPh --delete"
export_hyperling:
export_hyperling: |
export HYPERLING6="2a07:e03:3:80::1"
export HYPERLING4="185.130.47.173"
export HYPERLING="$HYPERLING4"
source_docker_env: |
DOCKER_SOURCE="/opt/Docker/source.env"
if [[ -e $DOCKER_SOURCE && $LOGNAME == "root" ]]; then
source $DOCKER_SOURCE
fi
- name: General | Account Management | Users | Files | Common Variable
set_fact:
@ -494,6 +500,7 @@
{{ function_clean_filenames_tree }}
{{ alias_clone }}
{{ export_hyperling }}
{{ source_docker_env }}
- name: General | Account Management | Users | Files | .bashrc
blockinfile:

View File

@ -54,6 +54,7 @@
- gcc
- vim
- "{{ cron }}"
- "{{ encfs }}"
state: present
- name: General | Software | Packages | Install Software (DEV)

View File

@ -13,6 +13,7 @@
, 'io.gitlab.librewolf-community.desktop', 'librewolf.desktop'
, 'org.mozilla.firefox.desktop', 'firefox.desktop'
, 'com.visualstudio.code-oss.desktop', 'code-oss.desktop'
, 'com.google.AndroidStudio.desktop'
, 'org.godotengine.Godot.desktop'
, 'org.shotcut.Shotcut.desktop'
, 'io.lbry.lbry-app.desktop', 'lbry.desktop'