-
Notifications
You must be signed in to change notification settings - Fork 0
/
TorrentBot_140512.au3
276 lines (250 loc) · 8.24 KB
/
TorrentBot_140512.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#Include <file.au3>
#Include <Array.au3>
#include <Date.au3>
Global $PathDWND
Dim $arrayTorrents[1][5]
Global $Path=@ScriptDir & "\"
Dim $OnlyLog=False
Dim $CurrentIndex=0
;~ $PathDropBox="D:\Dropbox\DWND\"
;~ $PathDWND="C:\DWND\"
;~ $TimeUpdate=3000
If not FileExists($Path & "config.ini") Then
$file = FileOpen($Path & "config.ini", 1)
FileWriteLine($file, "[options]")
FileWriteLine($file, "PathDWND=")
FileWriteLine($file, "PathDropBox=")
FileWriteLine($file, "TimeUpdate=3000")
FileClose($file)
Exit
Else
$PathDropBox=IniRead($Path & "config.ini", "options", "PathDropBox", "NotFound")
$PathDWND=IniRead($Path & "config.ini", "options", "PathDWND","NotFound")
$TimeUpdate=IniRead($Path & "config.ini", "options", "TimeUpdate","NotFound")*1000
Select
Case $PathDropBox="NotFound"
_MsgBox("Íåîáõîäèìî óêàçàòü ïàðàìåòðû PathDropBox â " & $Path & "config.ini")
Exit
case $PathDWND="NotFound"
_MsgBox("Íåîáõîäèìî óêàçàòü ïàðàìåòðû PathDWND â " & $Path & "config.ini")
Exit
case $TimeUpdate="NotFound"
_MsgBox("Íåîáõîäèìî óêàçàòü ïàðàìåòðû â " & $Path & "config.ini")
Exit
EndSelect
EndIf
;~ _ArrayDisplay($ArrayFolders)
;Åñëè çàïóñê ïðîèñõîäèò èç êîìàíäíîé ñòðîêè îáðàáîòêà ïàðàìåòðîâ
For $id = 1 to $CmdLine[0]
if StringLower(StringLeft($CmdLine[$id],4))="dbx-" then
$PathDropBox= StringMid($CmdLine[$id],5)
EndIf
if StringLower(StringLeft($CmdLine[$id],5))="dwnd-" then
$PathDWND=StringMid($CmdLine[$id],6);
EndIf
if StringLower(StringLeft($CmdLine[$id],2))="t-" then
$TimeUpdate=StringMid($CmdLine[$id],3)*1000
EndIf
Next
;Ïðîâåðêà íå âõîäèò ëè ïàïêà DropBox â Ïàïêó êóäà ñêà÷èâàþòñÿ ôèëüìû. Åñëè âõîäèò áóäåò çàöèêëèâàíèå.
If StringInStr(StringLower($PathDropBox),StringLower($PathDWND))>0 Then
_MsgBox("Ïàïêà DropBox íå ìîæåò âõîäèòü â ïàïêó êóäà ñêà÷èâàþòñÿ Ôàéëû.")
Exit
EndIf
$TorrentName=""
$PozOnly=StringInStr(StringLower($CmdLineRaw),"onlylog")
if $PozOnly>0 Then
$OnlyLog=True
$TorrentName=StringLeft($CmdLineRaw,$PozOnly-2)
EndIf
if $OnlyLog Then
WriteLog("Çàêà÷êà çàâåðøåíà - " & $TorrentName,"logTorrentBot.txt",33)
EndIf
While 1 and $OnlyLog=False
Sleep ($TimeUpdate)
SynhroniseFolders($PathDWND,$PathDropBox)
GetFiles($PathDropBox,$arrayTorrents,1,$CurrentIndex)
For $id = 0 to $CurrentIndex-1
if $arrayTorrents[$id][1] <> "" then
;~ $StrokaZapuska="C:\Program Files\uTorrent\uTorrent.exe /DIRECTORY " & chr(34) & $arrayTorrents[$id][1] & chr(34) & " " & chr(34) & $arrayTorrents[$id][2] & chr(34)
$StrokaZapuska="C:\Program Files\uTorrent\uTorrent.exe " & chr(34) & $arrayTorrents[$id][2] & chr(34)
if Run($StrokaZapuska)=0 Then
;$arrayTorrents[$id][1] ïóòü äî
WriteLog("Íå óäàëîñü ïîñòàâèòü òîððåíò íà çàêà÷êó - " & $arrayTorrents[$id][2],"logTorrentBot.txt",33)
Else
$NameTorrent=SetNameTorrent($arrayTorrents[$id][0],$arrayTorrents[$id][3])
;~ Exit
$arrayTorrents[$id][4]=True
WriteLog("Òîððåíò äîáàâëåí " & $NameTorrent,"logTorrentBot.txt",33)
if FileDelete($arrayTorrents[$id][0]) = 0 then
WriteLog("íå óäàëîñü óäàëèòü " & $arrayTorrents[$id][0],"logTorrentBot.txt",33)
EndIf
Sleep (3000)
EndIf
EndIf
Next
$flDeleteItem=False
For $id = 0 to $CurrentIndex-1
if $flDeleteItem Then
$id=0
EndIf
;~ _MsgBox($id & " = "& $CurrentIndex)
if $CurrentIndex <> 0 then
If $arrayTorrents[$id][4] Then
if $CurrentIndex = 1 then
$arrayTorrents[0][0]=""
$arrayTorrents[0][1]=""
$arrayTorrents[0][2]=""
$arrayTorrents[0][3]=""
$arrayTorrents[0][4]=False
$CurrentIndex=0
Else
_ArrayDelete($arrayTorrents, $id)
$CurrentIndex=$CurrentIndex-1
$flDeleteItem=True
;~ _MsgBox($id & " = "& $CurrentIndex)
EndIf
Else
$flDeleteItem=False
EndIf
Else
$flDeleteItem=False
EndIf
Next
;~ Exit
WEnd
Func SynhroniseFolders($FolderISX,$FolderSYNC)
Dim $CurrentIndexISX=0
Dim $CurrentIndexSync=0
Dim $FolderISX[1],$FolderSYNC[1]
GetFiles($PathDWND,$FolderISX,2,$CurrentIndexISX)
GetFiles($PathDropBox,$FolderSYNC,2,$CurrentIndexSync)
$SizeArray=$CurrentIndexISX ;$CurrentIndexSync
Dim $ArrayFolders[$SizeArray][4]
$id_AF=0
For $id_C = 0 to $CurrentIndexISX-1
$ArrayFolders[$id_AF][0]=StringReplace($FolderISX[$id_C],$PathDWND,"")
$ArrayFolders[$id_AF][1]=""
For $id_DBX = 0 to $CurrentIndexSync-1
if StringReplace($FolderISX[$id_C],$PathDWND,"")=StringReplace($FolderSYNC[$id_DBX],$PathDropBox,"") Then
$ArrayFolders[$id_AF][1]=StringReplace($FolderSYNC[$id_DBX],$PathDropBox,"")
$ArrayFolders[$id_AF][2]=False
$ArrayFolders[$id_AF][3]=False
$FolderSYNC[$id_DBX]=""
EndIf
Next
if $ArrayFolders[$id_AF][1]="" then
$ArrayFolders[$id_AF][2]=True
$ArrayFolders[$id_AF][3]=False
EndIf
$id_AF=$id_AF+1
Next
For $id_DBX = 0 to $CurrentIndexSync-1
if $FolderSYNC[$id_DBX]<>"" Then
$SizeArray=$SizeArray+1
ReDim $ArrayFolders[$SizeArray][4]
$ArrayFolders[$id_AF][0]=""
$ArrayFolders[$id_AF][1]=StringReplace($FolderSYNC[$id_DBX],$PathDropBox,"")
$ArrayFolders[$id_AF][2]=False
$ArrayFolders[$id_AF][3]=True
$id_AF=$id_AF+1
EndIf
Next
;~ _ArrayDisplay($ArrayFolders)
;~ Exit
For $id = 0 to $SizeArray-1
if $ArrayFolders[$id][2] then
DirCreate($PathDropBox & $ArrayFolders[$id][0])
;~ WriteLog("Ñîçäàíà ïàïêà " & $PathDropBox & $ArrayFolders[$id][0],"logTorrentBot.txt",33)
EndIf
Next
For $id = 0 to $SizeArray-1
if $ArrayFolders[$id][3] then
DirRemove($PathDropBox & $ArrayFolders[$id][1],1)
;~ WriteLog("Óäàëåíà ïàïêà " & $PathDropBox & $ArrayFolders[$id][1],"logTorrentBot.txt",33)
EndIf
Next
EndFunc
Func SetNameTorrent($FileTorrent,$NameTorrent)
$PozTorrent=StringInStr($NameTorrent,".torrent")
$NameTorrent=StringLeft($NameTorrent,$PozTorrent-1)
$file = FileOpen($FileTorrent,128)
$Multi=False
While 1
$line = FileReadLine($file)
;~ MsgBox(-1,"",$line)
$PozName=StringInStr($line,"name")
$PozPath=StringInStr($line,"path")
$line=StringMid($line,$PozName)
if $PozPath>0 Then
$Multi=True
EndIf
if $PozName>0 then
$PozDV=StringInStr($line,":")
$line=StringMid($line,$PozDV+1)
$PozDV=StringInStr($line,":")
$Name=StringLeft($line,$PozDV-3)
ExitLoop
EndIf
WEnd
FileClose($file)
$PozT=StringInStr($Name,".",0,-1)
$rashirenie=StringMid($Name,$PozT)
$DostupnueRashieniya=".3gp .avi .dat .flv .ifo .m4v .mkv .mov .mp4 .rm .vob .wmv"
if StringLen($rashirenie)>4 or $Multi then
$rashirenie=""
EndIf
$Name=$Name & " - Äîáàâèòü íîâûé òîððåíò"
Sleep(1000)
ControlSetText($Name, "", "ComboBox1", $NameTorrent & $rashirenie)
Sleep(1000)
ControlClick ( $Name, "", "Button13")
Sleep(1000)
Return $NameTorrent & $rashirenie
EndFunc
Func WriteLog($Text,$NameLog,$Mode)
$Time=_Date_Time_GetLocalTime()
$Time=_Date_Time_SystemTimeToDateTimeStr($Time)
$logfile = FileOpen($PathDropBox & $NameLog, $Mode)
FileWriteLine($logfile,$Time & "-" & $Text)
FileClose($logfile)
EndFunc
Func GetFiles($PathFolder,ByRef $array,$Type,Byref $CurrentIndex)
$FileList=_FileListToArray($PathFolder)
If @Error=1 or @Error=4 Then
Else
For $id = 1 to $FileList[0]
$FileAtr=FileGetAttrib ($PathFolder & $FileList[$id])
if StringInStr($FileAtr,"D") then
if $Type = 2 then
ReDim $array[$CurrentIndex+1]
$array[$CurrentIndex]=$PathFolder & $FileList[$id]
;~ StringReplace($FolderISX[$id_C],$PathDWND,"")
$CurrentIndex=$CurrentIndex+1
EndIf
GetFiles($PathFolder & $FileList[$id] & "\",$array,$Type,$CurrentIndex)
Else
;~ _MsgBox("Test")
if StringInStr($FileList[$id],".torrent")>0 and $Type=1 then
ReDim $array[$CurrentIndex+1][5]
$array[$CurrentIndex][0]=$PathFolder & $FileList[$id]
$PathTorrent=StringReplace($PathFolder,$PathDropBox,"")
$array[$CurrentIndex][1]=$PathDWND & $PathTorrent
$array[$CurrentIndex][2]=$PathDWND & "torrents\" & $FileList[$id]
$array[$CurrentIndex][3]=$PathDWND & $PathTorrent & $FileList[$id]
$array[$CurrentIndex][4]=false
if FileCopy($array[$CurrentIndex][0], $array[$CurrentIndex][2], 9) =0 then
WriteLog("Íå óäàëîñü ñêîïèðîâàòü òîððåíò " & $array[$CurrentIndex][2],"logTorrentBot.txt",33)
Else
;~ WriteLog("Ñêîïèðîâàí òîððåíò " & $arrayTorrents[$CurrentIndex][2],"logTorrentBot.txt",1)
EndIf
$CurrentIndex=$CurrentIndex+1
EndIf
EndIf
Next
EndIf
;~ Return $FileList
EndFunc
Func _MsgBox($Text)
MsgBox(-1,"",$Text)
EndFunc