Sign in to follow this  
Followers 0

Downloading .torrent files with InetGet

10 posts in this topic

Hi Guys,

I'm trying to create a program that'll download .torrent files for me automatically and place them in a folder so uTorrent starts downloading them.

The whole script works flawless (for now) except for the most important part: Downloading the .torrent file.

It works, it downloads the .torrent file perfectly, but for some reason uTorrent gives me the error that 'the torrent file was not correctly encoded'.

For some reason downloading the torrent with InetGet instead of my browser, fucks it up. The size of the torrent is exactly the same as that of the one I download with my browser, still the files are different.

This is my script:

#cs ----------------------------------------------------------------------------

 AutoIt Version:
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <INet.au3>
#include <Array.au3>
$downloadfolder = 'C:\Users\Ludo\Downloads\torrents'

$searchquiry = StringReplace('the hobbit desolation of smaug', ' ', '+')
$preferedsite = 'kickmirror'
$link = ''&$searchquiry
$source = _INetGetSource($link, True)
$S1 = StringSplit($source, '<a rel="nofollow" href="/searchA?f='&$searchquiry&'"> date </a> |  <a rel="nofollow" href="/searchS?f='&$searchquiry&'"> size </a> |  <b> peers </b></h3>', 1)
$S2 = StringSplit($S1[2], '<dl><dt style="text-align: right">', 1)
$S3 = StringSplit($S2[1], @LF, 1)
global $torrents[$S3[0]+1][7]
$torrents[0][0] = $S3[0]-1
;   Form of $torrents[a][b] for b:
;       $torrents[a][0] = total string
;       $torrents[a][1] = torrent url
;       $torrents[a][2] = torrent title
;       $torrents[a][3] = torrent size
;       $torrents[a][4] = torrent seeders
;       $torrents[a][5] = torrent peers
;       $torrents[a][6] = torrent type

For $i = 1 to $torrents[0][0]
    ;MsgBox(0, '', _StringBetw($S3[$i], '<a href="', '">'))
    $torrents[$i][0] = $S3[$i]
    $torrents[$i][1] = _StringBetw($S3[$i], '<a href="', '">')
    $torrents[$i][2] = _StringStrip(_StringBetw($S3[$i], '<a href="'&$torrents[$i][1]&'">', '</a>'))
    $temp1 = StringSplit($S3[$i], '</a> &#187; ', 1)
    $temp2 = StringSplit($temp1[2], '</dt><dd>', 1)
    $temp3 = StringSplit($S3[$i], '</span></span><span class="s">', 1)
    $temp4 = StringSplit($temp3[2], '</span> <span class="u">', 1)
    $temp5 = StringSplit($temp4[2], '</span><span class="d">', 1)
    $temp6 = StringSplit($temp5[2], '</span>', 1)
    $torrents[$i][3] = $temp4[1]
    $torrents[$i][4] = $temp5[1]
    $torrents[$i][5] = $temp6[1]
    $torrents[$i][6] = $temp2[1]


$source2 = _INetGetSource(''&$torrents[1][1])
$A1 = StringSplit($source2, ' torrent download locations</h2><dl><dt>', 1)
$A2 = StringSplit($A1[1], '</span> ', 1)
$A3 = StringSplit($A1[2], '<a href="', 1)
$locations = $A2[$A2[0]]
global $tors[$locations+1]
$n = 0
For $i = 2 to $locations
    $A4 = StringSplit($A3[$i], '" ', 1)
    $tors[$i] = $A4[1]
    If StringInstr($tors[$i], $preferedsite) Then
        $n = $i
If $n = 0 Then
    Msgbox(32, 'Too bad', 'No kickmirror torrent links found..')

$source3 = _INetGetSource($tors[$n], True)

;$B1 = _StringBetw($source3, '<a title="Magnet link" href="', '"')

$B1 = _StringBetw($source3, '<a rel="nofollow" title="Download verified torrent file" href="', '"')
$B2 = StringSplit($B1, '.torrent?title=', 1)
$finallink = $B2[1]&'.torrent'
InetGet($finallink,$downloadfolder&'\'&$B2[2]&'.torrent', 4)

MsgBox(32, 'Succes', 'Torrent started downloading!')
Func _StringBetw($string, $start, $end)
    $pa = StringSplit($string, $start, 1)
    If $pa[0] <  2 Then Return 0
    $pb = StringSplit($pa[2], $end, 1)
    Return $pb[1]

Func _StringStrip($string)
    $s = StringReplace($string, '<b>', '')
    $s1 = StringReplace($s, '</b>', '')
    Return $s1

Please try it out, then try to run the torrent with utorrent or some other torrent downloader.

If somebody knows what the problem is, I'd be very happy if you'd help me here!

Thnx in advance,


Share this post

Link to post
Share on other sites

#2 ·  Posted (edited)

You can't, in a torrent downloaded using Inetget there are tracker data missing in the file

But if you win out getting the magnet link then it works

Edited by mikell

Share this post

Link to post
Share on other sites

Why are you treating the binary torrent files as ASCII?

InetGet($finallink,$downloadfolder&'\'&$B2[2]&'.torrent', 4)

change it to


and try again.

I haven't tried your code but that should work. :)

Good Luck!

Share this post

Link to post
Share on other sites

#4 ·  Posted (edited)

@Mikell: Ah so that's the problem. Well too bad. Yes I know, that's the alternitave I came up with. Still I'd rather download the direct torrent file.

Could there be some other way then InetGet that can download a torrent file?

@Storme: Nope, I was just experimenting, and apparently didn't change the 4 back to nothing. But none of the opts work for those torrent files.

Edited by ludocus

Share this post

Link to post
Share on other sites

@Storme: Nope, I was just experimenting, and apparently didn't change the 4 back to nothing. But none of the opts work for those torrent files.


I use

$hDownload = InetGet($sDownloadURL & $sfilename, $sTorrentFolder & "\" & $sfilename)

To download torrents for my "DriverPacksAutoUpdate" script and it works perfectly.

Share this post

Link to post
Share on other sites

Weird, it doesn't work for me. Try my script.

Share this post

Link to post
Share on other sites

Works perfectly for me :oops:

Maybe compile and try it on another computer to see if it's something on yours that is messing up?

Good Luck!

Share this post

Link to post
Share on other sites

Look here at the Torcache home page.


The torrent files are saved to disk in gzip format, that means you have to use a browser that understands the gzip transfer encoding.

So what you are doing is downloading a file that is compressed in gzip format. You could use 7-zip to extract the file after downloading. :)

Share this post

Link to post
Share on other sites

Thnx MHz,

I'll look in to that. Any other, simpler way than using 7zip?

Share this post

Link to post
Share on other sites

.Net has the GZipStream class but I have doubt that is any good for this. You could use GZip.exe here (about 90kb) and keep that with the script. Perhaps something is exposed in COM usage but I have not found it yet.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello all
      I have a question please
      I've searched a lot on how to make a GUI for programs designed by Autoit to accepts dragging files from Windows File Explorer
      Unfortunately, however, it failed
      Is there any way to do this?
      Where I am making a audio player and I want to activate the feature of dragging files from Windows Explorer to a program window to play them
      I hope to find a simple solution here in this wonderful forum
      Thank you very much in advance
    • nacerbaaziz
      By nacerbaaziz
      hello dears
      First I would like to apologize to you for my many questions.
      I have a new question if you allow
      I am programming an audio player for blinds
      I had a problem
      I put an option in the folders context menu to Opens the audio files that in the selected folder
      I did not know how to make the Autoit Search the subfolders
      Please provide an example of how to search for  files in the subfolders
      Let's say, for example, MP3 files
      Just give me a simple example and I will try to modify it as appropriate for the program I designing it
      Please help me to find the solution
      Thanks in advance
    • Ignacio
      By Ignacio
      Hello, and good day
      Im trying to make a sentence autocompleter so that when you type certain words (or commands) the scripts, and im in need of help/pointers
      That is what i have at the time and the issues i have currently is that:
      - I cant find an easy way to reset the counter to 0 in case a different letter from those are pressed ( tried NOT _ispressed but i think i got it wrong)
      -Is there another way to detect the key press that _ispressed? (i couldnt find it so far), since i feel like it is too clunky ( although maybe that is just me and my way to code)
      - for some reason the hex code (6F) for the / (divide nume pad) isnt working for me
      Im thinking of making a text file with some words to use them as variables/comparations  (so that at least removes the need of a variable for the words in the script) and make the script make a temporal text file to save the input and then compare it with the other one. But i dont know if that is a good approach.
      Thanks for your time and patience.
    • UEZ
      By UEZ
      Here a small tool I wrote to update my Sysinternal tools collection without the need to download always the whole package or visiting the site to check for updates. I know that there are several tools available (also some tools written in AutoIt) but here another one for the collection. It was good exercise for me to code it.
      Some files from cannot be downloaded although they are visible on the web site!
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.1 build 2017-10-23 beta.7z  (1353 downloads previously)
      -=> Requires AutoIt version or higher / tested on Win8.1 real machine and some VMs: Win7 / Vista / Win10
      Compiled exe only: @MediaFire
      Just select the Sysinternal Tools folder or create one and press the synchronize button to download the selected items. Click on AutoIt label (near to left upper corner) to open menu.
      Special thanks to LarsJ, Melba23 and mesale0077 for their help. 
      I've still some ideas to implement which are more gimmick related, so it is not finished yet...
      If you want to add your language please check out #Region Language. Thanks. 
      Please report any bug or if you have any suggestions.
      The language of the tool tip from each of the executable in the left list view were automatically created using Google translator and weren't checked for correctness.
    • leb
      By leb
      Hello there,
      I am using the function InetGet example in the help files on a website and getting the error 13. First, I searched the help files and the forum for a list of errors to consult to no avail. I suspect this is a 400's server reply based error but it would be nice to get more info about it.
      Please help, thanks.