Jump to content
Sign in to follow this  
ludocus

Downloading .torrent files with InetGet

Recommended Posts

ludocus

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: 3.3.8.1
 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 = 'http://torrentz.eu/search?f='&$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]
Next


;_ArrayDisplay($torrents)
;ClipPut($torrents[1][1]&@CRLF&@CRLF&$torrents[$torrents[0][0]][2])

$source2 = _INetGetSource('http://torrentz.eu/'&$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
    EndIf
Next
If $n = 0 Then
    Msgbox(32, 'Too bad', 'No kickmirror torrent links found..')
    Exit
EndIf

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

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

$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]
EndFunc

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

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,

Ludo

Share this post


Link to post
Share on other sites
mikell

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

Shellexecute("magnet:?xt=urn:btih:A8F9179F064E97184D6FD005F921D6D786FD84CF&dn=the+hobbit+ii+the+desolation+of+smaug+2013+xvid+dd2+0+screener+custom+nlsubs+nltoppers&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337")
Edited by mikell

Share this post


Link to post
Share on other sites
storme

Why are you treating the binary torrent files as ASCII?

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

change it to

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

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
ludocus

@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

@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
ludocus

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

Share this post


Link to post
Share on other sites
storme

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
MHz

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
ludocus

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
MHz

.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  

  • Similar Content

    • Schneeflocke
      By Schneeflocke
      #RequireAdmin
      #include <NomadMemory.au3>
      $Value = _Pointer()
      MsgBox(0,"", "Value: " = $Value)
      Func _Pointer()
      Global $iBase = 0x7FF649DB0000, $iStaticofsset = 0x01559C08
      Global $hOpen, $sRead
      $hOpen = _MemoryOpen(ProcessExists("Tutorial-i386.exe"))
      $sRead = _Memoryread($iBase + $iStaticoffset, $hOpen, 'Float') + 0x70
      $sRead = _Memoryread($iBase + $iStaticoffset, $hOpen, 'Float') + 0xA0
      $sRead = _Memoryread($iBase + $iStaticoffset, $hOpen, 'Float') + 0x20
      $sRead = _Memoryread($iBase + $iStaticoffset, $hOpen, 'Float') + 0x1B0
      $sRead = _Memoryread($iBase + $iStaticoffset, $hOpen, 'Float') + 0x40
      $sRead = _Memoryread($iBase + $iStaticoffset, $hOpen, 'Float') + 0x10
      $sRead = _Memoryread($iBase + $iStaticoffset, $hOpen, 'Float') + 0x368
      $sValue = _Memoryread($sRead, $hOpen, 'Float')
      _MemoryClose($hOpen)
      Return $sValue
      EndFunc
      I Would like to create an Round Timer and Kers BoT for Assetto Corsa.
      Intelliboost need too many Performance
    • Pagi
      By Pagi
       
      <a href="index.php=4143b27b41db0a40c499202865c3e24d" class="menuitem " target="\_self"> "Menu Item 1" </a>
      Can you tell me if it´s possible to click this menu button? If yes, how? Cause I have no idea, I think i should use _IETagNameGetCollection
    • milkmoron
      By milkmoron
      https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/?do=findComment&comment=1156373 At least we have an element title: [Entered By:] class: [WindowsForms10.EDIT.app.0.30495d1_r9_ad1] Having the following values for all properties: Title is: <Entered By:> Class := <WindowsForms10.EDIT.app.0.30495d1_r9_ad1> controltype:= <UIA_EditControlTypeId> ,<50004> , (0000C354) 322;370;736;184 *** Parent Information top down *** 3: Title is: <View Activity> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_WindowControlTypeId> ,<50032> , (0000C370) 306;72;784;605 "Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 2: Title is: <> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;103;768;542 "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 1: Title is: <> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;103;749;451 "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 0: Title is: <Delete> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;122;749;432 "Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ;View Activity _UIA_setVar("oP2","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ; _UIA_setVar("oP3","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ; _UIA_setVar("oP4","Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ;Delete _UIA_setVar("EnteredBy:.mainwindow","title:=Entered By:;classname:=WindowsForms10.EDIT.app.0.30495d1_r9_ad1") ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") ;~_UIA_Action("oP4","highlight") _UIA_Action("oP4","setfocus") _UIA_action("EnteredBy:.mainwindow","setfocus") ;~ *** Standard code Flexible*** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP3,"setfocus") Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP2,"setfocus") Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP1,"setfocus") Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP0,"setfocus") _UIA_setVar("EnteredBy:.mainwindow","title:=Entered By:;classname:=WindowsForms10.EDIT.app.0.30495d1_r9_ad1") _UIA_action("EnteredBy:.mainwindow","setfocus") Need some help selecting this defining it as a variable to save and then insert the text within, to the same application but different account.
    • PleaseHelpMEIWillLoveyou
      By PleaseHelpMEIWillLoveyou
      Is there a way to use a custom terminal or something from my pc and run a script on another pc.
      please let me know if its possible
      (not for anything bad just for a project im working on)
    • kelso
      By kelso
      Hello Guru's,
       
      I'm trying to write an autoit script to select from the dropdown list as you see in the attached picture. 
      I read the help page for _IEFormElementOptionSelect, but I cannot grasp how to correlate that with the source code that I'm seeing. any suggestions?

×