#SingleInstance, Force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_AppData% ; Ensures a consistent starting directory.
viewers :=
;menu, tray, nostandard
;menu, tray, add, Exit
;Creates and fills a folder and ini file in AppData if one does not exist.
IfNotExist, tvco
{
FileCreateDir, tvco
IniWrite, Bkid, tvco\tvco.ini, Settings, StreamName
}
;Prepare the socket
WS_Startup()
socket := WS_Socket()
WS_Connect(socket, "api.justin.tv", "80")
IniRead, StreamName, tvco\tvco.ini, Settings, StreamName
Gui, Add, Text, x25 y8, http://twitch.tv/
Gui, Add, Edit, x104 y5 w150 vStreamName, %StreamName%
Gui, Add, Button, x5 gGo w270 Default, Go!
Gui, Add, Button, x5 gAbout w270, About
Gui, Add, Button, x5 gExit w270, Exit
Gui, Show, w280, Twitch Viewer Count Overlay
Return
Go:
Gui, Submit
If !StreamName
{
MsgBox, Please enter a stream name!
Reload
}
IniWrite, %StreamName%, tvco\tvco.ini, Settings, StreamName
Gui, Destroy
Gui, -caption +border +AlwaysOnTop +ToolWindow
Gui, Add, Text, x5, Viewers:
Gui, Add, Text, x+3 w30 vViewCount, Loading
Gui, Show, w90
OnMessage(0x201, "WM_LButtonDOWN")
SetTimer, GetResponse, 0
GoSub, Refresh
Return
GetResponse:
WS_Recv(socket, response)
return
Refresh:
SetTimer, Refresh, 10000
request := "GET /api/stream/summary.xml?channel=" StreamName " HTTP/1.1`r`n"
request .= "Host: api.justin.tv`r`n"
request .= "Accept: */*`r`n`r`n"
WS_Send(socket, request)
if(response) {
if(InStr(response, "200 OK`r`n")) {
RegExMatch(response, "(?<=<streams_count>).*?(?=</streams_count>)", online)
RegExMatch(response, "(?<=<viewers_count>).*?(?=</viewers_count>)", viewers)
if(online = 0)
GuiControl, ,ViewCount, Offline
else
GuiControl, ,ViewCount, % viewers
}
else
GuiControl, ,ViewCount, Timeout
}
Return
WM_LBUTTONDOWN()
{
If A_Gui
PostMessage, 0xA1, 2
}
Return
About:
MsgBox, Twitch Viewer Count Overlay by Bkid`n v1.0.0.0`n Bkid@bemaniso.ws
Return
F11::
if(!isClickThrough) {
Gui, +LastFound
Gui, +E0x20
WinSet, Transparent, 255
isClickThrough := true
}
else {
Gui, +LastFound
Gui, -E0x20
WinSet, Transparent, Off
isClickThrough := false
}
return
Exit:
GuiClose:
F12::
;Close the socket
WS_CloseSocket(socket)
WS_ShutDown()
ExitApp