forked from vitorgalvao/tiny-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathringtonemaker
More file actions
executable file
·94 lines (80 loc) · 2.08 KB
/
Copy pathringtonemaker
File metadata and controls
executable file
·94 lines (80 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
readonly program="$(basename "${0}")"
function depends_on {
readonly local dep="${1}"
if ! command -v "${dep}" &>/dev/null; then
echo -e >&2 "\n$(tput setaf 1)This script requires ${dep}. Please install it first.$(tput sgr0)\n"
exit 1
fi
}
function syntax_error {
echo -e "${program}: ${1}\nTry \`${program} --help\` for more information." >&2
exit 1
}
function get_output_path {
local input_path output_path
input_path="${1}"
output_path="${2}"
if [[ -n "${output_path}" ]]; then
[[ "${output_path##*.}" == 'm4r' ]] && echo "${output_path}" || echo "${output_path}.m4r"
else
echo "${input_path%.*}.m4r"
fi
}
function usage {
echo "
Usage:
${program} [-d <duration>] [-s <time>] [-o <output_file>] <input_file>
Options:
-d <number>, --duration <number> Duration (in seconds) of the output file. Maximum is 40 seconds.
-o <file>, --output <file> Path to output file. If empty, will be next to the input file.
-s <time>, --start <time> Start time from when to start cutting, in the form xx:xx:xx
-h, --help Show this help.
" | sed -E 's/^ {4}//'
}
# available flags
args=()
while [[ "${1}" ]]; do
case "${1}" in
-h | --help)
usage
exit 0
;;
-d | --duration)
duration="${2}"
shift
;;
-o | --output)
given_output_path="${2}"
shift
;;
-s | --start)
start="${2}"
shift
;;
--)
shift
args+=("${@}")
break
;;
-*)
syntax_error "unrecognized option: ${1}"
;;
*)
args+=("${1}")
;;
esac
shift
done
set -- "${args[@]}"
depends_on 'ffmpeg'
input_file="${1}"
output_file="$(get_output_path "${input_file}" "${given_output_path}")"
if [[ ! -f "${input_file}" ]]; then
echo 'A valid path to an input file is required.'
usage
exit 1
fi
[[ -z "${duration}" || "${duration}" -gt 40 ]] && duration='40'
[[ -z "${start}" ]] && start='00:00:00'
ffmpeg -i "${input_file}" -vn -acodec aac -f mp4 -ss "${start}" -t "${duration}" "${output_file}"