Guest User

TorrentsAutodownload

a guest
May 16th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 21.01 KB | None | 0 0
  1. ;*************************************************************************************************************************
  2. ;   $a<символ> - (Array) Массив данных -  последующий символ взятый из списка ниже, определяет тип данных в массиве
  3. ;   $b - (Binary data) Двоичные данные
  4. ;   $h - (File or window handle) Дескриптор файла, окна, и т.д.
  5. ;   $i - (Integer) Целое число
  6. ;   $f - (Boolean) Логический тип, может принимать значения True или False
  7. ;   $n - (Floating point number) Число с плавающей точкой
  8. ;   $s - (String) Строка
  9. ;   $v - (Variant) Вариант, неопределенный тип данных, базовый тип для AutoIt
  10. ;   $t - (Struct) Структура в стиле C/C++, для использования в DllCall, в сообщениях WM_*, при обработке данных и т.п.
  11. ;   $p - (Pointer) Указатель на структуру или на её элемент
  12. ;*************************************************************************************************************************
  13.  
  14. #include <Array.au3>
  15.  
  16. Dim $aList, $HWnd, $sSearchPath, $sTorrentContentName, $sTorrentPath
  17.  
  18. $sScriptName = StringReplace(@ScriptName, '.exe', '')
  19.  
  20. $sSearchPath = InputBox('', 'Введите путь для поиска ' & $sScriptName, 'i:\MUSIC;d:\INSTALL;i:\VIDEO;f:\Music')
  21.  
  22. If NOT $sSearchPath Then Exit
  23.  
  24. While True
  25.     _ConfirmDownload()
  26.  
  27.     $aList = WinList()
  28.  
  29.     For $i = 1 to $aList[0][0]
  30.         ; Только для окон имеющих заголовок и не скрытых
  31.         If $aList[$i][0] <> "" Then
  32.         If BitAnd(WinGetState($aList[$i][1]), 2) Then
  33.             If StringRight($aList[$i][0], 26) = 'Добавление нового торрента' Or StringRight($aList[$i][0], 22) ='Добавить новый торрент' Then
  34.                 $sTorrentContentName = ControlGetText($aList[$i][1], '', '[CLASS:ComboBox; INSTANCE:1]')
  35.                 $sTorrentContentName = StringRight($sTorrentContentName, StringLen($sTorrentContentName) - StringInStr($sTorrentContentName, Chr(92), 0, -1))
  36.                 $sTorrentPath = _FileListToArrayXT($sSearchPath, $sTorrentContentName, 0, 2, True, '', 1)
  37.                 If IsArray($sTorrentPath) Then
  38.                     WinActivate($aList[$i][1])
  39.                     ControlSetText($aList[$i][1], '', '[CLASS:ComboBox; INSTANCE:1]', $sTorrentPath[1])
  40.                     ControlClick($aList[$i][1], '', '[CLASS:Button; INSTANCE:3]', 'left', 1, 7, 7)
  41.                     $sTorrentTrackerName = ControlGetText($aList[$i][1], '', '[CLASS:Static; INSTANCE:5]')
  42.                     $sTorrentTrackerName = StringRight($sTorrentTrackerName, StringLen($sTorrentTrackerName) - StringInStr($sTorrentTrackerName, Chr(47), 1, 2))
  43.                     $sTorrentTrackerName = StringLeft($sTorrentTrackerName, StringInStr($sTorrentTrackerName, Chr(47))-1)
  44.                     ControlSetText($aList[$i][1], '', '[CLASS:ComboBox; INSTANCE:2]', $sTorrentTrackerName)
  45.                     ControlClick($aList[$i][1], '', '[CLASS:Button; INSTANCE:10]')
  46.                     TrayTip($sScriptName, 'Added torrent: ' & $sTorrentContentName, 5)
  47.                 EndIf
  48.             EndIf
  49.         EndIf
  50.         EndIf
  51.     Next
  52. TrayTip($sScriptName, 'Going to sleep for 2 minutes...', 5)
  53. Sleep(120000)
  54. WEnd   
  55. ;*************************************************************************************************************************
  56. Func _ConfirmDownload()
  57. If WinExists('[Title:µTorrent; Class:#32770]') Then
  58.     WinActivate(WinGetHandle('[Title:µTorrent; Class:#32770]'))
  59.     ControlClick(WinGetHandle('[Title:µTorrent; Class:#32770]'), '', '[CLASS:Button; INSTANCE:1]')
  60. EndIf
  61. EndFunc
  62. ;*************************************************************************************************************************
  63.  
  64. ;*************************************************************************************************************************
  65. ; #FUNCTION# ===========================================================================================
  66. ; Name:             _FileListToArrayXT
  67. ; Description:      Lists files and\or folders in specified path(s) (Similar to using Dir with the /B Switch)
  68. ;                   additional features: multi-path, multi-filter, multi-exclude-filter, path format options, recursive search
  69. ;                   Corrected on 2010/08/19: Added FileClose()
  70. ; Syntax:           _FileListToArrayXT([$sPath = @ScriptDir, [$sFilter = "*", [$iRetItemType, [$bRecursive = False, [$sExclude = "", [$iRetFormat = 1]]]]]])
  71. ; Parameter(s):     $sPath = optional: Search path(s), semicolon delimited (default: @ScriptDir)
  72. ;                            (Example: "C:\Tmp;D:\Temp")
  73. ;                   $sFilter = optional: Search filter(s), semicolon delimited . Wildcards allowed. (default: "*")
  74. ;                              (Example: "*.exe;*.txt")
  75. ;                   $iRetItemType = Include in search: 0 = Files and Folder, 1 = Files Only, 2 = Folders Only
  76. ;                   $iRetPathType = Returned element format: 0 = file/folder name only, 1 = relative path, 2 = full path
  77. ;                   $bRecursive = optional: True: recursive search including all subdirectories
  78. ;                                           False (default): search only in specified folder
  79. ;                   $sExclude = optional: Exclude filter(s), semicolon delimited. Wildcards allowed.
  80. ;                               (Example: "Unins*" will remove all files/folders that begin with "Unins")
  81. ;                   $iRetFormat =  optional: return format
  82. ;                                  0 = one-dimensional array, 0-based
  83. ;                                  1 = one-dimensional array, 1-based (default)
  84. ;                                  2 = String ( "|" delimited)
  85. ; Return Value(s):  on success: 1-based or 0-based array or string (dependent on $iRetFormat)
  86. ;                   If no path is found, @error and @extended are set to 1, returns empty string
  87. ;                   If no filter is found, @error and @extended are set to 2, returns empty string
  88. ;                   If $iRetFormat is invalid, @error and @extended are set to 3, returns empty string
  89. ;                   If no data is found, @error and @extended are set to 4, returns empty string
  90. ; Author(s):        Half the AutoIt Community
  91. ; ====================================================================================================
  92. ;*************************************************************************************************************************
  93. Func _FileListToArrayXT($sPath = @ScriptDir, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 0, $bRecursive = False, $sExclude = "", $iRetFormat = 1)
  94.   Local $hSearchFile, $sFile, $sFileList, $sWorkPath, $sRetPath, $iRootPathLen, $iPCount, $iFCount, $fDirFlag
  95.  
  96.   ;[check and prepare parameters]
  97.   ;---------------
  98.   If $sPath = -1 Or $sPath = Default Then $sPath = @ScriptDir
  99.   ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons
  100.   $sPath = StringRegExpReplace(StringRegExpReplace($sPath, "(\s*;\s*)+", ";"), "\A;|;\z", "")
  101.   ;check that at least one path is set
  102.   If $sPath = "" Then Return SetError(1, 1, "")
  103.   ;-----
  104.   If $sFilter = -1 Or $sFilter = Default Then $sFilter = "*"
  105.   ;prepare filter
  106.   ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons
  107.   $sFilter = StringRegExpReplace(StringRegExpReplace($sFilter, "(\s*;\s*)+", ";"), "\A;|;\z", "")
  108.   ;check for invalid chars or that at least one filter is set
  109.   If StringRegExp($sFilter, "[\\/><:\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
  110.   If $bRecursive Then
  111.     ;Convert $sFilter for Regular Expression
  112.     $sFilter = StringRegExpReplace($sFilter, '([\Q\.+[^]$(){}=!\E])', '\\$1')
  113.     $sFilter = StringReplace($sFilter, "?", ".")
  114.     $sFilter = StringReplace($sFilter, "*", ".*?")
  115.     $sFilter = "(?i)\A(" & StringReplace($sFilter, ";", "$|") & "$)" ;case-insensitive, convert ';' to '|', match from first char, terminate strings
  116.     ;$sFilter = "(?i)\A" & StringReplace($sFilter, ";", "|") & "\z"
  117.   EndIf
  118.   ;-----
  119.   If $iRetItemType <> "1" And $iRetItemType <> "2" Then $iRetItemType = "0"
  120.   ;-----
  121.   If $iRetPathType <> "1" And $iRetPathType <> "2" Then $iRetPathType = "0"
  122.   ;-----
  123.   $bRecursive = ($bRecursive = "1")
  124.   ;-----
  125.   If $sExclude = -1 Or $sExclude = Default Then $sExclude = ""
  126.   If $sExclude Then
  127.     ;prepare $sExclude
  128.     ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons
  129.     $sExclude = StringRegExpReplace(StringRegExpReplace($sExclude, "(\s*;\s*)+", ";"), "\A;|;\z", "")
  130.     ;Convert $sExclude for Regular Expression
  131.     $sExclude = StringRegExpReplace($sExclude, '([\Q\.+[^]$(){}=!\E])', '\\$1')
  132.     $sExclude = StringReplace($sExclude, "?", ".")
  133.     $sExclude = StringReplace($sExclude, "*", ".*?")
  134.     $sExclude = "(?i)\A(" & StringReplace($sExclude, ";", "$|") & "$)" ;case-insensitive, convert ';' to '|', match from first char, terminate strings
  135.     ;$sExclude = "(?i)\A" & StringReplace($sExclude, ";", "|") & "\z"
  136.   EndIf
  137.   ;-----
  138.   ;If $iRetFormat <> "0" And $iRetFormat <> "2" Then $iRetFormat = "1"
  139.   If Not ($iRetItemType = 0 Or $iRetItemType = 1 Or $iRetItemType = 2) Then Return SetError(3, 3, "")
  140.   ;---------------
  141.   ;[/check and prepare parameters]
  142.  
  143.   ;---------------
  144.  
  145.   Local $aPath = StringSplit($sPath, ';', 1) ;paths array
  146.   Local $aFilter = StringSplit($sFilter, ';', 1) ;filters array
  147.  
  148.   ;---------------
  149.  
  150.   If $bRecursive Then ;different handling for recursion (strategy: unfiltered search for all items and filter unwanted)
  151.  
  152.     If $sExclude Then ;different handling dependent on $sExclude parameter is set or not
  153.  
  154.       For $iPCount = 1 To $aPath[0] ;Path loop
  155.         $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash
  156.         If Not FileExists($sPath) Then ContinueLoop
  157.         $iRootPathLen = StringLen($sPath) - 1
  158.  
  159.         Local $aPathStack[1024] = [1, $sPath]
  160.  
  161.         While $aPathStack[0] > 0
  162.           $sWorkPath = $aPathStack[$aPathStack[0]]
  163.           $aPathStack[0] -= 1
  164.           ;-----
  165.           $hSearchFile = FileFindFirstFile($sWorkPath & '*')
  166.           If @error Then
  167.             FileClose($hSearchFile)
  168.             ContinueLoop
  169.           EndIf
  170.           ;-----
  171.           Switch $iRetPathType
  172.             Case 2 ;full path
  173.               $sRetPath = $sWorkPath
  174.             Case 1 ;relative path
  175.               $sRetPath = StringTrimLeft($sWorkPath, $iRootPathLen + 1)
  176.           EndSwitch
  177.           ;-----
  178.           Switch $iRetItemType
  179.             Case 1
  180.               While True ;Files only
  181.                 $sFile = FileFindNextFile($hSearchFile)
  182.                 If @error Then
  183.                   FileClose($hSearchFile)
  184.                   ExitLoop
  185.                 EndIf
  186.                 $fDirFlag = @extended
  187.                 If $fDirFlag Then
  188.                   $aPathStack[0] += 1
  189.                   If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2]
  190.                   $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\"
  191.                   ContinueLoop
  192.                 EndIf
  193.                 If StringRegExp($sFile, $sExclude) Then ContinueLoop
  194.                 If StringRegExp($sFile, $sFilter) Then
  195.                   $sFileList &= $sRetPath & $sFile & "|"
  196.                 EndIf
  197.               WEnd
  198.             Case 2
  199.               While True ;Folders only
  200.                 $sFile = FileFindNextFile($hSearchFile)
  201.                 If @error Then
  202.                   FileClose($hSearchFile)
  203.                   ExitLoop
  204.                 EndIf
  205.                 $fDirFlag = @extended
  206.                 If StringRegExp($sFile, $sExclude) Then ContinueLoop
  207.                 If $fDirFlag Then
  208.                   $aPathStack[0] += 1
  209.                   If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2]
  210.                   $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\"
  211.                   If StringRegExp($sFile, $sFilter) Then
  212.                     $sFileList &= $sRetPath & $sFile & "|"
  213.                   EndIf
  214.                 EndIf
  215.               WEnd
  216.             Case Else
  217.               While True ;Files and Folders
  218.                 $sFile = FileFindNextFile($hSearchFile)
  219.                 If @error Then
  220.                   FileClose($hSearchFile)
  221.                   ExitLoop
  222.                 EndIf
  223.                 $fDirFlag = @extended
  224.                 If StringRegExp($sFile, $sExclude) Then ContinueLoop
  225.                 If $fDirFlag Then
  226.                   $aPathStack[0] += 1
  227.                   If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2]
  228.                   $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\"
  229.                 EndIf
  230.                 If StringRegExp($sFile, $sFilter) Then
  231.                   $sFileList &= $sRetPath & $sFile & "|"
  232.                 EndIf
  233.               WEnd
  234.           EndSwitch
  235.           ;-----
  236.         WEnd
  237.  
  238.         FileClose($hSearchFile)
  239.  
  240.       Next ;$iPCount - next path
  241.  
  242.     Else ;If Not $sExclude
  243.  
  244.       For $iPCount = 1 To $aPath[0] ;Path loop
  245.         $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash
  246.         If Not FileExists($sPath) Then ContinueLoop
  247.         $iRootPathLen = StringLen($sPath) - 1
  248.  
  249.         Local $aPathStack[1024] = [1, $sPath]
  250.  
  251.         While $aPathStack[0] > 0
  252.           $sWorkPath = $aPathStack[$aPathStack[0]]
  253.           $aPathStack[0] -= 1
  254.           ;-----
  255.           $hSearchFile = FileFindFirstFile($sWorkPath & '*')
  256.           If @error Then
  257.             FileClose($hSearchFile)
  258.             ContinueLoop
  259.           EndIf
  260.           ;-----
  261.           Switch $iRetPathType
  262.             Case 2 ;full path
  263.               $sRetPath = $sWorkPath
  264.             Case 1 ;relative path
  265.               $sRetPath = StringTrimLeft($sWorkPath, $iRootPathLen + 1)
  266.           EndSwitch
  267.           ;-----
  268.           Switch $iRetItemType
  269.             Case 1
  270.               While True ;Files only
  271.                 $sFile = FileFindNextFile($hSearchFile)
  272.                 If @error Then
  273.                   FileClose($hSearchFile)
  274.                   ExitLoop
  275.                 EndIf
  276.                 If @extended Then
  277.                   $aPathStack[0] += 1
  278.                   If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2]
  279.                   $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\"
  280.                   ContinueLoop
  281.                 EndIf
  282.                 If StringRegExp($sFile, $sFilter) Then
  283.                   $sFileList &= $sRetPath & $sFile & "|"
  284.                 EndIf
  285.               WEnd
  286.             Case 2
  287.               While True ;Folders only
  288.                 $sFile = FileFindNextFile($hSearchFile)
  289.                 If @error Then
  290.                   FileClose($hSearchFile)
  291.                   ExitLoop
  292.                 EndIf
  293.                 If @extended Then
  294.                   $aPathStack[0] += 1
  295.                   If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2]
  296.                   $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\"
  297.                   If StringRegExp($sFile, $sFilter) Then
  298.                     $sFileList &= $sRetPath & $sFile & "|"
  299.                   EndIf
  300.                 EndIf
  301.               WEnd
  302.             Case Else
  303.               While True ;Files and Folders
  304.                 $sFile = FileFindNextFile($hSearchFile)
  305.                 If @error Then
  306.                   FileClose($hSearchFile)
  307.                   ExitLoop
  308.                 EndIf
  309.                 If @extended Then
  310.                   $aPathStack[0] += 1
  311.                   If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2]
  312.                   $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\"
  313.                 EndIf
  314.                 If StringRegExp($sFile, $sFilter) Then
  315.                   $sFileList &= $sRetPath & $sFile & "|"
  316.                 EndIf
  317.               WEnd
  318.           EndSwitch
  319.           ;-----
  320.         WEnd
  321.  
  322.         FileClose($hSearchFile)
  323.  
  324.       Next ;$iPCount - next path
  325.  
  326.     EndIf ;If $sExclude
  327.  
  328.   Else ;If Not $bRecursive (strategy: filtered search for items)
  329.  
  330.     If $sExclude Then ;different handling dependent on $sExclude parameter is set or not
  331.  
  332.       For $iPCount = 1 To $aPath[0] ;Path loop
  333.  
  334.         $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash
  335.         If Not FileExists($sPath) Then ContinueLoop
  336.         ;-----
  337.         Switch $iRetPathType
  338.           Case 2 ;full path
  339.             $sRetPath = $sPath
  340.           Case 1 ;relative path
  341.             $sRetPath = ""
  342.         EndSwitch
  343.  
  344.         For $iFCount = 1 To $aFilter[0] ;filter loop
  345.           ;-----
  346.           $hSearchFile = FileFindFirstFile($sPath & $aFilter[$iFCount])
  347.           If @error Then
  348.             FileClose($hSearchFile)
  349.             ContinueLoop
  350.           EndIf
  351.           ;-----
  352.           Switch $iRetItemType
  353.             Case 1 ;files Only
  354.               While True
  355.                 $sFile = FileFindNextFile($hSearchFile)
  356.                 If @error Then
  357.                   FileClose($hSearchFile)
  358.                   ExitLoop
  359.                 EndIf
  360.                 If @extended Then ContinueLoop ;bypass folder
  361.                 ;check for exclude files
  362.                 If StringRegExp($sFile, $sExclude) Then ContinueLoop
  363.                 $sFileList &= $sRetPath & $sFile & "|"
  364.               WEnd
  365.             Case 2 ;folders Only
  366.               While True
  367.                 $sFile = FileFindNextFile($hSearchFile)
  368.                 If @error Then
  369.                   FileClose($hSearchFile)
  370.                   ExitLoop
  371.                 EndIf
  372.                 If @extended Then ;bypass file
  373.                   ;check for exclude folder
  374.                   If StringRegExp($sFile, $sExclude) Then ContinueLoop
  375.                   $sFileList &= $sRetPath & $sFile & "|"
  376.                 EndIf
  377.               WEnd
  378.             Case Else ;files and folders
  379.               While True
  380.                 $sFile = FileFindNextFile($hSearchFile)
  381.                 If @error Then
  382.                   FileClose($hSearchFile)
  383.                   ExitLoop
  384.                 EndIf
  385.                 ;check for exclude files/folder
  386.                 If StringRegExp($sFile, $sExclude) Then ContinueLoop
  387.                 $sFileList &= $sRetPath & $sFile & "|"
  388.               WEnd
  389.           EndSwitch
  390.           FileClose($hSearchFile)
  391.         Next ;$iFCount - next filter
  392.  
  393.       Next ;$iPCount - next path
  394.  
  395.     Else ;If Not $sExclude
  396.  
  397.       For $iPCount = 1 To $aPath[0] ;Path loop
  398.  
  399.         $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash
  400.         If Not FileExists($sPath) Then ContinueLoop
  401.         ;-----
  402.         Switch $iRetPathType
  403.           Case 2 ;full path
  404.             $sRetPath = $sPath
  405.           Case 1 ;relative path
  406.             $sRetPath = ""
  407.         EndSwitch
  408.  
  409.         For $iFCount = 1 To $aFilter[0] ;filter loop
  410.           ;-----
  411.           $hSearchFile = FileFindFirstFile($sPath & $aFilter[$iFCount])
  412.           If @error Then
  413.             FileClose($hSearchFile)
  414.             ContinueLoop
  415.           EndIf
  416.           ;-----
  417.           Switch $iRetItemType
  418.             Case 1 ;files Only
  419.               While True
  420.                 $sFile = FileFindNextFile($hSearchFile)
  421.                 If @error Then
  422.                   FileClose($hSearchFile)
  423.                   ExitLoop
  424.                 EndIf
  425.                 If @extended Then ContinueLoop ;bypass folder
  426.                 $sFileList &= $sRetPath & $sFile & "|"
  427.               WEnd
  428.             Case 2 ;folders Only
  429.               While True
  430.                 $sFile = FileFindNextFile($hSearchFile)
  431.                 If @error Then
  432.                   FileClose($hSearchFile)
  433.                   ExitLoop
  434.                 EndIf
  435.                 If @extended Then ;bypass file
  436.                   $sFileList &= $sRetPath & $sFile & "|"
  437.                 EndIf
  438.               WEnd
  439.             Case Else ;files and folders
  440.               While True
  441.                 $sFile = FileFindNextFile($hSearchFile)
  442.                 If @error Then
  443.                   FileClose($hSearchFile)
  444.                   ExitLoop
  445.                 EndIf
  446.                 $sFileList &= $sRetPath & $sFile & "|"
  447.               WEnd
  448.           EndSwitch
  449.           FileClose($hSearchFile)
  450.         Next ;$iFCount - next filter
  451.  
  452.       Next ;$iPCount - next path
  453.  
  454.     EndIf ;If $sExclude
  455.  
  456.   EndIf ;If $bRecursive
  457.  
  458.   ;---------------
  459.  
  460.   ;set according return value
  461.   If $sFileList Then
  462.     Switch $iRetFormat
  463.       Case 2 ;return a delimited string
  464.         Return StringTrimRight($sFileList, 1)
  465.       Case 0 ;return a 0-based array
  466.         Return StringSplit(StringTrimRight($sFileList, 1), "|", 2)
  467.       Case Else ;return a 1-based array
  468.         Return StringSplit(StringTrimRight($sFileList, 1), "|", 1)
  469.     EndSwitch
  470.   Else
  471.     Return SetError(4, 4, "")
  472.   EndIf
  473.  
  474. EndFunc   ;==>_FileListToArrayXT
  475. ;*************************************************************************************************************************
Add Comment
Please, Sign In to add comment