Advertisement
Guest User

Automatic way to stop the seeding in uTorr

a guest
Jan 11th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     'Leecher app is an automatic way to stop the seeding in uTorrent client.
  2.     'This app works on all Win32 (MS Windows).
  3.     '
  4.     'Leecher
  5.     '(C) Rui Branco - rmrbranco at gmail dot com
  6.     'Project home https://drive.google.com/folderview?id=0B5MAgOEuMAVadE1oZnJxUzVrTDA&usp=sharing
  7.     '
  8.     'Resource
  9.     'The compiler to make single exe and console app http://www.lbbooster.com/
  10.     'The language and compiler http://www.libertybasic.com/
  11.     'uTorrent software http://www.utorrent.com/intl/pt/
  12.     'Webui API http://forum.utorrent.com/viewtopic.php?pid=318056#p318056
  13.     'Support token authentication http://forum.utorrent.com/viewtopic.php?id=58111
  14.  
  15.  
  16.  
  17.  
  18.     'Changelog:
  19.     '11-01-2014 - Add webui support.
  20.     '07-01-2014 - Add anti collision names of files and folder.
  21.     '07-01-2014 - Add several checks existence of content.
  22.     '07-01-2014 - Add retry sending wm_close command in the case of the window not closing.
  23.     '06-01-2014 - Add function to save the steps in output.log.
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.     'Nomainwin somewhere in the program source code prevents the window from opening.
  37.     'You can uncomment if you want silent mode
  38.     'NOMAINWIN
  39.  
  40.     'Put lower the aguments sent by uTorrent in strings
  41.     argut$ = lower$(CommandLine$)
  42.     dir$ = lower$(CommandLine$)
  43.     title$ = lower$(CommandLine$)
  44.     hash$ = lower$(CommandLine$)
  45.  
  46.     'Get dir from alias appdata
  47.     utdir$ = Environ$("APPDATA")
  48.  
  49.     'Load config
  50.     gosub [loadconfig]
  51.  
  52.     'If argument is nothing call the sub
  53.     if not(argut$ <> "") then
  54.         gosub [info]
  55.  
  56.         'Wait to close window
  57.         wait
  58.  
  59.         'Exit
  60.         end
  61.  
  62.     else
  63.  
  64.         'If in argument exists utorrent word, the dir and the title will fitrate and put in strings
  65.         if instr(argut$, "utorrent") then
  66.             arg$ = mid$(argut$, 10, 6)
  67.             resulta$ = "µTorrent";arg$
  68.             dir$ = word$(dir$, 4, chr$(34))
  69.             title$ = word$(title$, 6, chr$(34))
  70.             hash$ = word$(hash$, 8, chr$(34))
  71.  
  72.             'Send info to the window
  73.             print "Leecher - automatic way to stop the seeding in uTorrent"
  74.             print ""
  75.             print ""
  76.             print "Output:"
  77.  
  78.             'Create log and call sub output
  79.             output$ = " " : gosub [output]
  80.             output$ = "- Start ";date$();" - ";time$() : gosub [output]
  81.             output$ = "Arg. ";argut$ : gosub [output]
  82.             if yesno$ = "no" then output$ = "Version ";arg$ : gosub [output]
  83.             if yesno$ = "no" then output$ = "Real Window name ";resulta$ : gosub [output]
  84.             if yesno$ = "no" then output$ = "Dir ";dir$ : gosub [output]
  85.             if yesno$ = "no" then output$ = "Title ";title$ : gosub [output]
  86.             if yesno$ = "yes" then output$ = "Hash ";hash$ : gosub [output]
  87.  
  88.             'The address with the data available in conf to make the request
  89.             action$ = "http://";login$;":";password$;"@";ip$;"/gui/?action=stop&hash=";hash$
  90.  
  91.             'Go to sub webui
  92.             if yesno$ = "yes" then gosub [webui]
  93.  
  94.         else
  95.  
  96.             'If argument not exists call sub
  97.             gosub [info]
  98.  
  99.             'Wait to close window
  100.             wait
  101.  
  102.             'Exit
  103.             end
  104.  
  105.         end if
  106.  
  107.     end if
  108.  
  109.     'Send close command to uTorrent
  110.     gosub [sendclose]
  111.  
  112.     'Loop
  113. [loop]
  114.  
  115.     'If window is closed rename the folder name or file name and kill the torrent file
  116.     'If you pull the .torrent in client via url or magnet link you will be without it.
  117.     if ut = 0 then
  118.         dim info$(10, 10)
  119.         if fileExists(dir$, title$) then
  120.             'Create output
  121.             if yesno$ = "no" then output$ = "Rename file " ;dir$;title$; " as Renamed by Leecher - " ; time$("milliseconds") ; " - " ; title$ : gosub [output]
  122.             name dir$;title$ as dir$;"Renamed by Leecher - " ; time$("milliseconds") ; " - " ; title$
  123.  
  124.         else
  125.  
  126.             dim info$(10,10 )
  127.             if folderExists(dir$) then
  128.                 'Create output
  129.                 if yesno$ = "no" then output$ = "Rename folder ";dir$; " as Renamed by Leecher - " ; time$("milliseconds") ; " - " ; title$ : gosub [output]
  130.                 name dir$ as dir$;" - Renamed by Leecher - " ; time$("milliseconds")
  131.  
  132.             else
  133.  
  134.                 'Create output
  135.                 if yesno$ = "no" then output$ = "The folder or file does not exist at this location ";dir$ : gosub [output]
  136.  
  137.             end if
  138.  
  139.         end if
  140.  
  141.         dim info$(10, 10)
  142.         if fileExists(utdir$;"\uTorrent\", title$;".torrent") then
  143.             'Create output
  144.             if yesno$ = "no" then output$ = "Kill torrent file ";utdir$;"\uTorrent\";title$;".torrent" : gosub [output]
  145.             kill utdir$;"\uTorrent\";title$;".torrent"
  146.  
  147.         else
  148.  
  149.             'Create output
  150.             if yesno$ = "no" then output$ = "The file .torrent does not exist at this location ";utdir$;"\uTorrent\";title$;".torrent" : gosub [output]
  151.  
  152.         end if
  153.  
  154.     else
  155.  
  156.         'Retry sending close command
  157.         gosub [sendclose]
  158.  
  159.         'Returned from the sub now recheck uTorrent is already closed
  160.         goto [loop]
  161.  
  162.     end if
  163.  
  164.     'Check if uTorrent.exe exists
  165.     dim info$(10, 10)
  166.     if fileExists(utdir$;"\uTorrent\", "uTorrent.exe") then
  167.         'Create output
  168.         if yesno$ = "no" then output$ = "Start uTorrent ";utdir$;"\uTorrent\";"uTorrent.exe" : gosub [output]
  169.         'Finally run utorrent and show minimized
  170.         run utdir$;"\uTorrent\";"uTorrent.exe", SHOWMINIMIZED
  171.         'Create output
  172.         output$ = "- End ";date$();" - ";time$() : gosub [output]
  173.  
  174.     else
  175.  
  176.         'Create output
  177.         if yesno$ = "no" then output$ = "The file uTorrent.exe does not exist at this location ";utdir$;"\uTorrent\";"uTorrent.exe" : gosub [output]
  178.         output$ = "- End ";date$();" - ";time$() : gosub [output]
  179.  
  180.     end if
  181.  
  182.     'Exit
  183.     end
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.     'Subs/Functions
  198. [info]
  199.     'Show info
  200.     print "-Help, using Leecher in uTorrent(desktop):"
  201.     print "You need the exactly title of the window and uTorrent parameters."
  202.     print ""
  203.     print "(1)In uTorrent go to,"
  204.     print "   Options/preferences/UI Settings."
  205.     print "   Remove value true in (Close button closes uT to tray)"
  206.     print ""
  207.     print "(2)Options/preferences/UI Settings."
  208.     print "   Remove value true in (Show confirmation dialog on exit)"
  209.     print ""
  210.     print "(3)Options/preferences/Advanced/Run Program."
  211.     print "   In box (...when a torrent finishes) put app this way"
  212.     print "   C:\..\.\Leecher.exe" + chr$(34) + " " + chr$(34) + "uTorrent 3.3.2" + chr$(34) + " " + chr$(34) + "%D" + chr$(34) + " " + chr$(34) + "%N" + chr$(34)
  213.     print ""
  214.     print ""
  215.     print ""
  216.     print "-Help using Leecher in uTorrent with Webui(Web)"
  217.     print "(1)If you want to perform these actions via webui only. "
  218.     print "   go to Options/preferences/Advanced/Run Program. In box"
  219.     print "   (...when a torrent finishes) put app this way"
  220.     print "   C:\..\.\Leecher.exe" + chr$(34) + " " + chr$(34) + "uTorrent 3.3.2" + chr$(34) + " " + chr$(34) + "%D" + chr$(34) + " " + chr$(34) + "%N" + chr$(34) + " " + chr$(34) + "%I" + chr$(34)
  221.     print ""
  222.     print "(2)Go to Options/preferences/Advanced/"
  223.     print "   search for webui.token_auth and change the value to true."
  224.     print ""
  225.     print "(3)Finally, open config.conf and enter the required data"
  226.     print ""
  227.     print ""
  228.     print ""
  229.     print "Leecher - automatic way to stop the seeding in uTorrent"
  230.     print "Rui Branco - rmrbranco at gmail dot com"
  231.  
  232.  
  233.     RETURN
  234.  
  235.  
  236. [webui]
  237.     'By Brent D. Thorn, 9/2005
  238.  
  239.     'enough bytes to hold a single line of HTML
  240.     CHUNK.SIZE = 512
  241.  
  242.     Open "wininet" For DLL As #inet
  243.  
  244.     'It would be a good idea to test for an Internet
  245.     'connection before proceding. This demo assumes
  246.     'you have one already.
  247.  
  248.     ' Register a new user agent. Use proxy settings
  249.     ' set up in Internet Options Control Panel.
  250.     CallDLL #inet, "InternetOpenA", _
  251.         "My User Agent" As Ptr, _
  252.         0 As Long, _ 'INTERNET_OPEN_TYPE_PRECONFIG
  253.         _NULL As Long, _
  254.         _NULL As Long, _
  255.         0 As ULong, _
  256.         hInet As ULong
  257.     If hInet = 0 Then [ErrExit]
  258.  
  259.     ' Open a request to a remote file
  260.     CallDLL #inet, "InternetOpenUrlA", _
  261.         hInet As ULong, _
  262.         action$ As Ptr, _
  263.         _NULL As Long, _
  264.         0 As Long, _
  265.         2147483648 As ULong, _ 'INTERNET_FLAG_RELOAD
  266.         _NULL As Long, _
  267.         hFile As ULong
  268.     If hFile = 0 Then [ErrExit]
  269.  
  270.     ' Start reading in the file by chunks.
  271.     Buffer$ = ""
  272.     chunk$ = Space$(CHUNK.SIZE)+Chr$(0)
  273.     Struct pdw, NumberOfBytesRead As ULong
  274.     Do
  275.     CallDLL #inet, "InternetReadFile", _
  276.         hFile As ULong, _
  277.         chunk$ As Ptr, _
  278.         CHUNK.SIZE As ULong, _
  279.         pdw As Struct, _
  280.         ret As Long
  281.  
  282.     If pdw.NumberOfBytesRead.struct = 0 Then Exit Do
  283.  
  284.     Buffer$ = Buffer$ + Left$(chunk$, pdw.NumberOfBytesRead.struct)
  285.     Loop Until 0
  286.  
  287.     'Create output
  288.     output$ = "Action, Stop " ; title$ : gosub [output]
  289.     output$ = "Webui output " ; Buffer$ : gosub [output]
  290.  
  291. [ErrExit]
  292.     ' If you get an error, find GetLastError on MSDN. There
  293.     ' you will find a link to a list of error codes.
  294.     CallDLL #kernel32, "GetLastError", ret As ULong
  295.     If ret and yesno$ = "yes" Then Print "Error Webui";ret
  296.  
  297.     ' Free the handles we created and exit.
  298.     If hFile Then _
  299.         CallDLL #inet, "InternetCloseHandle", _
  300.         hFile As ULong, ret As Long
  301.  
  302.     If hInet Then _
  303.         CallDLL #inet, "InternetCloseHandle", _
  304.         hInet As ULong, ret As Long
  305.  
  306.     ' Strangely, the next line causes LB to hang for around 45
  307.     ' seconds on my computer, a 2.2 GHz running XP on dial-up.
  308.     Close #inet
  309.  
  310.     'Create output
  311.     output$ = "- End ";date$();" - ";time$() : gosub [output]
  312.  
  313.     'Exit
  314.     End
  315.  
  316.  
  317. [output]
  318.     'Create and show output info
  319.     open "output.log" for append as #log
  320.     print #log, output$
  321.     close #log
  322.  
  323.     print output$
  324.  
  325.  
  326.     RETURN
  327.  
  328.  
  329. [sendclose]
  330.     'Find utorrent window
  331.     CallDLL #user32, "FindWindowA",_
  332.         _NULL as ulong,_
  333.         resulta$ as ptr,_
  334.         ut as ulong
  335.  
  336.     'Create output
  337.     if ut = 0 then
  338.         output$ = "Window looks closed ";ut : gosub [output]
  339.     else
  340.         output$ = "Find Window ";ut : gosub [output]
  341.     end if
  342.  
  343.     'Send Close command to utorrent
  344.     Calldll #user32, "SendMessageA", _
  345.         ut as ulong, _
  346.         _WM_CLOSE as long, _
  347.         result as long
  348.  
  349.     'Create output
  350.     if ut = 0 then
  351.         output$ = "Window is closed ";ut : gosub [output]
  352.     else
  353.         output$ = "Send close to window ";ut : gosub [output]
  354.     end if
  355.  
  356.  
  357.     RETURN
  358.  
  359.  
  360. [loadconfig]
  361.     'Check if config exists
  362.     dim info$(10, 10)
  363.     if fileExists(DefaultDir$, "config.conf") then
  364.  
  365.         open "config.conf" for input as #lconf
  366.         LINE INPUT #lconf, null$
  367.         LINE INPUT #lconf, null$
  368.         LINE INPUT #lconf, null$
  369.         LINE INPUT #lconf, yesno$
  370.         LINE INPUT #lconf, null$
  371.         LINE INPUT #lconf, null$
  372.         LINE INPUT #lconf, ip$
  373.         LINE INPUT #lconf, null$
  374.         LINE INPUT #lconf, null$
  375.         LINE INPUT #lconf, login$
  376.         LINE INPUT #lconf, null$
  377.         LINE INPUT #lconf, null$
  378.         LINE INPUT #lconf, password$
  379.         LINE INPUT #lconf, null$
  380.         LINE INPUT #lconf, null$
  381.         LINE INPUT #lconf, null$
  382.         close #lconf
  383.  
  384.     else
  385.  
  386.         'Create a default config
  387.         open "config.conf" for output as #lconf
  388.         print #lconf, "#Leecher CONFIG"
  389.         print #lconf, " "
  390.         print #lconf, "#Webui [yes/no]"
  391.         print #lconf, "no"
  392.         print #lconf, " "
  393.         print #lconf, "#Webui [ip]:[port]"
  394.         print #lconf, "localhost:8080"
  395.         print #lconf, " "
  396.         print #lconf, "#Webui [login]"
  397.         print #lconf, "jonh"
  398.         print #lconf, " "
  399.         print #lconf, "#Webui [password]"
  400.         print #lconf, "1213234sfd334"
  401.         print #lconf, " "
  402.         print #lconf, "#Webui action [stop]"
  403.         print #lconf, "not yet implemented"
  404.         close #lconf
  405.  
  406.     end if
  407.  
  408.  
  409.     RETURN
  410.  
  411.  
  412.     'Retrieves the contents of the specified variable from the environment block of the calling process.
  413. Function Environ$(varName$)
  414.     retBufr$ = space$(127) : nSize = len(retBufr$)
  415.     CallDll #kernel32, "GetEnvironmentVariableA",_
  416.         varName$ as ptr,_
  417.         retBufr$ as ptr,_
  418.         nSize as long,_
  419.         ret as long
  420.     Environ$ = trim$(retBufr$)
  421. End Function
  422.  
  423.  
  424. 'Function which can be used to test if a file exists on disk.
  425. function fileExists(path$, filename$)
  426.     files path$, filename$, info$()
  427.     fileExists = val(info$(0, 0))
  428. end function
  429.  
  430.  
  431. 'Function which can be used to test if a folder exists on disk.
  432. function folderExists(path$)
  433.     folderExists = fileExists(path$, "nul")
  434. end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement