Skip to content

Commit

Permalink
Be more flexible with the output location of auto converted videos.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlesage committed Jun 30, 2017
1 parent 310a288 commit c5410d3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ of this parameter has the format `<VARIABLE_NAME>=<VALUE>`.
|`AUTOMATED_CONVERSION_PRESET`| HandBrake preset used by the automatic video converter. See the [Automatic Video Conversion](#automatic-video-conversion) section for more details. | `Very Fast 1080p30` |
|`AUTOMATED_CONVERSION_FORMAT`| Video container format used by the automatic video converter for output files. This is typically the video filename extension. See the [Automatic Video Conversion](#automatic-video-conversion) section for more details. | `mp4` |
|`AUTOMATED_CONVERSION_KEEP_SOURCE`| When set to `0`, a video that has been successfully converted is removed from the watch folder. | `1` |
|`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/`. | (unset) |
|`AUTOMATED_CONVERSION_SOURCE_STABLE_TIME`| Time 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` |
|`HANDBRAKE_DEBUG`| Setting this to `1` enables HandBrake debug logging. Log messages are sent to `/config/handbrake.debug.log` (container path). **NOTE**: When enabled, a lot of information is generated and the log file will grow quickly. Make sure to enable this temporarily and only when needed. | (unset) |

Expand Down
11 changes: 11 additions & 0 deletions appdefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ from Jinja2 templates.
<mask>false</mask>
</unraid_template>
</environment_variable>
<environment_variable>
<name>AUTOMATED_CONVERSION_OUTPUT_SUBDIR</name>
<description>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/`.</description>
<unraid_template>
<title>Automatic Video Converter: Output Subdirectory</title>
<description>Subdirectory of the output folder into which converted videos should be written.[ul][li]Leave value empty to save converted videos directly into [b][i]/output/[/i][/b].[/li][li]Use the special value [b][i]SAME_AS_SRC[/i][/b] to use the same subfolder as the source. For example, if the video source file is [b][i]/watch/Movies/mymovie.mkv[/i][/b], the converted video will be written to [b][i]/output/Movies/[/i][/b].[/li][li]Use any subfolder name. For example, setting the value [b][i]Home/Movies[/i][/b] will make converted videos written to [b][i]/output/Home/Movies[/i][/b]/[/li][/ul]</description>
<display>always</display>
<required>false</required>
<mask>false</mask>
</unraid_template>
</environment_variable>
<environment_variable>
<name>AUTOMATED_CONVERSION_SOURCE_STABLE_TIME</name>
<description>Time 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.</description>
Expand Down
19 changes: 15 additions & 4 deletions rootfs/etc/services.d/autovideoconverter/run
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,22 @@ process_file() {
fi

log "Starting conversion of '$file' ($hash)..."
case "${AUTOMATED_CONVERSION_OUTPUT_SUBDIR:-UNSET}" in
UNSET)
OUTPUT_DIR="/output"
;;
SAME_AS_SRC)
dirname="$(dirname "$file" | sed 's|^/watch||')"
OUTPUT_DIR="/output/$dirname"
;;
*)
OUTPUT_DIR="/output/$AUTOMATED_CONVERSION_OUTPUT_SUBDIR"
;;
esac
OUTPUT_DIR="$(echo "$OUTPUT_DIR" | sed 's|/\+|/|g' | sed 's|/\+$||')"
s6-setuidgid $USER_ID:$GROUP_ID mkdir -p "$OUTPUT_DIR"
basename="$(basename "$file" | sed 's/\.[^.]*$//')"
# dirname="$(dirname "$file" | sed 's|^/watch||')"
# OUTPUT_FILE="/output/$dirname/$basename.$AUTOMATED_CONVERSION_FORMAT"
# s6-setuidgid $USER_ID:$GROUP_ID mkdir -p "/output/$dirname"
OUTPUT_FILE="/output/$basename.$AUTOMATED_CONVERSION_FORMAT"
OUTPUT_FILE="$OUTPUT_DIR/$basename.$AUTOMATED_CONVERSION_FORMAT"
$HANDBRAKE_CLI -i "$file" \
-o "$OUTPUT_FILE" \
--preset "$AUTOMATED_CONVERSION_PRESET"
Expand Down

0 comments on commit c5410d3

Please sign in to comment.