mirror of
https://github.com/tanrax/bash-folders.git
synced 2024-11-09 20:55:40 +01:00
Add zip
This commit is contained in:
parent
127f6dba2b
commit
ebe72e8b13
87
bash-folders-decompress.sh
Normal file → Executable file
87
bash-folders-decompress.sh
Normal file → Executable file
@ -1,12 +1,12 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# --
|
# --
|
||||||
# Description: Script that watches when new videos are added to a folder and optimizes them.
|
# Description: Script that decompresses all the files that are left in the folder.
|
||||||
|
# --nnnnnnn
|
||||||
|
# Requirements: Install inotify-tools, gzip bzip2 xz-utils unzip p7zip-full and unrar
|
||||||
|
# Example Debian: $sudo apt install inotify-tools gzip bzip2 xz-utils unzip p7zip-full unrar
|
||||||
# --
|
# --
|
||||||
# Requirements: Install inotify-tools and ffmpeg
|
# Cron: @reboot bash-folders-descompress.sh >/dev/null 2>&1 &
|
||||||
# Example Debian: $sudo apt install inotify-tools ffmpeg
|
|
||||||
# --
|
|
||||||
# Cron: @reboot dynamic-folders-video-optimizer.sh >/dev/null 2>&1 &
|
|
||||||
# --
|
# --
|
||||||
|
|
||||||
# START
|
# START
|
||||||
@ -19,7 +19,7 @@ export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/user
|
|||||||
# VARIABLES
|
# VARIABLES
|
||||||
PROGNAME=$(basename "$0")
|
PROGNAME=$(basename "$0")
|
||||||
FOLDER_ORIGIN="$2"
|
FOLDER_ORIGIN="$2"
|
||||||
EXTENSIONS_TO_WATCH=("mkv" "mp4" "avi" "mov")
|
EXTENSIONS_TO_WATCH=("gzip" "bzip2" "xz" "zip" "7z" "rar")
|
||||||
|
|
||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
|
|
||||||
@ -30,9 +30,9 @@ usage() {
|
|||||||
|
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Usage: $PROGNAME [OPTION]
|
Usage: $PROGNAME [OPTION]
|
||||||
Watches when new videos are added to a folder and optimizes them.
|
Watches new compress files and decompresses all the files.
|
||||||
Options:
|
Options:
|
||||||
--folder [path] Folder path where new video will be monitored and optimized
|
--folder [path] Folder path where will be monitored.
|
||||||
--help Display this usage message and exit
|
--help Display this usage message and exit
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@ -56,50 +56,39 @@ start() {
|
|||||||
while read -r filename; do
|
while read -r filename; do
|
||||||
# Gets the file extension
|
# Gets the file extension
|
||||||
extension="${filename##*.}"
|
extension="${filename##*.}"
|
||||||
|
filepath=$(readlink -f "$FOLDER_ORIGIN/$filename")
|
||||||
# Checks if the extension is in the extension list
|
# Checks if the extension is in the extension list
|
||||||
for ext in "${EXTENSIONS_TO_WATCH[@]}"; do
|
for ext in "${EXTENSIONS_TO_WATCH[@]}"; do
|
||||||
if [[ "$ext" = "$extension" ]]; then
|
if [[ "$ext" = "$extension" ]]; then
|
||||||
# Check if the file name starts with "optimized"
|
# Notifies that the conversion is to be started
|
||||||
if [[ "$filename" != optimized* ]]; then
|
send-notification "Descompressing '$filename', please wait."
|
||||||
# Notifies that the conversion is to be started
|
# Decompresses the file
|
||||||
send-notification "Optimizing $filename ..."
|
filetype=$(file -b "$filepath" | awk '{print $1}')
|
||||||
# Convert the file to MP4 format using ffmpeg
|
case "$filetype" in
|
||||||
|
"gzip")
|
||||||
# sudo apt-get install gzip bzip2 xz-utils unzip p7zip-full unrar
|
gzip -d "$filepath"
|
||||||
|
;;
|
||||||
filename="$1"
|
"bzip2")
|
||||||
filetype=$(file -b "$filename" | awk '{print $1}')
|
bzip2 -d "$filepath"
|
||||||
|
;;
|
||||||
case "$filetype" in
|
"XZ")
|
||||||
"gzip")
|
xz -d "$filepath"
|
||||||
gzip -d "$filename"
|
;;
|
||||||
;;
|
"Zip")
|
||||||
"bzip2")
|
unzip "$filepath"
|
||||||
bzip2 -d "$filename"
|
;;
|
||||||
;;
|
"7-zip")
|
||||||
"XZ")
|
7z x "$filepath"
|
||||||
xz -d "$filename"
|
;;
|
||||||
;;
|
"RAR")
|
||||||
"Zip")
|
unrar x "$filepath"
|
||||||
unzip "$filename"
|
;;
|
||||||
;;
|
*)
|
||||||
"7-zip")
|
send-notification "Error: Unknown file type $filetype"
|
||||||
7z x "$filename"
|
;;
|
||||||
;;
|
esac
|
||||||
"RAR")
|
# Notifies that it has been terminated
|
||||||
unrar x "$filename"
|
send-notification "Descompressing $filename finished."
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Tipo de archivo desconocido: $filetype"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Notifies that it has been terminated
|
|
||||||
send-notification "Completed! Output: optimized_${filename%.*}.mp4"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user