Compare commits

...

54 commits

Author SHA1 Message Date
PedoDeveloper
3f600541ab Undo test commit -
PedoDeveloper
4748def178 Merge branch 'master' of http://onion.tor.my/PedoDeveloper/autoshare -
sometimesuseful
3e76fc49b0 added logging for when the input file is smaller than volume size 2024-11-13 16:08:48 +00:00
sometimesuseful
665e356842 fixed bug where volumes argument would be set to an invalid value 2024-11-13 16:08:48 +00:00
sometimesuseful
9b013d9996 fixed unbound variable error and missing function parameter 2024-11-13 16:08:48 +00:00
sometimesuseful
34529d3372 move some things around for improved readability 2024-11-13 16:08:48 +00:00
sometimesuseful
42bf72e127 remove error handling for mkdir, it's unlikely to fail and the script would exit on error due to set -e anyway 2024-11-13 16:08:15 +00:00
sometimesuseful
0ec24ecaf2 remove unused function parameter 2024-11-13 15:13:24 +00:00
PedoDeveloper
ee40a3b439 Fixed broken source statement 2024-11-13 12:13:26 +00:00
PedoDeveloper
f897c8c2a5 Fixed link 2024-11-13 12:02:00 +00:00
PedoDeveloper
93dd385cbe Renamed modules 2024-11-13 11:58:34 +00:00
PedoDeveloper
7da917274b Small code improvements 2024-11-13 11:58:07 +00:00
PedoDeveloper
ac4da0bab7 Merged colors.sh with functions.sh, moved to separate 'includes' directory 2024-11-13 11:54:58 +00:00
PedoDeveloper
c84085236d Fixed spacing 2024-11-13 11:52:26 +00:00
PedoDeveloper
3ea5fcfa15 Made if statements more concise 2024-11-13 11:51:36 +00:00
PedoDeveloper
5d9436d92c Changed && to ; 2024-11-13 11:50:03 +00:00
PedoDeveloper
596426e5a8 Added message for collaborators 2024-11-13 11:48:23 +00:00
sometimesuseful
ceb331eb10 stop leaking dependency variable 2024-11-13 03:10:19 +00:00
sometimesuseful
cebc024117 shellcheck 2024-11-13 02:40:59 +00:00
sometimesuseful
5eaa4863f7 improved logging 2024-11-13 02:33:39 +00:00
sometimesuseful
2f71885690 changed name from set_volumes to get_volumes to more accurately describe what the function does 2024-11-13 02:19:51 +00:00
sometimesuseful
713fbbb29a minor comment changes 2024-11-13 02:14:30 +00:00
sometimesuseful
20f311b7d6 fixed function call to log 2024-11-13 02:12:49 +00:00
sometimesuseful
4bbeec2230 use bash builtin instead of basename 2024-11-12 17:19:46 +00:00
sometimesuseful
904aa642e1 remove useless if-statement 2024-11-12 17:17:25 +00:00
sometimesuseful
2ec3e333e5 minor change + shellcheck 2024-11-12 17:09:39 +00:00
sometimesuseful
006ecbe7d4 fixed non-local variables, changed variable names, other minor fixes 2024-11-12 17:02:39 +00:00
sometimesuseful
96e65508d1 shellcheck 2024-11-12 16:04:51 +00:00
sometimesuseful
8ebb5071a4 added strict mode, fixed unbound variables caused by it 2024-11-12 16:03:02 +00:00
sometimesuseful
ebbc407b93 removed unnecessary source, fixed logging messages, refactored functions to work in a more traditional functional style rather than relying on global values 2024-11-12 15:55:33 +00:00
sometimesuseful
834ba85b30 replaced all logging statements with log function, resolved misconception with and argument handling 2024-11-12 15:22:28 +00:00
sometimesuseful
f363327a34 removed check_dependencies in favor of functions.sh version, modified cleanup to use new log function, fixed trap signals 2024-11-12 15:14:02 +00:00
sometimesuseful
3c1060a84f function for checking dependencies added, log functions condensed into a single function 2024-11-12 14:43:48 +00:00
sometimesuseful
085b8ea8bb added yellow 2024-11-12 14:40:12 +00:00
sometimesuseful
a43d991a3b moved calls out of global space to main function, preparing for usage with strict mode 2024-11-12 14:17:59 +00:00
sometimesuseful
e4bce4beef logging functions and color variables 2024-11-12 14:14:25 +00:00
PedoDeveloper
66c2231a15 Added basic video preview script 2024-11-12 12:41:08 +00:00
PedoDeveloper
e7f2320b82 Removed use of bc 2024-11-12 12:40:07 +00:00
PedoDeveloper
194b6b672d Minor code cleanup 2024-11-11 13:05:32 +00:00
PedoDeveloper
0b438f91ba Minor code cleanup 2024-11-11 13:03:48 +00:00
PedoDeveloper
0c351f42ae Improved archive name generation 2024-11-11 13:02:25 +00:00
PedoDeveloper
755cd36fb6 Don't use volumes when filesize is smaller than volume size 2024-11-11 12:52:32 +00:00
PedoDeveloper
b6f5334011 Minor code cleanup 2024-11-11 12:43:59 +00:00
PedoDeveloper
c29fa867f3 Added smart volume size explanation 2024-11-11 12:40:59 +00:00
PedoDeveloper
926df11f34 Minor code cleanup 2024-11-11 12:38:36 +00:00
PedoDeveloper
92efe6f85b Added smart volume size algorithm 2024-11-11 12:31:17 +00:00
PedoDeveloper
4a236a56cf Improved input validation 2024-11-11 12:07:49 +00:00
PedoDeveloper
bb075ed369 Added explanation to archive.7z 2024-11-09 07:04:40 +00:00
PedoDeveloper
9515d2c952 Added cleanup function 2024-11-09 06:59:06 +00:00
PedoDeveloper
537e018647 Added basic archiving script 2024-11-09 06:42:05 +00:00
PedoDeveloper
9b15435ef6 Fixed typo 2024-11-09 05:43:45 +00:00
PedoDeveloper
c6a2961ba3 Test commit -
PedoDeveloper
262e6916a9 Much faster method of finding videos 2024-11-13 16:02:22 +00:00
PedoDeveloper
9599a76490 Created .gitignore file 2024-11-13 13:51:44 +00:00
5 changed files with 239 additions and 1 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
archives/
previews/

View file

@ -1,7 +1,11 @@
# Autoshare
An upcoming project. This will be a single program that fully automates the content sharing process (packing content into archives, creating previews, uploading archives and previews, and creating a post template ready to be copied and pasted.
An upcoming project. This will be a single program that fully automates the content sharing process (packing content into archives, creating previews, uploading archives and previews, and creating a post template ready to be copied and pasted).
It will be written in a mixture of Bash and Python. Tails and Whonix will be supported, with the goal of making the program work natively in Tails without the need to install additional software.
Anyone is welcome to collaborate with me.
## Collaborators
Currently it is not possible to submit pull requests when using the Tor Browser on the Safest setting. Please do not fork this repo attempting to submit a pull request. Instead leave a comment in [this thread](http://onion.tor.my/PedoDeveloper/autoshare/issues/7) and you will be added as a collaborator

43
includes/functions.sh Normal file
View file

@ -0,0 +1,43 @@
#!/bin/bash
# Common utility functions shared across multiple files.
RESET="\033[0m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
RED="\033[1;31m"
check_dependencies() {
# Usage: check_dependencies "7z" "unrar" "curl" ...
local dependencies=()
local dependency
for dependency in "$@"; do
if ! command -v "$dependency" >/dev/null; then
dependencies+=("$dependency")
fi
done
if (( "${#dependencies[@]}" > 0 )); then
log "ERROR" "Missing dependencies" "${dependencies[@]}"
return 1
fi
}
log() {
# Usage: log "NOTICE|WARN|ERROR" "this is a log message" ...
local caller="${0##*/}"
local level="$1"; shift
local color
case "$level" in
NOTICE) color="$GREEN" ;;
WARN) color="$YELLOW" ;;
ERROR) color="$RED" ;;
# No color for these levels.
INFO) color="" ;;
*) color="" ;;
esac
echo -e "$caller: ${color}[$level]: $*${RESET}" >&2
}

116
modules/create_archive Executable file
View file

@ -0,0 +1,116 @@
#!/bin/bash
# This script packs a file or directory into a 7z archive with the given password.
# It can (optionally) split the archives into volumes of a fixed size in megabytes.
source "$(dirname "$0")/../includes/functions.sh"
set -euo pipefail
cleanup() {
local archive_name="$1"
rm -f "${archive_name}"*
log "INFO" "Cleaning up ${archive_name##*/} remains before exit"
}
check_input() {
local input_file="$1"
local password="$2"
local size="$3"
[[ -e "$input_file" ]] || { log "ERROR" "Input file '${input_file}' does not exist"; exit 2; }
[[ -n "${password}" ]] || { log "ERROR" "No password given"; exit 2; }
[[ "$size" =~ ^([1-9][0-9]*)?$ ]] || { log "ERROR" "Invalid size '$size', must be empty or a positive number"; exit 2; }
}
calc_smart_volumes() {
# Calculates a "smart" volume size so that each volume (including the final part)
# will be approximately the same size
local input_file="$1"
local size="$2"
local total_size num_volumes smart_size
total_size=$(du -s -BM "${input_file}" | grep -oP '^\d+') || return 1
# If total file size is smaller than volume size, don't pack it into volumes
if (( total_size < size)); then
log "WARN" "$input_file is smaller than ${size}MB, skipping volumes"
return 1
fi
num_volumes=$(( (total_size + size - 1) / size ))
smart_size=$(( (total_size + num_volumes - 1) / num_volumes ))
log "INFO" "Calculated smart volume size '$smart_size'"
echo "$smart_size"
}
get_volumes() {
local input_file="$1"
local size="${2:-}"
local volumes=""
local smart_size=""
if [[ -n "$size" ]]; then
log "INFO" "Volumes size is set to ${size}MB"
smart_size="$(calc_smart_volumes "$input_file" "$size" || true)"
fi
if [[ -n "$smart_size" ]]; then
volumes="-v${smart_size}m"
log "INFO" "Volumes set to '$volumes'"
else
log "INFO" "Volumes argument unset"
fi
echo "$volumes"
}
generate_name() {
# Generates a random archive name of 20 alphanumeric characters
local archive_dir="$1"
local archive_name
archive_name="$archive_dir/$(tr -dc '[:alnum:]' < /dev/urandom | head -c 20).7z"
log "INFO" "Generated archive name '$archive_name'"
echo "$archive_name"
}
create_archive() {
local input_file="$1"
local password="$2"
local volumes="$3"
local archive_name="$4"
7z a -mhe=on "-p${password}" "$volumes" "$archive_name" "${input_file}"
}
main() {
local input_file="${1:-}"
local password="${2:-}"
local size="${3:-}"
local volumes archive_name archive_dir
check_dependencies "7z"
check_input "$input_file" "$password" "$size"
archive_dir="$(dirname "$0")/../archives"
mkdir -p "$archive_dir"
archive_name="$(generate_name "$archive_dir")"
volumes="$(get_volumes "$input_file" "$size")"
log "INFO" "Packing '${input_file}' into archive '$archive_name' with password '${password}'"
trap 'cleanup "$archive_name"' ERR INT
create_archive \
"$input_file" \
"$password" \
"$volumes" \
"$archive_name"
log "NOTICE" "Archive created"
}
main "$@"

73
modules/create_video_previews Executable file
View file

@ -0,0 +1,73 @@
#!/bin/bash
preview_dir="$(dirname "$0")/../previews"
search_dir="${1}"
check_dependencies() {
if ! mkdir -p "$preview_dir"; then
echo "ERROR: Unable to create preview directory"
exit 1
elif ! command -v ffmpeg xargs 2>&1 >/dev/null; then
echo "ERROR: FFmpeg and xargs must be installed"
exit 1
fi
}
check_input() {
if [[ ! -e "${search_dir}" ]]; then
echo "ERROR: Input file '${search_dir}' does not exist"
exit 2
fi
}
# Search for videos recursively using the MIME type
find_videos() {
video_list=$(find ${search_dir} -type f -print0 | xargs -0 file -i | grep -oP '.*(?=:\s+video/)')
echo "${video_list}" >&2
}
create_previews() {
while IFS= read -r video; do
echo "Making preview for ${video}"
make_preview
done <<< "${video_list}"
}
get_size() {
IFS=','
read -r width height <<< $(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 "${video}")
if (( $width >= $height )); then
rows=4 cols=5
scale_format="200:-1"
else
rows=5 cols=4
scale_format="-1:200"
fi
}
get_num_frames() {
local num_snapshots=$(( rows * cols ))
num_frames=$(ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -of csv=p=0 "${video}")
echo "Num frames: $num_frames" >&2
frames_per_snapshot=$(( num_frames / num_snapshots ))
}
make_preview() {
get_size
get_num_frames
filename="$preview_dir/$(basename "${video}").webp"
filters="select=not(mod(n\,$frames_per_snapshot)),scale=$scale_format,tile=${rows}x${cols}"
ffmpeg -nostdin -loglevel panic -i "${video}" -frames 1 -q:v 90 -vf "$filters" "${filename}"
}
check_dependencies
check_input
find_videos
create_previews