Name : Skip archives when simplifying names.

This commit is contained in:
Dmitry Voronin 2023-12-27 14:05:07 +03:00
parent c00fdc84b4
commit d1774fa6cb
5 changed files with 52 additions and 32 deletions

View file

@ -267,6 +267,13 @@ function _archive_date() {
date +%Y%m%d%H%M date +%Y%m%d%H%M
} }
# Check if file is an archive.
function _is_archive() {
local out=$(echo "${*}" | grep -E ${_archive_pattern})
[[ "${out}" != "" ]]
}
complete -o filenames -F _archive_grep archive_check unarchive archive_rm complete -o filenames -F _archive_grep archive_check unarchive archive_rm
complete -o filenames -F _archive_grep_fast archive_xz complete -o filenames -F _archive_grep_fast archive_xz
complete -o filenames -F _archive_name archive_name complete -o filenames -F _archive_name archive_name

View file

@ -75,7 +75,7 @@ function _checksum_check() {
# Compare values. # Compare values.
if [[ "${stored}" != "${actual}" ]]; then if [[ "${stored}" != "${actual}" ]]; then
echo -e "${color_bred}${file}: Failed.${color_default}" _error "${file}: Failed."
return 1 return 1
fi fi

View file

@ -1,3 +1,37 @@
# Rename dirs to `snake_case` and files to `PascalCase`. Careful with structured file names like archives!
# Usage: name [FILES]
function name() {
local IFS=$'\n'
local targets=(${@})
[[ "${targets}" = "" ]] && targets=($(ls))
process() {
# Skip archive.
if $(_is_archive ${target}); then
_warn "File is an archive, skip."
return 0
fi
if [[ -d "${target}" ]]; then
local new_name=$(parse_snake ${target})
[[ -e "${new_name}" ]] && return 0
mv -- ${target} ${new_name} && echo ${new_name}
else
local ext=".${target##*.}"
local name=${target%.*}
[[ "${ext}" = ".${target}" ]] && ext=""
local new_name="$(parse_pascal ${name})${ext}"
[[ -e "${new_name}" ]] && return 0
mv -- ${target} ${new_name} && echo ${new_name}
fi
}
_iterate_targets process ${targets[@]}
}
# Rename files to strip all special characters. # Rename files to strip all special characters.
# All files by default. # All files by default.
# Usage: name_simple [FILES] # Usage: name_simple [FILES]
@ -7,6 +41,12 @@ function name_simple() {
[[ "${targets}" = "" ]] && targets=([^.]*) [[ "${targets}" = "" ]] && targets=([^.]*)
process() { process() {
# Skip archive.
if $(_is_archive ${target}); then
_warn "File is an archive, skip."
return 0
fi
# parse new name. # parse new name.
local ext="" local ext=""
local name="${target}" local name="${target}"
@ -314,30 +354,3 @@ function name_fix_numbering() {
_iterate_targets process ${targets[@]} _iterate_targets process ${targets[@]}
} }
# Rename dirs to `snake_case` and files to `PascalCase`. Careful with structured file names like archives!
# Usage: name [FILES]
function name() {
local IFS=$'\n'
local targets=(${@})
[[ "${targets}" = "" ]] && targets=($(ls))
process() {
if [[ -d "${target}" ]]; then
local new_name=$(parse_snake ${target})
[[ -e "${new_name}" ]] && return 0
mv -- ${target} ${new_name} && echo ${new_name}
else
local ext=".${target##*.}"
local name=${target%.*}
[[ "${ext}" = ".${target}" ]] && ext=""
local new_name="$(parse_pascal ${name})${ext}"
[[ -e "${new_name}" ]] && return 0
mv -- ${target} ${new_name} && echo ${new_name}
fi
}
_iterate_targets process ${targets[@]}
}

View file

@ -35,7 +35,7 @@ function _iterate_targets() {
# status info. # status info.
local status="[${count}/${total}] ${target}" local status="[${count}/${total}] ${target}"
echo -e "${color_bwhite}${status}${color_default}" _info "${status}"
# Call function. # Call function.
${foo} "${target}" ${foo} "${target}"
@ -43,7 +43,7 @@ function _iterate_targets() {
# Show error. # Show error.
if [[ ${?} != 0 ]]; then if [[ ${?} != 0 ]]; then
((failed++)) ((failed++))
echo -e "${color_bred}${status}: Failed.${color_default}" _error "${status}: Failed."
fi fi
# Add newline if not the last one. # Add newline if not the last one.

View file

@ -3,7 +3,7 @@
function vdl() { function vdl() {
# Check that ffmpeg and ffprobe are available. # Check that ffmpeg and ffprobe are available.
if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then
echo -e "${color_red}ffmpeg and ffprobe are required.${color_default}" _error "ffmpeg and ffprobe are required."
return 1 return 1
fi fi
@ -14,7 +14,7 @@ function vdl() {
# If could not get [LINK] eventually, show an error and exit. # If could not get [LINK] eventually, show an error and exit.
if [[ "${target}" = "" ]]; then if [[ "${target}" = "" ]]; then
echo -e "${color_red}Could not determine [LINK] to download.${color_default}" _error "Could not determine [LINK] to download."
help vdl help vdl
return 2 return 2
fi fi