Cookies support on qBittorrent

qbittorrent
Like most people I used to use μTorrent to download files using the Bittorrent protocol or like they say now, to download torrents.

Since version 3.x of μTorrent some people like me got away from it, since it became bloatware. That all started when it was purchased by BitTorrent, Inc., and the client has gone down hill from there.  It’s still the most popular torrent client on the planet though.

So I moved to qBittorrent which is a wonderful client, but it lacks a feature that I really use and need: the ability to specify cookies when downloading a torrent from a URL using the WebUI.

I also wanted another little feature that I really need: the forms have to support the autocomplete feature of the internet browsers.  So when I fill a field in a form, the browser saves it for future use. For this to work the forms need to be actual forms, and you’ll see qBittorrent doesn’t use them.

Since qBittorrent is an Open Source project, it’s pretty easy to implement new features on.

Note: All this post is be based in qBittorrent beta version 3.3.0 + gitd60f2fc

Let’s take a look at the download page located at src/webui/www/public/download.html:

As you can see it’s not a real HTML form.  It’s just a single field with a button. Then there’s some JavaScript to make a REST request to download the URL that the user types in the field. This is src/webui/www/public/scripts/download.js:

Since it is not a real form, this won’t allow my browser to save the fields so I can reuse them.  I don’t want to copy/paste the same cookie over and over, so I had to modify this into a real form. Here’s what I want:

qbitorrent-download

And this is what I came up with:

QBT_TR(Download Torrents from their URLs or Magnet links)QBT_TR

QBT_TR(Only one link per line)QBT_TR

So basically I’m doing three things here:

  • Including a field for the download location and retrieving the default location via REST from the server.  That’s because I want my downloads organized in several folders.
  • Including a cookie field where I can type all the cookies if I’m downloading from a URL of a private site that needs an authentication first.
  • Also I added a label field to set the label and keep things organized.

From the server side I had to include the cookies in the AddTorrentParams, that’s a structure that contains several torrents parameters.  I included:

And modified a little bit the command/download request from the server side, to include the parsing of the cookies

I was losing the trick of closing the window automatically when the download is complete, since I’m not using click event of the downButton.  The only solution I could came up with was to send an HTML back that closed the window from the server. That’s the last line you see there in the code with a window.parent.closeWindows().

Now all I need that the DownloadManager actually send the cookies header in the download request, so I changed the downloadUrl() function a little bit, adding a new argument and setting the cookies:

And that’s it and it works really great. Now see it in action:

qbitorrent-download-blur

Yay! The browser saved the last cookie I used!

If you’re interested in the whole patch you can see the code here.

Leave a Reply