Transcode : Use _iterate_target.
This commit is contained in:
parent
418f146141
commit
43b1d7bc8e
|
@ -32,7 +32,7 @@ function checksum_check() {
|
||||||
local hashfile=".${target#./}.sha1"
|
local hashfile=".${target#./}.sha1"
|
||||||
|
|
||||||
# Skip if hash doesn't exist.
|
# Skip if hash doesn't exist.
|
||||||
[[ -f "${hashfile}" ]] || { ((skipped++)); _warn "No hash found."; return 0; }
|
[[ -f "${hashfile}" ]] || { _skip "No hash found."; return 0; }
|
||||||
|
|
||||||
# Calculate hash.
|
# Calculate hash.
|
||||||
local stored=$(cat "${hashfile}" | cut -d\ -f1)
|
local stored=$(cat "${hashfile}" | cut -d\ -f1)
|
||||||
|
|
|
@ -3,43 +3,26 @@
|
||||||
# Usage: transcode <FORMAT> [FILES]
|
# Usage: transcode <FORMAT> [FILES]
|
||||||
function transcode() {
|
function transcode() {
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
local targets=("${@:2}")
|
local format=${1}
|
||||||
local format="${1}"
|
local targets=(${@:2})
|
||||||
local total=${#targets[@]}
|
[[ "${targets}" = "" ]] && targets=($(_ls_file))
|
||||||
local count=0
|
|
||||||
local failed=0
|
|
||||||
local skipped=0
|
|
||||||
|
|
||||||
# Report no format.
|
# Report no format.
|
||||||
if [[ "${format}" = "" ]]; then
|
if [[ "${format}" = "" ]] || [[ "${format}" =~ "." ]]; then
|
||||||
echo -e "${color_bred}No format specified.${color_default}"
|
_error "No format specified."
|
||||||
help transcode
|
help transcode
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# All files by default.
|
process() {
|
||||||
if [[ "${targets}" = "" ]]; then
|
|
||||||
targets=($(ls --classify | grep -v /$))
|
|
||||||
total=${#targets[@]}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Process.
|
|
||||||
for target in "${targets[@]}"; do
|
|
||||||
# Increment counter.
|
|
||||||
((count++))
|
|
||||||
|
|
||||||
# Define context names and status.
|
# Define context names and status.
|
||||||
local from="${target##*.}"
|
local from="${target##*.}"
|
||||||
local to="${format}"
|
local to="${format}"
|
||||||
local output="${target##*/}"
|
local output="${target##*/}"
|
||||||
output="${output%.*}.${to}"
|
output="${output%.*}.${to}"
|
||||||
local status="[${count}/${total}] ${target} -> ${output}"
|
|
||||||
|
|
||||||
# Show status.
|
|
||||||
echo -e "${color_bwhite}${status}${color_default}"
|
|
||||||
|
|
||||||
# Skip if file exists.
|
# Skip if file exists.
|
||||||
[[ -f "${output}" ]] && { ((skipped++)); continue; }
|
[[ -f "${output}" ]] && { _skip "Already exists."; return 0; }
|
||||||
|
|
||||||
# Support multiple inputs.
|
# Support multiple inputs.
|
||||||
[[ "${to}" = "mp3" ]] && from=""
|
[[ "${to}" = "mp3" ]] && from=""
|
||||||
|
@ -68,27 +51,13 @@ function transcode() {
|
||||||
_transcode_mkv "${target}" "${output}"
|
_transcode_mkv "${target}" "${output}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "${color_yellow}Conversion ${target##*.}-${to} not supported.${color_default}"
|
_error "Conversion ${target##*.}-${to} not supported."
|
||||||
false
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
# Show error.
|
_iterate_targets process ${targets[@]}
|
||||||
if [[ ${?} != 0 ]]; then
|
|
||||||
echo -e "${color_bred}${status}: Failed.${color_default}"
|
|
||||||
((failed++))
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ ${skipped} != 0 ]]; then
|
|
||||||
echo -e "${color_byellow}Skipped: ${skipped}.${color_default}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${failed} != 0 ]]; then
|
|
||||||
echo -e "${color_bred}Failed: ${failed}.${color_default}"
|
|
||||||
false
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _transcode_gz-xz() {
|
function _transcode_gz-xz() {
|
||||||
|
|
|
@ -77,3 +77,11 @@ function _error() {
|
||||||
function _warn() {
|
function _warn() {
|
||||||
echo -e "${color_byellow}${*}${color_default}"
|
echo -e "${color_byellow}${*}${color_default}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Skip current iteration.
|
||||||
|
# Usage: _skip [MESSAGE]
|
||||||
|
function _skip() {
|
||||||
|
((skipped++))
|
||||||
|
|
||||||
|
[[ "${*}" = "" ]] || echo -e "${color_byellow}${*}${color_default}"
|
||||||
|
}
|
||||||
|
|
Reference in a new issue