API Question - How to get Hash of New Download

Other platforms, generic questions.
Post Reply
lsnow99

API Question - How to get Hash of New Download

Post by lsnow99 »

Hi,

I am building an application that downloads torrents through qBittorrent. It uses the Web API to upload an http url for the torrent as specified here in the documentation: https://github.com/qbittorrent/qBittorr ... ew-torrent

This works, however, my application needs to have some way to manage this torrent later on. I understand that qBittorrent's API allows me to manage torrents by their hash, but I don't have that on hand. Ideally qBittorrent would return the hash of the newly added torrent or at least some ID that I could use to manage the torrent going forward.

The only solution I can think of is to manually fetch the torrent file from the url and then decode the bencoded contents and compute the info hash myself (a process which has proved somewhat tedious so far). Is there a better way to do this that avoids me having to make the request in my application to compute the info hash?

Thanks
User avatar
Peter
Administrator
Administrator
Posts: 2701
Joined: Wed Jul 07, 2010 6:14 pm

Re: API Question - How to get Hash of New Download

Post by Peter »

The torrent file itself contains the hash, that's the whole point of the .torrent files.
So you can just use whatever library (Android, C#, Python) depending on what platform your app is for.
Once you read out the hash, boom.

But you can also get the transfer list.
Then simply get the latest torrent or you can pick them by name.
But then again, you do have the hash from the getgo.
lsnow99

Re: API Question - How to get Hash of New Download

Post by lsnow99 »

Peter wrote: Fri Dec 17, 2021 9:04 pm The torrent file itself contains the hash, that's the whole point of the .torrent files.
So you can just use whatever library (Android, C#, Python) depending on what platform your app is for.
Once you read out the hash, boom.

But you can also get the transfer list.
Then simply get the latest torrent or you can pick them by name.
But then again, you do have the hash from the getgo.
Thank you Peter, yeah I guess I can't avoid making the HTTP request to get the torrent file and compute the hash. All good, thanks for confirming!
User avatar
Peter
Administrator
Administrator
Posts: 2701
Joined: Wed Jul 07, 2010 6:14 pm

Re: API Question - How to get Hash of New Download

Post by Peter »

Nono I mean the .torrent has the hash. When you recheck the files in qBittorrent or any other client, they check based on the .torrent file.
lsnow99

Re: API Question - How to get Hash of New Download

Post by lsnow99 »

Peter wrote: Fri Dec 17, 2021 9:59 pm Nono I mean the .torrent has the hash. When you recheck the files in qBittorrent or any other client, they check based on the .torrent file.
Correct me if I'm wrong. The .torrent is a bencoded dictionary containing info about the torrent. The info hash of the torrent is what I need and to calculate that I must hash the info section of the bencoded dictionary.

I only have the URL for the .torrent file. I must make the HTTP request to download the .torrent file and then decode the contents, and take the sha1 hash of the info section. This is what I said in my reply and what I was originally trying to avoid. Am I missing something here or are we on the same page?

Thanks,
Logan
User avatar
Peter
Administrator
Administrator
Posts: 2701
Joined: Wed Jul 07, 2010 6:14 pm

Re: API Question - How to get Hash of New Download

Post by Peter »

Whoops, sorry about that. Yeah, you have to fetch it (even if into just memory). I managed to miss that part - that you are directly downloading a URL, instead of uploading a .torrent file.
Post Reply