Page 1 of 1

CURL to download torrent

Posted: Wed Jun 15, 2016 8:39 pm
by tresrrr
I am trying to make a applescript to send the torrents from local MAC, with POST method to begin the download.

The command I use:

Code: Select all

curl http://12.18.0.2:8081/command/upload --cookie "SID=" MyID " --header 'Content-Disposition: form-data; name="torrents"; filename="TorrentName"' --header 'Content-Type: application/x-bittorrent' --data 'TorrentFile'
The TorrentFile var is the posix path of the torrent.

After following the WebUI API Documentation: https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-Documentation
I just can't figure out how to to compose the CURL POST method to make it work.

Appreciate any help

Re: CURL to download torrent

Posted: Thu Sep 12, 2019 8:19 am
by basecase
Same here. I think they should just have a more detailed example in the documentation.

Re: CURL to download torrent

Posted: Thu Nov 11, 2021 2:36 am
by bmfrosty
Wrote a dumb script. It assumes that you're using the setting where it skips authentication if you're coming from a specific CIDR block. It basically uploads all the torrents in a directory. Make sure you fill in the environment variables for your setup:

Code: Select all

#!/bin/bash

DIRECTORY=
cd $DIRECTORY

QBT_CATEGORY=
QBT_HOST=
QBT_PORT=8080
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

for i in $(ls -1 | grep torrent$) ; do
  RANDSTRING=$(((RANDOM%100000000+100000000)))
  mv $i $RANDSTRING.torrent
  torrentFileName=$RANDSTRING.torrent
  echo "Uploading $i"
  curl -X POST --form category=$QBT_CATEGORY --form root_folder=false --form "torrents=@$torrentFileName" http://$QBT_HOST:$QBT_PORT/api/v2/torrents/add   
  echo ""
  if [ $? -eq 0 ] ; then
    rm $torrentFileName
  else
    echo "Error uploading $i"
    mv $RANDSTRING.torrent $i
  fi
done


IFS=$SAVEIFS


Re: CURL to download torrent

Posted: Thu Nov 11, 2021 2:54 am
by bmfrosty
now I know qbittorrent-cli exists. I think I'll be rewriting this.