From 6d2b20aafecc04d89c37e65000e6a5680651a714 Mon Sep 17 00:00:00 2001 From: Chad Date: Sun, 25 Jun 2023 15:00:59 -0700 Subject: [PATCH] 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/. --- files/scripts/compress-video.sh | 89 +++++++++++++++++++++ local.yml | 1 + tasks/general/scripts/install.yml | 16 ++++ tasks/workstation/shared/settings/gnome.yml | 17 ++-- 4 files changed, 116 insertions(+), 7 deletions(-) create mode 100755 files/scripts/compress-video.sh create mode 100644 tasks/general/scripts/install.yml diff --git a/files/scripts/compress-video.sh b/files/scripts/compress-video.sh new file mode 100755 index 0000000..04c6ded --- /dev/null +++ b/files/scripts/compress-video.sh @@ -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 diff --git a/local.yml b/local.yml index 37052fa..decc67a 100644 --- a/local.yml +++ b/local.yml @@ -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 diff --git a/tasks/general/scripts/install.yml b/tasks/general/scripts/install.yml new file mode 100644 index 0000000..8714f99 --- /dev/null +++ b/tasks/general/scripts/install.yml @@ -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' diff --git a/tasks/workstation/shared/settings/gnome.yml b/tasks/workstation/shared/settings/gnome.yml index ea7c696..d5b3f88 100644 --- a/tasks/workstation/shared/settings/gnome.yml +++ b/tasks/workstation/shared/settings/gnome.yml @@ -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 }}"