diff --git a/daemon/Dockerfile b/daemon/Dockerfile index 3cca629db9703b28dfff7c773a380b16f5069aa6..017096188f09e373247374dcae992391ecbc91d1 100644 --- a/daemon/Dockerfile +++ b/daemon/Dockerfile @@ -4,11 +4,13 @@ RUN apk add --update --no-cache --repository http://dl-cdn.alpinelinux.org/alpin gosu \ && \ apk add --update --no-cache \ + curl \ transmission-daemon \ && \ mkdir -m 777 /run/transmission COPY --chown=root:root entrypoint /usr/local/sbin/docker-entrypoint COPY --chown=root:root settings.json /etc/transmission/ +COPY --chown=root:root kodi-scan /usr/local/bin/ VOLUME /var/lib/transmission WORKDIR /var/lib/transmission ENV HOME /var/lib/transmission diff --git a/daemon/kodi-scan b/daemon/kodi-scan new file mode 100755 index 0000000000000000000000000000000000000000..b46337aa2656d1b1c472e9582faab4923b38e40a --- /dev/null +++ b/daemon/kodi-scan @@ -0,0 +1,42 @@ +#!/bin/sh +set -eu + +scan() { + case "${1:-}" in + audio) curl \ + --data-binary \ + '{ "jsonrpc": "2.0", "method": "AudioLibrary.Scan", "id": "transmission"}' \ + -H 'content-type: application/json;' \ + http://172.18.0.1:8080/jsonrpc ;; + video) curl \ + --data-binary \ + '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "transmission"}' \ + -H 'content-type: application/json;' \ + http://172.18.0.1:8080/jsonrpc ;; + *) scan video; scan audio ;; + esac +} + +starts_with() { + [ "${1##$2}" != "$1" ] +} + +is_in_dir() { + ! starts_with "$(realpath --relative-base "$1" "$2")" '/' +} + +if [ -z "${TR_TORRENT_DIR:-}" ] +then + scan +elif is_in_dir '/var/lib/transmission/Downloads/TV Shows' "$TR_TORRENT_DIR" +then + scan video +elif is_in_dir '/var/lib/transmission/Downloads/Movies' "$TR_TORRENT_DIR" +then + scan video +elif is_in_dir '/var/lib/transmission/Downloads/Music' "$TR_TORRENT_DIR" +then + scan audio +else + scan +fi diff --git a/daemon/settings.json b/daemon/settings.json index c92e48df5c4df59a5bf0159b38e5aa97d8b49239..9698f2f2580dd224b3ef56f0b5907729abf94851 100644 --- a/daemon/settings.json +++ b/daemon/settings.json @@ -55,8 +55,8 @@ "rpc-whitelist": "127.0.0.*,192.168.*.*,10.*.*.*,172.16.*.*,172.17.*.*,172.18.*.*,172.19.*.*,172.2?.*.*,172.30.*.*,172.31.*.*", "rpc-whitelist-enabled": false, "scrape-paused-torrents-enabled": true, - "script-torrent-done-enabled": false, - "script-torrent-done-filename": "", + "script-torrent-done-enabled": true, + "script-torrent-done-filename": "/usr/local/bin/kodi-scan", "seed-queue-enabled": false, "seed-queue-size": 10, "speed-limit-down": 100,