[Tool] Twitch/Justin.tv viewer count overlay (Update 1.0!)

dondi

New Member
Re: [Tool] Twitch/Justin.tv viewer count overlay (Update 1.0

Bkid said:
dondi said:
This is the tool I needed, thanks!

Could this also count down the viewers who watched the stream?
So it would looks something like this: "1/100 viewers".
Do you mean how many people are currently watching/how many people total have watched?

I'll try to look into that for the next update.
Yes that is the thing I meant. :)
 

GetReal

New Member
Re: [Tool] Twitch/Justin.tv viewer count overlay (Update 1.0

Hello all, just recently registered on OBS forums, yet I've been using the program for a while. I decided to join the forums to help you out Bkid!
Bkid said:
This is made in AHK, which only runs a single thread, so unfortunately that's not possible.
Actually it's quite possible to do so. Create a sub-routine (let's call it ThreadSub) with the code that fetches the data from Twitch/Justin API and on the main part of the program just create a timer with SetTimer. If you also want it to fetch the data right away (creating a timer will delay it by how much time you've given it to be refreshed), you can do something like this:
GoSub, ThreadSub
SetTimer, ThreadSub, 5000
This will allow it to instantly call the ThreadSub and then repeatedly do so in a 5 second cycle.
Also if you want the window to be click-through just add this somewhere before Gui, Show:
Gui, +E0x20
WinSet, Transparent, 255
This way the window will still be opaque but it will allow the clicks to pass through it.

I've got many projects of mine (sadly, not just for OBS) written in AHK, so if you have any questions feel free to contact me and I'll do my best to help you out!

EDIT:
I've just downloaded your source code and I see you already used a timer to poll the data from Justin API. If it still freezes the GUI, maybe you could use your Refresh sub-routine to fetch the data into a buffer and then use another sub-routine to read from that same buffer into the GUI. Also, I've decided to play around a bit, and added this somewhere before GuiClose, Exit and F12 hotkey labels:
Code:
F11::
  if(!isClickThrough) {
    Gui, +LastFound
    Gui, +E0x20
    WinSet, Transparent, 255
    isClickThrough := true
  }
  else {
    Gui, +LastFound
    Gui, -E0x20
    WinSet, Transparent, Off
    isClickThrough := false
  }
return
This will make a toggle for it to be (or not) click through.
 

Bkid

New Member
Re: [Tool] Twitch/Justin.tv viewer count overlay (Update 1.0

Thanks for the input, although I'm not sure anything can be done about the freezing.
Subroutines or not, AHK in and of itself, is a single-threaded language. It can only do one thing at a time. It may do those things very quickly (to the point where it looks like it's doing more than one thing at a time), but it's actually not.

That being said, when it goes to pull the data from the twitch API, it takes a while to do so in some cases. When/if it does, nothing else can be done during that time.

I'll look around for alternatives, but I'm not thinking there is one.
 

HypnoToadTrance

New Member
Re: [Tool] Twitch/Justin.tv viewer count overlay (Update 1.0

Bkid said:
Thanks for the input, although I'm not sure anything can be done about the freezing.
Subroutines or not, AHK in and of itself, is a single-threaded language. It can only do one thing at a time. It may do those things very quickly (to the point where it looks like it's doing more than one thing at a time), but it's actually not.

That being said, when it goes to pull the data from the twitch API, it takes a while to do so in some cases. When/if it does, nothing else can be done during that time.

I'll look around for alternatives, but I'm not thinking there is one.
You could use a different programming language :P

I made this program a while back for FFsplit.

http://www.mediafire.com/download/4cluc ... Status.exe

If you try it out, you can see how the refreshment does not cause lag.

This was programmed in Microsoft C# with the .NET 4.0 Framework. It's a very simple language. You might try your hand at it.

I can provide the sourcecode of this program too if you want to peruse it, though my code looks horrible xD
 

GetReal

New Member
Re: [Tool] Twitch/Justin.tv viewer count overlay (Update 1.0

Bkid said:
Thanks for the input, although I'm not sure anything can be done about the freezing.
[...]
I'll look around for alternatives, but I'm not thinking there is one.
I believe AHKsock does not block the main program. I've been trying it out, but apparently I suck at properly form an HTTP request...
If you want to have a go at it, AHKsock is here.
 

Yachak

Member
Re: [Tool] Twitch/Justin.tv viewer count overlay (Update 1.0

U want to download data from the api async, that will fix the problem. I can always help for things coded in C# as i use it to code
 

Bkid

New Member
Re: [Tool] Twitch/Justin.tv viewer count overlay (Update 1.0

HypnoToadTrance said:
Bkid said:
Thanks for the input, although I'm not sure anything can be done about the freezing.
Subroutines or not, AHK in and of itself, is a single-threaded language. It can only do one thing at a time. It may do those things very quickly (to the point where it looks like it's doing more than one thing at a time), but it's actually not.

That being said, when it goes to pull the data from the twitch API, it takes a while to do so in some cases. When/if it does, nothing else can be done during that time.

I'll look around for alternatives, but I'm not thinking there is one.
You could use a different programming language :P
I've been using AHK on and off for about 8 years, compared to 0 years with any other language (I'm a networking major, not programming).


GetReal said:
Bkid said:
Thanks for the input, although I'm not sure anything can be done about the freezing.
[...]
I'll look around for alternatives, but I'm not thinking there is one.
I believe AHKsock does not block the main program. I've been trying it out, but apparently I suck at properly form an HTTP request...
If you want to have a go at it, AHKsock is here.
I've looked into AHKsock out of curiosity, but never really tried much with it. Honestly this project is on hold for a little bit while I sort out life. Between work and school, there isn't much time for it, but I'll try to push out an update this weekend (no promises!).
 

GetReal

New Member
Re: [Tool] Twitch/Justin.tv viewer count overlay (Update 1.0

Bkid said:
Between work and school, there isn't much time for it, but I'll try to push out an update this weekend (no promises!).
Same here. Yet, this weekend I'll try to use another socket library to form a proper HTTP request so I can get the data without locking the main program. If I can achieve something, I'll post here and let you know.

EDIT:
I've managed to make it update without locking and added a new hotkey for toggling click through. I've also fixed some indentation, deleted the COM Object (I hate COM Objects :C) and "returns" in all cases of the "If ... else" statement and one extra "return" at the end of that. If all cases have something in common, most probably it can be done outside of the "if ... else" statement. Anyway, here it is:
Code:
#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
You gotta love timers. Even if you set a stupidly low interval of time for it, it still doesn't consume CPU (if done correctly). Check the line right after On_Message. ;)

EDIT2:
Forgot to leave the link for the WS lib! Sorry about that, here it is. Just scroll down to where it says:
WS.ahk: (Die Lib)
I'm not German, but I suspect that "Die lib" means "The library". Also, if you don't know how to work with libraries on AHK, here's an helpful link!
 

sodade21

New Member
Re: [Tool] Twitch/Justin.tv viewer count overlay (Update 1.0

very handy tool,Thanks.
Although i have a problem now and then the overlay box just dissapears and i have to re open the program and put where i want...it can happen in 1 minute or in 20 its completely random. is any way i can fix that or u can fix it? the game im playing is Guild Wars 2
 
Top