Extd rename/unmux to pad with zeroes
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
|
||||
set -u
|
||||
|
||||
ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
CONFIG_DIR="${FFX_CONFIG_DIR:-${HOME}/.local/etc}"
|
||||
CONFIG_FILE="${FFX_CONFIG_FILE:-${CONFIG_DIR}/ffx.json}"
|
||||
VAR_DIR="${FFX_VAR_DIR:-${HOME}/.local/var/ffx}"
|
||||
LOG_DIR="${FFX_LOG_DIR:-${HOME}/.local/var/log}"
|
||||
DATABASE_FILE="${FFX_DATABASE_FILE:-${VAR_DIR}/ffx.db}"
|
||||
SUBTITLES_BASE_DIR="${FFX_SUBTITLES_BASE_DIR:-${HOME}/.local/var/sync/subtitles}"
|
||||
FFX_PYTHON="${FFX_PYTHON:-${HOME}/.local/share/ffx.venv/bin/python}"
|
||||
CONFIG_TEMPLATE_FILE="${FFX_CONFIG_TEMPLATE:-${ROOT_DIR}/assets/ffx.json.j2}"
|
||||
|
||||
CHECK_ONLY=0
|
||||
WITH_TESTS=0
|
||||
@@ -49,6 +52,8 @@ Environment overrides:
|
||||
FFX_LOG_DIR Override the default log directory.
|
||||
FFX_DATABASE_FILE Override the database path written into a newly seeded config.
|
||||
FFX_SUBTITLES_BASE_DIR Override the default subtitles base directory written into a newly seeded config.
|
||||
FFX_PYTHON Override the bundle venv Python used to render the seeded config.
|
||||
FFX_CONFIG_TEMPLATE Override the Jinja2 template path used to seed the config.
|
||||
|
||||
Notes:
|
||||
- tools/setup.sh is the first installation step and owns bundle venv setup.
|
||||
@@ -316,6 +321,93 @@ install_system_requirements() {
|
||||
return 0
|
||||
}
|
||||
|
||||
render_default_config() {
|
||||
local output_path="$1"
|
||||
local temporary_output_path=""
|
||||
|
||||
if [ ! -x "${FFX_PYTHON}" ]; then
|
||||
printf 'Missing bundle Python interpreter at %s.\n' "${FFX_PYTHON}" >&2
|
||||
INSTALL_FAILURES=$((INSTALL_FAILURES + 1))
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -f "${CONFIG_TEMPLATE_FILE}" ]; then
|
||||
printf 'Missing FFX config template at %s.\n' "${CONFIG_TEMPLATE_FILE}" >&2
|
||||
INSTALL_FAILURES=$((INSTALL_FAILURES + 1))
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! temporary_output_path="$(mktemp "${output_path}.tmp.XXXXXX")"; then
|
||||
printf 'Failed to create a temporary config file next to %s.\n' "${output_path}" >&2
|
||||
INSTALL_FAILURES=$((INSTALL_FAILURES + 1))
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! FFX_CONFIG_TEMPLATE_FILE="${CONFIG_TEMPLATE_FILE}" \
|
||||
FFX_REPO_ROOT="${ROOT_DIR}" \
|
||||
FFX_DATABASE_PATH="${DATABASE_FILE}" \
|
||||
FFX_LOG_DIRECTORY="${LOG_DIR}" \
|
||||
FFX_SUBTITLES_DIRECTORY="${SUBTITLES_BASE_DIR}" \
|
||||
"${FFX_PYTHON}" - >"${temporary_output_path}" <<'PY'
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader, StrictUndefined
|
||||
|
||||
repo_root = Path(os.environ["FFX_REPO_ROOT"])
|
||||
src_root = repo_root / "src"
|
||||
if str(src_root) not in sys.path:
|
||||
sys.path.insert(0, str(src_root))
|
||||
|
||||
from ffx.constants import (
|
||||
DEFAULT_SHOW_INDEX_EPISODE_DIGITS,
|
||||
DEFAULT_SHOW_INDEX_SEASON_DIGITS,
|
||||
DEFAULT_SHOW_INDICATOR_EPISODE_DIGITS,
|
||||
DEFAULT_SHOW_INDICATOR_SEASON_DIGITS,
|
||||
)
|
||||
|
||||
template_path = Path(os.environ["FFX_CONFIG_TEMPLATE_FILE"])
|
||||
environment = Environment(
|
||||
loader=FileSystemLoader(str(template_path.parent)),
|
||||
undefined=StrictUndefined,
|
||||
autoescape=False,
|
||||
keep_trailing_newline=True,
|
||||
)
|
||||
template = environment.get_template(template_path.name)
|
||||
|
||||
sys.stdout.write(
|
||||
template.render(
|
||||
database_path_json=json.dumps(os.environ["FFX_DATABASE_PATH"]),
|
||||
log_directory_json=json.dumps(os.environ["FFX_LOG_DIRECTORY"]),
|
||||
subtitles_directory_json=json.dumps(os.environ["FFX_SUBTITLES_DIRECTORY"]),
|
||||
default_index_season_digits=DEFAULT_SHOW_INDEX_SEASON_DIGITS,
|
||||
default_index_episode_digits=DEFAULT_SHOW_INDEX_EPISODE_DIGITS,
|
||||
default_indicator_season_digits=DEFAULT_SHOW_INDICATOR_SEASON_DIGITS,
|
||||
default_indicator_episode_digits=DEFAULT_SHOW_INDICATOR_EPISODE_DIGITS,
|
||||
)
|
||||
)
|
||||
PY
|
||||
then
|
||||
rm -f "${temporary_output_path}"
|
||||
printf 'Failed to render ffx config from template %s.\n' "${CONFIG_TEMPLATE_FILE}" >&2
|
||||
INSTALL_FAILURES=$((INSTALL_FAILURES + 1))
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! mv "${temporary_output_path}" "${output_path}"; then
|
||||
rm -f "${temporary_output_path}"
|
||||
printf 'Failed to move rendered ffx config into place at %s.\n' "${output_path}" >&2
|
||||
INSTALL_FAILURES=$((INSTALL_FAILURES + 1))
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
seed_default_config() {
|
||||
if [ "${CHECK_ONLY}" -eq 1 ]; then
|
||||
return 0
|
||||
@@ -365,43 +457,7 @@ seed_default_config() {
|
||||
|
||||
if [ ! -f "${CONFIG_FILE}" ]; then
|
||||
printf 'Seeding ffx config at %s...\n' "${CONFIG_FILE}"
|
||||
if ! cat >"${CONFIG_FILE}" <<EOF
|
||||
{
|
||||
"databasePath": "${DATABASE_FILE}",
|
||||
"logDirectory": "${LOG_DIR}",
|
||||
"subtitlesDirectory": "${SUBTITLES_BASE_DIR}",
|
||||
"metadata": {
|
||||
"signature": {
|
||||
"RECODED_WITH": "FFX"
|
||||
},
|
||||
"remove": [
|
||||
"VERSION-eng",
|
||||
"creation_time",
|
||||
"NAME"
|
||||
],
|
||||
"streams": {
|
||||
"remove": [
|
||||
"BPS",
|
||||
"NUMBER_OF_FRAMES",
|
||||
"NUMBER_OF_BYTES",
|
||||
"_STATISTICS_WRITING_APP",
|
||||
"_STATISTICS_WRITING_DATE_UTC",
|
||||
"_STATISTICS_TAGS",
|
||||
"BPS-eng",
|
||||
"DURATION-eng",
|
||||
"NUMBER_OF_FRAMES-eng",
|
||||
"NUMBER_OF_BYTES-eng",
|
||||
"_STATISTICS_WRITING_APP-eng",
|
||||
"_STATISTICS_WRITING_DATE_UTC-eng",
|
||||
"_STATISTICS_TAGS-eng"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
then
|
||||
printf 'Failed to write ffx config at %s.\n' "${CONFIG_FILE}" >&2
|
||||
INSTALL_FAILURES=$((INSTALL_FAILURES + 1))
|
||||
if ! render_default_config "${CONFIG_FILE}"; then
|
||||
return 1
|
||||
fi
|
||||
created_any=1
|
||||
|
||||
Reference in New Issue
Block a user