Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Leecher app is an automatic way to stop the seeding in uTorrent client.
- 'This app works on all Win32 (MS Windows).
- '
- 'Leecher
- '(C) Rui Branco - rmrbranco at gmail dot com
- 'Project home https://drive.google.com/folderview?id=0B5MAgOEuMAVadE1oZnJxUzVrTDA&usp=sharing
- '
- 'Resource
- 'The compiler to make single exe and console app http://www.lbbooster.com/
- 'The language and compiler http://www.libertybasic.com/
- 'uTorrent software http://www.utorrent.com/intl/pt/
- 'Webui API http://forum.utorrent.com/viewtopic.php?pid=318056#p318056
- 'Support token authentication http://forum.utorrent.com/viewtopic.php?id=58111
- 'Changelog:
- '11-01-2014 - Add webui support.
- '07-01-2014 - Add anti collision names of files and folder.
- '07-01-2014 - Add several checks existence of content.
- '07-01-2014 - Add retry sending wm_close command in the case of the window not closing.
- '06-01-2014 - Add function to save the steps in output.log.
- 'Nomainwin somewhere in the program source code prevents the window from opening.
- 'You can uncomment if you want silent mode
- 'NOMAINWIN
- 'Put lower the aguments sent by uTorrent in strings
- argut$ = lower$(CommandLine$)
- dir$ = lower$(CommandLine$)
- title$ = lower$(CommandLine$)
- hash$ = lower$(CommandLine$)
- 'Get dir from alias appdata
- utdir$ = Environ$("APPDATA")
- 'Load config
- gosub [loadconfig]
- 'If argument is nothing call the sub
- if not(argut$ <> "") then
- gosub [info]
- 'Wait to close window
- wait
- 'Exit
- end
- else
- 'If in argument exists utorrent word, the dir and the title will fitrate and put in strings
- if instr(argut$, "utorrent") then
- arg$ = mid$(argut$, 10, 6)
- resulta$ = "µTorrent";arg$
- dir$ = word$(dir$, 4, chr$(34))
- title$ = word$(title$, 6, chr$(34))
- hash$ = word$(hash$, 8, chr$(34))
- 'Send info to the window
- print "Leecher - automatic way to stop the seeding in uTorrent"
- print ""
- print ""
- print "Output:"
- 'Create log and call sub output
- output$ = " " : gosub [output]
- output$ = "- Start ";date$();" - ";time$() : gosub [output]
- output$ = "Arg. ";argut$ : gosub [output]
- if yesno$ = "no" then output$ = "Version ";arg$ : gosub [output]
- if yesno$ = "no" then output$ = "Real Window name ";resulta$ : gosub [output]
- if yesno$ = "no" then output$ = "Dir ";dir$ : gosub [output]
- if yesno$ = "no" then output$ = "Title ";title$ : gosub [output]
- if yesno$ = "yes" then output$ = "Hash ";hash$ : gosub [output]
- 'The address with the data available in conf to make the request
- action$ = "http://";login$;":";password$;"@";ip$;"/gui/?action=stop&hash=";hash$
- 'Go to sub webui
- if yesno$ = "yes" then gosub [webui]
- else
- 'If argument not exists call sub
- gosub [info]
- 'Wait to close window
- wait
- 'Exit
- end
- end if
- end if
- 'Send close command to uTorrent
- gosub [sendclose]
- 'Loop
- [loop]
- 'If window is closed rename the folder name or file name and kill the torrent file
- 'If you pull the .torrent in client via url or magnet link you will be without it.
- if ut = 0 then
- dim info$(10, 10)
- if fileExists(dir$, title$) then
- 'Create output
- if yesno$ = "no" then output$ = "Rename file " ;dir$;title$; " as Renamed by Leecher - " ; time$("milliseconds") ; " - " ; title$ : gosub [output]
- name dir$;title$ as dir$;"Renamed by Leecher - " ; time$("milliseconds") ; " - " ; title$
- else
- dim info$(10,10 )
- if folderExists(dir$) then
- 'Create output
- if yesno$ = "no" then output$ = "Rename folder ";dir$; " as Renamed by Leecher - " ; time$("milliseconds") ; " - " ; title$ : gosub [output]
- name dir$ as dir$;" - Renamed by Leecher - " ; time$("milliseconds")
- else
- 'Create output
- if yesno$ = "no" then output$ = "The folder or file does not exist at this location ";dir$ : gosub [output]
- end if
- end if
- dim info$(10, 10)
- if fileExists(utdir$;"\uTorrent\", title$;".torrent") then
- 'Create output
- if yesno$ = "no" then output$ = "Kill torrent file ";utdir$;"\uTorrent\";title$;".torrent" : gosub [output]
- kill utdir$;"\uTorrent\";title$;".torrent"
- else
- 'Create output
- if yesno$ = "no" then output$ = "The file .torrent does not exist at this location ";utdir$;"\uTorrent\";title$;".torrent" : gosub [output]
- end if
- else
- 'Retry sending close command
- gosub [sendclose]
- 'Returned from the sub now recheck uTorrent is already closed
- goto [loop]
- end if
- 'Check if uTorrent.exe exists
- dim info$(10, 10)
- if fileExists(utdir$;"\uTorrent\", "uTorrent.exe") then
- 'Create output
- if yesno$ = "no" then output$ = "Start uTorrent ";utdir$;"\uTorrent\";"uTorrent.exe" : gosub [output]
- 'Finally run utorrent and show minimized
- run utdir$;"\uTorrent\";"uTorrent.exe", SHOWMINIMIZED
- 'Create output
- output$ = "- End ";date$();" - ";time$() : gosub [output]
- else
- 'Create output
- if yesno$ = "no" then output$ = "The file uTorrent.exe does not exist at this location ";utdir$;"\uTorrent\";"uTorrent.exe" : gosub [output]
- output$ = "- End ";date$();" - ";time$() : gosub [output]
- end if
- 'Exit
- end
- 'Subs/Functions
- [info]
- 'Show info
- print "-Help, using Leecher in uTorrent(desktop):"
- print "You need the exactly title of the window and uTorrent parameters."
- print ""
- print "(1)In uTorrent go to,"
- print " Options/preferences/UI Settings."
- print " Remove value true in (Close button closes uT to tray)"
- print ""
- print "(2)Options/preferences/UI Settings."
- print " Remove value true in (Show confirmation dialog on exit)"
- print ""
- print "(3)Options/preferences/Advanced/Run Program."
- print " In box (...when a torrent finishes) put app this way"
- print " C:\..\.\Leecher.exe" + chr$(34) + " " + chr$(34) + "uTorrent 3.3.2" + chr$(34) + " " + chr$(34) + "%D" + chr$(34) + " " + chr$(34) + "%N" + chr$(34)
- print ""
- print ""
- print ""
- print "-Help using Leecher in uTorrent with Webui(Web)"
- print "(1)If you want to perform these actions via webui only. "
- print " go to Options/preferences/Advanced/Run Program. In box"
- print " (...when a torrent finishes) put app this way"
- 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)
- print ""
- print "(2)Go to Options/preferences/Advanced/"
- print " search for webui.token_auth and change the value to true."
- print ""
- print "(3)Finally, open config.conf and enter the required data"
- print ""
- print ""
- print ""
- print "Leecher - automatic way to stop the seeding in uTorrent"
- print "Rui Branco - rmrbranco at gmail dot com"
- RETURN
- [webui]
- 'By Brent D. Thorn, 9/2005
- 'enough bytes to hold a single line of HTML
- CHUNK.SIZE = 512
- Open "wininet" For DLL As #inet
- 'It would be a good idea to test for an Internet
- 'connection before proceding. This demo assumes
- 'you have one already.
- ' Register a new user agent. Use proxy settings
- ' set up in Internet Options Control Panel.
- CallDLL #inet, "InternetOpenA", _
- "My User Agent" As Ptr, _
- 0 As Long, _ 'INTERNET_OPEN_TYPE_PRECONFIG
- _NULL As Long, _
- _NULL As Long, _
- 0 As ULong, _
- hInet As ULong
- If hInet = 0 Then [ErrExit]
- ' Open a request to a remote file
- CallDLL #inet, "InternetOpenUrlA", _
- hInet As ULong, _
- action$ As Ptr, _
- _NULL As Long, _
- 0 As Long, _
- 2147483648 As ULong, _ 'INTERNET_FLAG_RELOAD
- _NULL As Long, _
- hFile As ULong
- If hFile = 0 Then [ErrExit]
- ' Start reading in the file by chunks.
- Buffer$ = ""
- chunk$ = Space$(CHUNK.SIZE)+Chr$(0)
- Struct pdw, NumberOfBytesRead As ULong
- Do
- CallDLL #inet, "InternetReadFile", _
- hFile As ULong, _
- chunk$ As Ptr, _
- CHUNK.SIZE As ULong, _
- pdw As Struct, _
- ret As Long
- If pdw.NumberOfBytesRead.struct = 0 Then Exit Do
- Buffer$ = Buffer$ + Left$(chunk$, pdw.NumberOfBytesRead.struct)
- Loop Until 0
- 'Create output
- output$ = "Action, Stop " ; title$ : gosub [output]
- output$ = "Webui output " ; Buffer$ : gosub [output]
- [ErrExit]
- ' If you get an error, find GetLastError on MSDN. There
- ' you will find a link to a list of error codes.
- CallDLL #kernel32, "GetLastError", ret As ULong
- If ret and yesno$ = "yes" Then Print "Error Webui";ret
- ' Free the handles we created and exit.
- If hFile Then _
- CallDLL #inet, "InternetCloseHandle", _
- hFile As ULong, ret As Long
- If hInet Then _
- CallDLL #inet, "InternetCloseHandle", _
- hInet As ULong, ret As Long
- ' Strangely, the next line causes LB to hang for around 45
- ' seconds on my computer, a 2.2 GHz running XP on dial-up.
- Close #inet
- 'Create output
- output$ = "- End ";date$();" - ";time$() : gosub [output]
- 'Exit
- End
- [output]
- 'Create and show output info
- open "output.log" for append as #log
- print #log, output$
- close #log
- print output$
- RETURN
- [sendclose]
- 'Find utorrent window
- CallDLL #user32, "FindWindowA",_
- _NULL as ulong,_
- resulta$ as ptr,_
- ut as ulong
- 'Create output
- if ut = 0 then
- output$ = "Window looks closed ";ut : gosub [output]
- else
- output$ = "Find Window ";ut : gosub [output]
- end if
- 'Send Close command to utorrent
- Calldll #user32, "SendMessageA", _
- ut as ulong, _
- _WM_CLOSE as long, _
- result as long
- 'Create output
- if ut = 0 then
- output$ = "Window is closed ";ut : gosub [output]
- else
- output$ = "Send close to window ";ut : gosub [output]
- end if
- RETURN
- [loadconfig]
- 'Check if config exists
- dim info$(10, 10)
- if fileExists(DefaultDir$, "config.conf") then
- open "config.conf" for input as #lconf
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, yesno$
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, ip$
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, login$
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, password$
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, null$
- LINE INPUT #lconf, null$
- close #lconf
- else
- 'Create a default config
- open "config.conf" for output as #lconf
- print #lconf, "#Leecher CONFIG"
- print #lconf, " "
- print #lconf, "#Webui [yes/no]"
- print #lconf, "no"
- print #lconf, " "
- print #lconf, "#Webui [ip]:[port]"
- print #lconf, "localhost:8080"
- print #lconf, " "
- print #lconf, "#Webui [login]"
- print #lconf, "jonh"
- print #lconf, " "
- print #lconf, "#Webui [password]"
- print #lconf, "1213234sfd334"
- print #lconf, " "
- print #lconf, "#Webui action [stop]"
- print #lconf, "not yet implemented"
- close #lconf
- end if
- RETURN
- 'Retrieves the contents of the specified variable from the environment block of the calling process.
- Function Environ$(varName$)
- retBufr$ = space$(127) : nSize = len(retBufr$)
- CallDll #kernel32, "GetEnvironmentVariableA",_
- varName$ as ptr,_
- retBufr$ as ptr,_
- nSize as long,_
- ret as long
- Environ$ = trim$(retBufr$)
- End Function
- 'Function which can be used to test if a file exists on disk.
- function fileExists(path$, filename$)
- files path$, filename$, info$()
- fileExists = val(info$(0, 0))
- end function
- 'Function which can be used to test if a folder exists on disk.
- function folderExists(path$)
- folderExists = fileExists(path$, "nul")
- end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement