Skip to content

Instantly share code, notes, and snippets.

@bdmorin
Last active January 29, 2023 16:37
Show Gist options
  • Save bdmorin/d3c53e0f495f4947bf61fb55e1c85310 to your computer and use it in GitHub Desktop.
Save bdmorin/d3c53e0f495f4947bf61fb55e1c85310 to your computer and use it in GitHub Desktop.
my blackhole solution for put.io & sonarr
#!/usr/bin/env bash
# authornote: i need to change all mentions of blackhole -> transferdir or something
# tested on macos, YMMV
# Gist: https://gist.github.com/bdmorin/d3c53e0f495f4947bf61fb55e1c85310
# Set ur putio oath token
OAUTH_TOKEN=$(cat ${HOME}/.putio_oauth)
# Set ur blackhole directory
BH_DIR="${HOME}/Plex/blackhole"
# Set ur putio directory id
PUTIO_DIR='746080174'
# get a tempfile
tempfile="$(/usr/bin/env mktemp)"
#echo ${tempfile}
# get jq location
jq="$(/usr/bin/env which jq)"
# get curl location
curl="$(/usr/bin/env which curl)"
# Gather bhole files
for MAGNETS in ${BH_DIR}/*.magnet
do
printf "Processing: %s\n" "${MAGNETS}"
${curl} -s -d "save_parent_id=${PUTIO_DIR}" --data-urlencode "url@${MAGNETS}" -o "${tempfile}" "https://api.put.io/v2/transfers/add?oauth_token=${OAUTH_TOKEN}"
if [ $(cat ${tempfile} | ${jq} --compact-output --raw-output '.status') == "OK" ]
then
printf "uploaded: %s\n" "${MAGNETS}"
printf "remove these files\n"
printf " -- %s\n" "${tempfile}"
printf " -- %s\n" "${MAGNETS}"
/bin/rm -v "${tempfile}" "${MAGNETS}"
else
printf "something didn't go right\n"
cat ${tempfile} | ${jq} '.'
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment