Add First Script - Video Compression (#40)

* Script is working well. Maybe not its final resting place but adding it to the repo here for now.

* Add Signal to favorites after Delta Chat.

* Fix the a and v parameters never being used.

* New file to copy all scripts to /usr/local/bin/.

* Call the new file which installs everything under files/scripts/.
This commit is contained in:
Hyperling 2023-06-25 15:00:59 -07:00 committed by GitHub
parent f8b791bbd2
commit 6d2b20aafe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 116 additions and 7 deletions

89
files/scripts/compress-video.sh Executable file
View File

@ -0,0 +1,89 @@
#!/bin/bash
# 2023-06-13 Hyperling
# Compress a video to good-enough quality for high quality streaming.
DIR=`dirname $0`
PROG=`basename $0`
if [[ $DIR == '.' ]]; then
DIR=`pwd`
fi
echo "Running $DIR/$PROG"
## Functions
function usage {
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.
Parameters:
-f 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.
-h : Display this help messaging.
EOF
exit $1
}
## Parse Input
while getopts ":f:v:a:h" opt; do
case $opt in
f)
input="$OPTARG"
;;
v)
video_bitrate="$OPTARG"
;;
a)
audio_bitrate="$OPTARG"
;;
h)
usage 0
;;
esac
done
if [[ -z $input && ! -z $1 ]]; then
echo "WARNING: Program was not passed a file. Using input 1."
input=$1
else
echo "WARNING: Program was not passed a file. Using current directory."
input='.'
fi
if [[ -z $video_bitrate ]]; then
video_bitrate='2000k'
fi
if [[ -z $audio_bitrate ]]; then
audio_bitrate='128k'
fi
## Other Variables
filename_flag='compressed.'
## Main Loop
ls $input | while read file; do
## Exception Checks
if [[ $file != *'.mp4' && $file != *'.mpeg' ]]; then
echo "Skipping $file, not an MP4 or MPEG."
continue
fi
# Build the new filename to signify it is different thn the original.
extension=${file##*.}
newfile=${file//$extension/$filename_flag$extension}
if [[ $file == *"$filename_flag"* || -e $newfile ]]; then
echo "Skipping $file, already compressed."
continue
fi
# Convert the file.
echo "Converting $file to $newfile."
ffmpeg -nostdin -hide_banner -loglevel quiet \
-i $file -b:v $video_bitrate -b:a $audio_bitrate \
$newfile
done
exit 0

View File

@ -30,6 +30,7 @@
- include_tasks: tasks/general/scripts/root.yml
- include_tasks: tasks/general/scripts/user.yml
- include_tasks: tasks/general/scripts/install.yml
- include_tasks: tasks/general/cron/ansible.yml

View File

@ -0,0 +1,16 @@
---
# Copy everything from PROJECT/files/scripts/ to /usr/local/bin/.
- name: General | Scripts | Install | Ensure Directory Exists
ansible.builtin.file:
path: '{{ global_bin }}'
state: directory
mode: '0755'
- name: General | Scripts | Install | Copy Files
copy:
src: 'scripts/'
dest: "{{ global_bin }}/"
owner: root
group: "{{ root_group }}"
mode: '0755'

View File

@ -167,13 +167,16 @@
- name: Workstation | Account Management | GNOME | Favorites (Linux)
dconf:
key: /org/gnome/shell/favorite-apps
value: "['org.gnome.Terminal.desktop', 'gnome-system-monitor.desktop', 'org.gnome.Nautilus.desktop'
,'io.gitlab.librewolf-community.desktop', '{{ browser }}', 'org.gnome.Evolution.desktop'
,'chat.delta.desktop.desktop'
,'com.vscodium.codium.desktop', 'org.shotcut.Shotcut.desktop'
,'org.telegram.desktop.desktop', 'com.discordapp.Discord.desktop', 'im.riot.Riot.desktop'
,'io.lbry.lbry-app.desktop'
,'com.valvesoftware.Steam.desktop'
value: "[ 'org.gnome.Terminal.desktop', 'gnome-system-monitor.desktop'
, 'org.gnome.Nautilus.desktop'
, 'io.gitlab.librewolf-community.desktop', '{{ browser }}'
, 'org.gnome.Evolution.desktop', 'chat.delta.desktop.desktop'
, 'org.signal.Signal.desktop'
, 'com.vscodium.codium.desktop', 'org.shotcut.Shotcut.desktop'
, 'org.telegram.desktop.desktop', 'com.discordapp.Discord.desktop'
, 'im.riot.Riot.desktop'
, 'io.lbry.lbry-app.desktop'
, 'com.valvesoftware.Steam.desktop'
]"
state: present
become_user: "{{ user }}"