我收藏了大量的音乐。有些文件是无损的,有些文件是有损的。
我想维护一个由原始集合的有损文件和原始集合无损文件的有损转换代码组成的集合的副本。
一些假设:
我想:
我想我需要使用一些自定义脚本来完成这个任务,但是如果在我投入大量时间之前,任何人都有建议或提示,我将永远感激。
发布于 2022-06-11 22:40:43
我不喜欢Makefiles (我可能同意这 guy),但是,make可以随心所欲地做你想做的事情:
例如,您定义了一条规则,希望为每个源.opus文件提供一个.flac文件:
Makefile,从我头顶
TARGETDIR=/path/to/compressed/library
%.opus: %.flac
ffmpeg -ffmpegflags -and -stuff -i "$<" -o "$@"
$(TARGETDIR)/%.opus: %.opus
cp --reflink=always "$<" "$@"它可以将所有的FLACs转换为树中的OPUSes。只有当.opus文件还没有存在,或者比FLAC上一次更改更早的时候,它才能做到这一点。
我不喜欢它,因为它发生在-tree中,也就是说,您不会得到一个干净的“纯原始”目录。至少在文件系统上使用一个支持反射的cp,这样你的拷贝就很浅了(而且实际上不需要任何空间)。它也不优雅地处理子目录,我认为,您会发现
那么,老实说,make在这里的功能实际上是:
对于每个通配符源文件(%.flac),检查结果(相同的文件.opus)是否已经生成,如果没有(或者构建比源文件更早),则执行构建。
这是有点向后,也没有复杂到足以依赖于制造。所以,shell脚本。我用zsh。虽然我不测试我写的东西,但我试着评论一下:
#!/usr/bin/zsh
# Copyright 2022 Marcus Müller
# SPDX-License-Identifier: BSD-3-Clause
# Find the license text under https://spdx.org/licenses/BSD-3-Clause.html
# set options:
setopt null_glob # Don't fail if there's no file matching a pattern
setopt no_case_glob # Don't care about case in matching
TARGET_DIR=../compressed_library
make_containing_dir() {
target_dir="${1:h}"
if [[ ! -d "${target_dir}" ]] ; then
logger -p user.debug "Creating directory ${target_dir}"
mkdir -p "${target_dir}" || logger -p user.err "can't mkdir ${target_dir}"
}
for compressed_source in **/*.{mp3,opus,vorbis,mp4} ; do
if [[ -d "${compressed_source}" ]]; then
continue # skip directories that happen to have a matching suffix
fi
logger -p user.debug "dealing with compressed source ${compressed_source}"
target_file="${TARGET_DIR}/${compressed_source}"
make_containing_dir "${target_file}"
# -h : check whether target exists and is symlink
if [[ ! -h "${target_file}" ]] ; then
ln -s "$(pwd)/${compressed_source}" "${target_file}" \
|| logger -p user.err "copying ${compressed_source} failed"
fi
done
for uncompressed_source in **/*.flac ; do
if [[ -d "${uncompressed_source}" ]]; then
continue # skip directories that happen to have a matching suffix
fi
logger -p user.debug "dealing with uncompressed source ${compressed_source}"
target_file="${TARGET_DIR}/${uncompressed_source%%.flac}.opus"
# ^ strip the .flac suffix
make_containing_dir "${target_file}"
# /-- compare source file for "older than"
# | target file; this returns !=0 if the source file
# | is newer, or the target file nonexisting
# \--------------------\
# |
if [[ "${uncompressed_source}" -ot "${target_file}" ]]; then
ffmpeg -loglevel=fatal \
-i "${uncompressed_source}" \
-b:a 96k \
"${target_file}" \
|| logger -p user.err "transcoding ${uncompressed_source} failed"
fi
done这是非常未经测试的,但至少它会登录到syslog (journalctl -xef是您的朋友)
https://unix.stackexchange.com/questions/705840
复制相似问题