Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Environnement Variable to setup the path for the temporary encoding #364

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ ENV \
AUTOMATED_CONVERSION_KEEP_SOURCE=1 \
AUTOMATED_CONVERSION_OUTPUT_DIR=/output \
AUTOMATED_CONVERSION_OUTPUT_SUBDIR= \
AUTOMATED_CONVERSION_OUTPUT_TEMP= \
AUTOMATED_CONVERSION_OVERWRITE_OUTPUT=0 \
AUTOMATED_CONVERSION_VIDEO_FILE_EXTENSIONS= \
AUTOMATED_CONVERSION_NON_VIDEO_FILE_ACTION=ignore \
Expand All @@ -169,6 +170,7 @@ ENV \
# Define mountable directories.
VOLUME ["/storage"]
VOLUME ["/output"]
VOLUME ["/output_tmp"]
VOLUME ["/watch"]
VOLUME ["/trash"]

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ of this parameter has the format `<VARIABLE_NAME>=<VALUE>`.
|`AUTOMATED_CONVERSION_NON_VIDEO_FILE_EXTENSIONS`| Space-separated list of file extensions to be considered as not being videos. Most non-video files are properly rejected by HandBrake. However, some files, like images, are convertible by HandBrake even if they are not video files. | `jpg jpeg bmp png gif txt nfo` |
|`AUTOMATED_CONVERSION_OUTPUT_DIR`| Root directory, inside the container, where converted videos should be written. **NOTE**: Make sure a volume mapping for this directory is defined when creating the container. | `/output` |
|`AUTOMATED_CONVERSION_OUTPUT_SUBDIR`| Subdirectory of the output folder into which converted videos should be written. By default, this variable is not set, meaning that videos are saved directly into `/output/`. If `Home/Movies` is set, converted videos will be written to `/output/Home/Movies`. Use the special value `SAME_AS_SRC` to use the same subfolder as the source. For example, if the video source file is `/watch/Movies/mymovie.mkv`, the converted video will be written to `/output/Movies/`. | (no value) |
|`AUTOMATED_CONVERSION_OUTPUT_TEMP`| If unset, Handbrake will create a temp folder .XXXXXX inside /output directory. When set to specific path **ON THE HOST**, temporary files will get written inside (in a subdir .XXXXXX) before being moved to /output. | `(no value)` |
|`AUTOMATED_CONVERSION_OVERWRITE_OUTPUT`| Setting this to `1` allows the final destination file to be overwritten if it already exists. | `0` |
|`AUTOMATED_CONVERSION_SOURCE_STABLE_TIME`| Time (in seconds) during which properties (e.g. size, time, etc) of a video file in the watch folder need to remain the same. This is to avoid processing a file that is being copied. | `5` |
|`AUTOMATED_CONVERSION_SOURCE_MIN_DURATION`| Minimum title duration (in seconds). Shorter titles will be ignored. This applies only to video disc sources (ISO file, `VIDEO_TS` folder or `BDMV` folder). | `10` |
Expand Down
56 changes: 42 additions & 14 deletions rootfs/etc/services.d/autovideoconverter/run
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,24 @@ process_video() {
# Set the temporary output directory: this is where the video will be
# actually written before being moved its final location once conversion is
# terminated.
OUTPUT_DIR_TMP="$(mktemp -d "$AC_OUTPUT_DIR/.XXXXXX")"
if [ ! -d "$OUTPUT_DIR_TMP" ]; then
hb_rc=1
log "ERROR: Failed to create temporary directory under '$AC_OUTPUT_DIR'."
break
fi
case "$AC_OUTPUT_TEMP" in
UNSET)
OUTPUT_DIR_TMP="$(mktemp -d "$AC_OUTPUT_DIR/.XXXXXX")"
if [ ! -d "$OUTPUT_DIR_TMP" ]; then
hb_rc=1
log "ERROR: Failed to create temporary directory under '$AC_OUTPUT_DIR'."
break
fi
;;
*)
OUTPUT_DIR_TMP="$(mktemp -d "/output_tmp/.XXXXXX")"
if [ ! -d "$OUTPUT_DIR_TMP" ]; then
hb_rc=1
log "ERROR: Failed to create temporary directory under '$AC_OUTPUT_TEMP'."
break
fi
;;
esac

# Set the temporary output filename.
OUTPUT_FILE_TMP="$OUTPUT_DIR_TMP/$basename.$AC_FORMAT"
Expand Down Expand Up @@ -411,14 +423,29 @@ process_watch_folder() {
log "ERROR: Cannot process watch folder '$WF', because the associated output directory '$AC_OUTPUT_DIR' doesn't exist."
return
else
TMPFILE="$(mktemp "$AC_OUTPUT_DIR"/.test_XXXXXX 2>/dev/null)"
RC=$?
if [ "$RC" -eq 0 ]; then
rm "$TMPFILE"
else
log "ERROR: Cannot process watch folder '$WF', because the associated output directory '$AC_OUTPUT_DIR' is not writable."
return
fi
case "$AC_OUTPUT_TEMP" in
UNSET)
TMPFILE="$(mktemp "$AC_OUTPUT_DIR"/.test_XXXXXX 2>/dev/null)"
RC=$?
if [ "$RC" -eq 0 ]; then
rm "$TMPFILE"
else
log "ERROR: Cannot process watch folder '$WF', because the associated output directory '$AC_OUTPUT_DIR' is not writable."
return
fi
;;
*)
TMPFILE="$(mktemp /output_tmp/.test_XXXXXX 2>/dev/null)"
RC=$?
if [ "$RC" -eq 0 ]; then
rm "$TMPFILE"
else
log "ERROR: Cannot process watch folder '$WF', because the associated output directory '$AC_OUTPUT_TEMP' is not writable."
return
fi
;;
esac

fi

if WATCHDIR_HASH_isset "$WF"; then
Expand Down Expand Up @@ -502,6 +529,7 @@ while true; do
AC_SOURCE_MAIN_TITLE_DETECTION="${AUTOMATED_CONVERSION_SOURCE_MAIN_TITLE_DETECTION:-0}"
AC_OUTPUT_DIR="${AUTOMATED_CONVERSION_OUTPUT_DIR:-/output}"
AC_OUTPUT_SUBDIR="${AUTOMATED_CONVERSION_OUTPUT_SUBDIR:-UNSET}"
AC_OUTPUT_TEMP="${AUTOMATED_CONVERSION_OUTPUT_TEMP:-UNSET}"
AC_KEEP_SOURCE="${AUTOMATED_CONVERSION_KEEP_SOURCE:-1}"
AC_VIDEO_FILE_EXTENSIONS="${AUTOMATED_CONVERSION_VIDEO_FILE_EXTENSIONS:-}"
AC_NON_VIDEO_FILE_ACTION="${AUTOMATED_CONVERSION_NON_VIDEO_FILE_ACTION:-ignore}"
Expand Down