├── tdarr_autoscan.sh ├── LICENSE ├── tdarr_scan.sh └── README.md /tdarr_autoscan.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ -n "${sonarr_eventtype}" ]]; then 4 | FILE_PATH=${sonarr_episodefile_path} 5 | EVENT_TYPE="${sonarr_eventtype}" 6 | elif [[ -n "${radarr_eventtype}" ]]; then 7 | FILE_PATH=${radarr_moviefile_path} 8 | EVENT_TYPE="${radarr_eventtype}" 9 | fi 10 | 11 | if [[ -n "${TDARR_PATH_TRANSLATE}" ]]; then 12 | FILE_PATH=$(echo "$FILE_PATH" | sed "s|${TDARR_PATH_TRANSLATE}|") 13 | fi 14 | 15 | PAYLOAD="{\"data\": {\"scanConfig\": {\"dbID\": \"${TDARR_DB_ID}\", \"arrayOrPath\": [\"$FILE_PATH\"], \"mode\": \"scanFolderWatcher\" }}}" 16 | 17 | # debug logs - payload is most important 18 | echo "EVENT_TYPE: $EVENT_TYPE" 19 | echo "TDARR_URL: $TDARR_URL" 20 | echo "PAYLOAD: $PAYLOAD" 21 | 22 | # don't call tdarr when testing 23 | if [[ -n "$EVENT_TYPE" && "$EVENT_TYPE" != "Test" ]]; then 24 | curl --silent --request POST \ 25 | --url ${TDARR_URL}/api/v2/scan-files \ 26 | --header 'content-type: application/json' \ 27 | --data "$PAYLOAD" \ 28 | --location \ 29 | --insecure 30 | fi -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Brad Holland 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tdarr_scan.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # this is intended for calling manually, with input args 4 | # ./tdarr_manual_scan -t -f -r -l 5 | 6 | while getopts 't:f:r:l:' opt; do 7 | case "$opt" in 8 | t) 9 | TDARR_URL="${OPTARG}" 10 | echo "Processing option 't' with $TDARR_URL argument" 11 | ;; 12 | 13 | f) 14 | FILE_PATH="$OPTARG" 15 | echo "Processing option 'f' with '$FILE_PATH' argument" 16 | ;; 17 | 18 | r) 19 | TDARR_PATH_TRANSLATE="$OPTARG" 20 | echo "Processing option 'r' with '$TDARR_PATH_TRANSLATE' argument" 21 | FILE_PATH=$(echo "$FILE_PATH" | sed "s|$TDARR_PATH_TRANSLATE|") 22 | ;; 23 | 24 | l) 25 | TDARR_DB_ID="$OPTARG" 26 | echo "Processing option 'l' with '$TDARR_DB_ID' argument" 27 | ;; 28 | 29 | :) 30 | echo -e "option requires an argument.\nUsage: $(basename $0) [-t arg] [-f arg] [-r arg] [-l arg]" 31 | exit 1 32 | ;; 33 | 34 | ?) 35 | echo -e "Invalid command option.\nUsage: $(basename $0) [-t arg] [-f arg] [-r arg] [-l arg]" 36 | exit 1 37 | ;; 38 | esac 39 | done 40 | shift "$(($OPTIND -1))" 41 | 42 | PAYLOAD="{\"data\": {\"scanConfig\": {\"dbID\": \"${TDARR_DB_ID}\", \"arrayOrPath\": [\"$FILE_PATH\"], \"mode\": \"scanFolderWatcher\" }}}" 43 | 44 | # debug logs - payload is most important 45 | echo "EVENT_TYPE: $EVENT_TYPE" 46 | echo "TDARR_URL: $TDARR_URL" 47 | echo "PAYLOAD: $PAYLOAD" 48 | 49 | curl --silent --request POST \ 50 | --url ${TDARR_URL}/api/v2/scan-files \ 51 | --header 'content-type: application/json' \ 52 | --data "$PAYLOAD" \ 53 | --location \ 54 | --insecure 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tdarr_autoscan 2 | 3 | Original idea from [tdarr_inform](https://github.com/deathbybandaid/tdarr_inform) 4 | 5 | This script is done entirely in bash, which means it can be used for docker containers, where you might not have python, and do not wish to modify the base image 6 | The primary difference though, is that this script needs additional input, via environment variables, where as tdarr_inform is more configurable, in just about every way. 7 | 8 | This script is designed to be used with Sonarr or Radarr "custom scripts", on import/upgrade. 9 | 10 | ## Installation 11 | 12 | The following commands will download the script, and configure the correct permissions 13 | 14 | 1) `cd /path/to/arr/config/folder` 15 | 2) `wget https://raw.githubusercontent.com/hollanbm/tdarr_autoscan/main/tdarr_autoscan.sh` 16 | 3) `chmod 0755 tdarr_autoscan.sh` 17 | 4) Set `TDARR_URL`, `TDARR_DB_ID`, and/or `TDARR_PATH_TRANSLATE` environment variables on your container 18 | - [docker documentation](https://docs.docker.com/compose/environment-variables/) 19 | 20 | example docker-compose.yml 21 | 22 | ```yaml 23 | sonarr: 24 | container_name: sonarr 25 | image: ghcr.io/linuxserver/sonarr 26 | restart: unless-stopped 27 | ports: 28 | - 8989:8989 29 | environment: 30 | - TDARR_URL=http://tdarr:8265 31 | - TDARR_DB_ID=qWlsbkvbx 32 | - TDARR_PATH_TRANSLATE=/tv/|/media/tv/ 33 | volumes: 34 | - ${HOME}/Sonarr:/config # config files 35 | - /media/tv/:/tv 36 | ``` 37 | 38 | 5) Open the Sonarr/Radarr webui 39 | 6) `Settings > Connect > New > Custom Script` 40 | 7) Name: tdarr_autoscan 41 | 8) Notification Triggers 42 | - On Import 43 | - On Upgrade 44 | 9) Optionally, set any tags 45 | 10) Path: `/config/tdarr_autoscan.sh` 46 | 11) Save 47 | 48 | ## Usage 49 | 50 | ### Required fields 51 | 52 | The following environment variables are required to be set in your container 53 | 54 | - TDARR_URL 55 | - For most users, it will probably be in the form of 56 | - `http://ip:port` 57 | - If you have docker networking configured, then you may use the container_name instead of the ip address 58 | - `http://container_name:port` 59 | - If you have a reverse proxy or SSL configured, then you may use the full tdarr site URL 60 | - `https://site.domain` 61 | 62 | - TDARR_DB_ID 63 | - This value is a string hash, NOT an integer 64 | - The easiest way to determine what this value is, is to goto the libraries section in tdarr, and grab it from the URL after you've selected the correct library 65 | - The url (as of 1/16/23) is in the format `https://tdarr.domain.#/libraries//source` 66 | 67 | ### Optional fields 68 | 69 | - TDARR_PATH_TRANSLATE 70 | - This is intended to be used for path map translation, where your volume, is mounted at a different path than tdarr 71 | - This will be used as input to [sed](https://linux.die.net/man/1/sed) 72 | - This must be in the format `search|replace` 73 | - in the above example, only the first occurence of the word `search`, in the file path, will be replaced with the word `replace` 74 | - see [this line](https://github.com/hollanbm/tdarr_autoscan/blob/main/tdarr_autoscan.sh#L12) in the script in the script 75 | 76 | ### tdarr_scan.sh 77 | 78 | This is provided for those who would like to manually call the script with input args 79 | --------------------------------------------------------------------------------