Skip to content

Instantly share code, notes, and snippets.

@markododa
Last active July 1, 2023 22:25
Show Gist options
  • Save markododa/1c2332e6824db32aaf0d639c4a7d729d to your computer and use it in GitHub Desktop.
Save markododa/1c2332e6824db32aaf0d639c4a7d729d to your computer and use it in GitHub Desktop.
#!/bin/bash
TOKEN=""
ARG="$1"
#get id of list files for torrent
#list-torrents
if [ "$ARG" == 'list' ]; then
curl -s 'https://app.real-debrid.com/rest/1.0/torrents' -H "Authorization: Bearer $TOKEN"|jq -r '.[]|.id,.filename,.status'|paste - - -|sed 's/downloaded//g'
exit 0
fi
if [ "$ARG" == 'get' ]; then
TORRENT_ID="$2"
ID_FILES=$(curl -s https://app.real-debrid.com/rest/1.0/torrents/info/"${TORRENT_ID}" -H "Authorization: Bearer $TOKEN" |jq -r '.links[]')
echo "[playlist]"
i=0
while read -r ID; do
response=$(curl -s 'https://app.real-debrid.com/rest/1.0/unrestrict/link' --data-urlencode "link=${ID}" -H "Authorization: Bearer $TOKEN")
if [[ "$response" =~ "hoster_unavailable" ]]; then
echo "$ID" 1>&2
else
link="$( echo "$response" |jq -r '.download')"
name="$( echo "$response" |jq -r '.filename')"
#name=$(ffprobe "$link" 2>&1 |grep title|head -n 1|sed s/'title :'//g)
i=$((i+1))
echo File"${i}"="${link}"
echo Title"${i}"="${name}"
fi
done <<< "$ID_FILES"
echo NumberOfEntries="${i}"
fi
if [ "$ARG" == 'add' ]; then
while read -rp 'Enter magnet:' MAGNET; do
TORRENT_ID=$(curl -s 'https://app.real-debrid.com/rest/1.0/torrents/addMagnet' --data "magnet=${MAGNET}" -H "Authorization: Bearer $TOKEN" | jq -r '.id')
curl -s "https://app.real-debrid.com/rest/1.0/torrents/selectFiles/$TORRENT_ID" --data "files=all" -H "Authorization: Bearer $TOKEN"
done
fi
if [ "$ARG" == 'sel' ]; then
TORRENT_ID="$2"
curl -s "https://app.real-debrid.com/rest/1.0/torrents/selectFiles/$TORRENT_ID" --data "files=all" -H "Authorization: Bearer $TOKEN"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment