forked from TrackerControl/platformcontrol-ios-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instrumentor.ahk
122 lines (108 loc) · 2.81 KB
/
instrumentor.ahk
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
appCollection := "apps.txt" ; a list of app URLs
applePassword := "**********************"
waitTime := 5000 ; wait time between download attempts in seconds. Should leave enough time for iTunes to download an average app.
DownloadsDir := "C:\Users\Konrad\Music\iTunes\iTunes Media\Downloads" ; adapt to your environment
Restart := 100 ; how often iTunes is closed and restarted to overcome issues
iTunes := StartTunes()
; Save progress in file
Loop, read, instrumentorStatus.txt
{
StoppedAt := A_LoopReadLine
}
If LastLine == "" ; if instrumentorStatus.txt does not exist
StoppedAt := 0
i := 0
Loop, read, %appCollection%
{
i := i + 1
If (i <= StoppedAt)
Continue
; Reset iTunes regularly, just in case
If (Mod(A_Index, %Restart%) = 0)
{
Sleep, %waitTime%
KillTunes()
Sleep, %waitTime%
Loop, %DownloadsDir%\*.*, 1, 0
{
If InStr(A_LoopFileAttrib, "D")
FileRemoveDir, %A_LoopFileLongPath%, 1
Else
FileSetAttrib, -RASH, %A_LoopFileLongPath%
FileDelete, %A_LoopFileLongPath%
}
iTunes := StartTunes()
}
url := A_LoopReadLine
url := StrReplace(url, "https://", "itmss://") ; use correct protocol
; Open App in store
try
{
iTunes.OpenURL(url)
}
catch e
{
iTunes := StartTunes()
}
; Download App
Sleep, %waitTime%
WinActivate, iTunes
If GetLoginWindow() <> ""
Login()
CloseAnyPopups()
MouseClick, left, 130, 410
; Save progress
FileAppend, `n%url%`n%i%, instrumentorStatus.txt
}
CloseAnyPopups()
{
If WinExist("ahk_class iTunesCustomModalDialog")
{
WinActivate
WinGetText, windowText
If (InStr(windowText, "&Buy") || InStr(windowText, "Item Not Available") || InStr(windowText, "not installed correctly")) {
Send, {Escape}
}
Else If InStr(windowText, "This update is free.") {
Send, {Left}{Enter}
}
Else {
Send, {Enter}
}
Sleep, 1000
CloseAnyPopups()
}
}
GetLoginWindow()
{
WinGet, Windows, List , iTunes
If (Windows > 1) {
Loop %Windows% {
active_id := Windows%A_Index%
WinGetText, windowText, ahk_id %active_id%
if InStr(windowText, "iforgot.apple.com")
return %active_id%
}
}
return ""
}
Login()
{
global applePassword
Sleep, 1000
Send, %applePassword%{Enter}
Sleep, 10000
}
StartTunes()
{
Run, C:\Program Files\iTunes\iTunes.exe
Sleep, 1000
CloseAnyPopups()
iTunes := ComObjCreate("iTunes.Application") ; starts iTunes if not active
WinWait, iTunes
return iTunes
}
KillTunes()
{
run,%comspec% /k taskkill /F /IM iTunes.exe && exit
}