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

Multiple libraries #2

Open
modem7 opened this issue Sep 25, 2023 · 5 comments
Open

Multiple libraries #2

modem7 opened this issue Sep 25, 2023 · 5 comments

Comments

@modem7
Copy link

modem7 commented Sep 25, 2023

Heya,

For multiple libraries, how best to get this done?

Cheers!

@hollanbm
Copy link
Owner

Heya,

For multiple libraries, how best to get this done?

Cheers!

I have separate *arr instances and tdarr libraries. So that was never a thought of mine.

you would need to modify the script, one of the input args contains the file path. You could check the paths and setup additional env vars for input.

@modem7
Copy link
Author

modem7 commented Sep 26, 2023

This is what I've come up with so far. Untested, will give it a try tomorrow.

This should also retain the original behaviour of the script if you only have a single library/multiple instances.

#!/bin/bash

##########################################
# For a single library, set the following:
##########################################
TDARR_DB_ID="value1"

############################################
# For multiple libraries, set the following:
############################################
# How many libraries do you have?
LIBRARY_COUNT=6
# Library ID's. Add or remove ID's depending on your requirements.
TDARR_DB_ID_1="value1"
TDARR_DB_ID_2="value2"
TDARR_DB_ID_3="value3"
TDARR_DB_ID_4="value4"
TDARR_DB_ID_5="value5"
TDARR_DB_ID_6="value6"

if [[ -n "${sonarr_eventtype}" ]]; then
  FILE_PATH=${sonarr_episodefile_path}
  EVENT_TYPE="${sonarr_eventtype}"
elif [[ -n "${radarr_eventtype}" ]]; then
  FILE_PATH=${radarr_moviefile_path}
  EVENT_TYPE="${radarr_eventtype}"
fi

if [[ -n "${TDARR_PATH_TRANSLATE}" ]]; then
  FILE_PATH=$(echo "$FILE_PATH" | sed "s|${TDARR_PATH_TRANSLATE}|")
fi

if [ -v TDARR_DB_ID ]
then
    PAYLOAD="{\"data\": {\"scanConfig\": {\"dbID\": \"${TDARR_DB_ID}\", \"arrayOrPath\": [\"$FILE_PATH\"], \"mode\": \"scanFolderWatcher\" }}}"
else
    for i in $(seq 1 $LIBRARY_COUNT)
    do
        TDARR_DB_ID=TDARR_DB_ID_${i}
        PAYLOAD="{\"data\": {\"scanConfig\": {\"dbID\": \"${!TDARR_DB_ID}\", \"arrayOrPath\": [\"$FILE_PATH\"], \"mode\": \"scanFolderWatcher\" }}}"
done
fi

# debug logs - payload is most important
echo "EVENT_TYPE: $EVENT_TYPE"
echo "TDARR_URL: $TDARR_URL"
echo "PAYLOAD: $PAYLOAD"

# don't call tdarr when testing
if [[ -n "$EVENT_TYPE" && "$EVENT_TYPE" != "Test" ]]; then
  curl --silent --request POST \
    --url ${TDARR_URL}/api/v2/scan-files \
    --header 'content-type: application/json' \
    --data "$PAYLOAD" \
    --location \
    --insecure
fi

If this is useful (and if it works in production), I'd be happy to raise a PR if appropriate.

@hollanbm
Copy link
Owner

This is what I've come up with so far. Untested, will give it a try tomorrow.

This should also retain the original behaviour of the script if you only have a single library/multiple instances.

#!/bin/bash

##########################################
# For a single library, set the following:
##########################################
TDARR_DB_ID="value1"

############################################
# For multiple libraries, set the following:
############################################
# How many libraries do you have?
LIBRARY_COUNT=6
# Library ID's. Add or remove ID's depending on your requirements.
TDARR_DB_ID_1="value1"
TDARR_DB_ID_2="value2"
TDARR_DB_ID_3="value3"
TDARR_DB_ID_4="value4"
TDARR_DB_ID_5="value5"
TDARR_DB_ID_6="value6"

if [[ -n "${sonarr_eventtype}" ]]; then
  FILE_PATH=${sonarr_episodefile_path}
  EVENT_TYPE="${sonarr_eventtype}"
elif [[ -n "${radarr_eventtype}" ]]; then
  FILE_PATH=${radarr_moviefile_path}
  EVENT_TYPE="${radarr_eventtype}"
fi

if [[ -n "${TDARR_PATH_TRANSLATE}" ]]; then
  FILE_PATH=$(echo "$FILE_PATH" | sed "s|${TDARR_PATH_TRANSLATE}|")
fi

if [ -v TDARR_DB_ID ]
then
    PAYLOAD="{\"data\": {\"scanConfig\": {\"dbID\": \"${TDARR_DB_ID}\", \"arrayOrPath\": [\"$FILE_PATH\"], \"mode\": \"scanFolderWatcher\" }}}"
else
    for i in $(seq 1 $LIBRARY_COUNT)
    do
        TDARR_DB_ID=TDARR_DB_ID_${i}
        PAYLOAD="{\"data\": {\"scanConfig\": {\"dbID\": \"${!TDARR_DB_ID}\", \"arrayOrPath\": [\"$FILE_PATH\"], \"mode\": \"scanFolderWatcher\" }}}"
done
fi

# debug logs - payload is most important
echo "EVENT_TYPE: $EVENT_TYPE"
echo "TDARR_URL: $TDARR_URL"
echo "PAYLOAD: $PAYLOAD"

# don't call tdarr when testing
if [[ -n "$EVENT_TYPE" && "$EVENT_TYPE" != "Test" ]]; then
  curl --silent --request POST \
    --url ${TDARR_URL}/api/v2/scan-files \
    --header 'content-type: application/json' \
    --data "$PAYLOAD" \
    --location \
    --insecure
fi

If this is useful (and if it works in production), I'd be happy to raise a PR if appropriate.

I’ve been so busy, I just now had time to sit down and look at the code you posted.

In the past I had issues with calling the tdarr scan endpoint, with a file that wasn’t actually in the library on the HTTP request. The file would get picked up and converted and put in the wrong output folder.

so I’m not certain looping and calling the endpoint for every library defined is an good idea. Let me sit and think on this, and see if I can come up with something more flexible.

@rukuh
Copy link

rukuh commented Dec 12, 2023

I have not tested end to end but the script on test in *arr app shows Success!

I went with the python version and used dockermods to install python3 and request in the container. This is assuming that you use lsio images ...

DOCKER_MODS: linuxserver/mods:universal-package-install
INSTALL_PACKAGES: python3
INSTALL_PIP_PACKAGES: requests

@hollanbm
Copy link
Owner

I have not tested end to end but the script on test in *arr app shows Success!

I went with the python version and used dockermods to install python3 and request in the container. This is assuming that you use lsio images ...

DOCKER_MODS: linuxserver/mods:universal-package-install
INSTALL_PACKAGES: python3
INSTALL_PIP_PACKAGES: requests

I think you might have my repo confused with tdarr_inform

my goal was to use bash/curl to eliminate any additional container dependencies.

But yes, what you have will work fine with tdarr_inform. I’d probably roll your own image though. Every container restart will reinstall python before it bootstraps sonarr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants