-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathECRPCarMusicSelector.ahk
112 lines (93 loc) · 2.31 KB
/
ECRPCarMusicSelector.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
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SetKeyDelay, 1
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
global URL
global url
global Linenumber
global fil
global query
Numpad1::
SongAdd()
return
Numpad2::
SongSelect()
return
Numpad3::
SongNext()
return
SongSelect(){
InputBox, searchstring, Search
Loop, %A_ScriptDir%\*.txt, 1
{
Loop, Read, %A_ScriptDir%\%A_LoopFileName% , 1
{
i := A_Index
IfInString, A_LoopReadLine, %searchstring%
{
Linenumber := A_Index
fil = %A_loopFIleName%
Loop, 2
{
FileReadLine, Line, %fil%, % i
Result .= Line "`n"
i++
}
Break
}
}
}
URL := Linenumber +1
FileReadLine, OutputURL, %fil%, URL
send, t/CarURL %OutputURL%{enter}
}
SongNext(){
Linenumber := URL +3
URL := Linenumber
FileReadLine, OutputURL2, %fil%, URL
send, t/CarURL %OutputURL2%{enter}
}
SongAdd(){
SoundBeep, 440, 100
SoundBeep, 440, 100
SearchYT =
InputBox, SearchYT, Add Song to Library
query := SearchYT
url := first_youtube_result( query )
SearchYT := url
AddSongOptions()
}
first_youtube_result( query ){
StringReplace, query, query, %A_Space%, +, All
url := "https://www.youtube.com/results?search_query=" query
r := ComObjCreate("WinHttp.WinHttpRequest.5.1")
r.Open("GET", url, true)
r.Send()
r.WaitForResponse()
If RegExMatch( r.ResponseText, "/watch\?v=.{11}", match )
url := "https://www.youtube.com" match
return url
}
AddSongOptions(){
MsgBox, 3, ,Would you like to use this name?`n`nSong name = %query%`nURL = %url%
ifMsgBox, Yes
FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt; *.doc)
FileAppend,`n%query%`n%url%`n,%SelectedFile%
ifMsgBox, No
ChangeSongNameMenu()
ifMsgBox, Cancel
return
}
ChangeSongNameMenu(){
MsgBox, 4, ,Would you like to change the name of the following song?`n`nSong name = %query%`nURL = %url%
ifMsgBox, Yes
ChangeSongName()
ifMsgBox, No
return
}
ChangeSongName(){
InputBox, query, Change name
FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt; *.doc)
FileAppend,`n%query%`n%url%`n,%SelectedFile%
}