Jump to content

Your JTV v1.1


z0mgItsJohn
 Share

Recommended Posts

If you happen to watch live streams on Justin.tv and want a easy to way to keep track of the channels your following, this is the tool for you!

Current version : 1.1

Features :

- Channels with a blue text color are live.

- Click a channel once to view information (Title, Status, Category, Sub-category), or double click to view it.

- Hide or Show the window : This feature can be accessed via the tray menu.

- Notifier : Allows you to set specific channels to be notified about when they go live.

Known Problems :

- If you are following over 100 people, only 100 of them will show up, this is due to JTV's API only allowing up to 100 at a time, I'm pretty sure you could work around it, if you really wanted to.

Screen Shots :

Posted ImagePosted ImagePosted Image

Your JTV.au3 :

; Includes.
#Include <GUIConstantsEx.au3>
#Include <GUIListBox.au3>
#Include <GUITreeView.au3>
#Include <WindowsConstants.au3>
#Include <Misc.au3>
#Include <_XMLDomWrapper.au3>
#Include <File.au3>
#Include <Array.au3>
#Include <INet.au3>
#Include <Date.au3>

; Username check.
If IniRead ('settings.ini','Settings','Username','') == '' Then
    $Input = InputBox ('JTV Username?','What is your JTV username?','','', 200, 125)
    If @Error Then Exit
    If $Input = '' Then
        Do
            $Input = InputBox ('JTV Username?','What is your JTV username?','','', 200, 125)
            If @Error Then Exit
        Until $Input <> ''
    ElseIf @Error Then
        Exit 
    EndIf
    IniWrite ('settings.ini','Settings','Username', $Input)
EndIf

; Options.
Opt ('GUIOnEventMode', 1)
Opt ('TrayMenuMode', 1)
Opt ('TrayOnEventMode', 1)

; Tray menu.
$Tray_Toggle = TrayCreateItem ('Hide')
TrayItemSetOnEvent (-1, '_Toggle')
TrayCreateItem ('')
TrayCreateItem ('Exit')
TrayItemSetOnEvent (-1, '_Exit')

; Live vars.
Global $Live_Nodes, $Live_sTitles, $Live_Titles, $Live_URLs, $Live_Status, $Live_C, $Live_SC
; Last Live var.
Global $Last_Live_URLs = 0
; All vars.
Global $All_Nodes, $All_sTitles, $All_Titles, $All_URLs, $All_Status, $All_C, $All_SC
; Other vars.
Global $Toggle = 0, $Toggle_Hide = 1

; Main GUI.
$GUI = GUICreate ('Your JTV v1.1', 230, 310)
GUISetOnEvent ($GUI_EVENT_CLOSE, '_Exit')
GUICtrlCreateTab (0, 0, 232, 313)
GUICtrlCreateTabItem ('Channels')
$Channel_Tree = GUICtrlCreateTreeView (5, 25, 220, 255)
GUICtrlCreateButton ('Refresh', 5, 285, 55, 20)
GUICtrlSetOnEvent (-1, '_Refresh')
GUICtrlSetTip (-1, 'Refresh the list of channels.')
GUICtrlCreateButton ('Open JTV', 64, 285, 65, 20)
GUICtrlSetOnEvent (-1, '_Open_JTV')
GUICtrlCreateButton ('Exit', 133, 285, 40, 20)
GUICtrlSetOnEvent (-1, '_Exit')
GUICtrlCreateTabItem ('Settings')
GUICtrlCreateGroup ('', 5, 20, 220, 40)
$Username = GUICtrlCreateInput (IniRead ('settings.ini','Settings','Username',''), 11, 32, 153, 20)
GUICtrlSetTip (-1, 'Your JTV username.')
GUICtrlCreateButton ('Update', 168, 31, 52, 21)
GUICtrlSetOnEvent (-1, '_Update')
GUICtrlSetTip (-1, 'Update your JTV username.')
GUICtrlCreateGroup ('Notifier', 5, 61, 220, 245)
$Notifier = GUICtrlCreateCombo ('', 11, 78, 65)
GUICtrlSetOnEvent (-1, '_Save_Settings')
GUICtrlSetData (-1, 'Enabled|Disabled', IniRead ('settings.ini','Settings','Notifier','Disabled'))
GUICtrlSetTip (-1, 'The status of the notifier.')
$Delay = GUICtrlCreateInput (IniRead ('settings.ini','Settings','Delay', 10), 81, 78, 43, 21, 1)
GUICtrlSetOnEvent (-1, '_Save_Settings')
GUICtrlSetTip (-1, 'The delay between how often the notifier checks for live channels. (In minutes.)')
GUICtrlCreateUpdown (-1)
$Add = GUICtrlCreateButton ('Add', 128, 78, 34, 21)
GUICtrlSetOnEvent (-1, '_Toggle_Hide')
GUICtrlSetTip (-1, 'Add a channel to the notifier list.')
$Remove = GUICtrlCreateButton ('Remove', 165, 78, 55, 21)
GUICtrlSetOnEvent (-1, '_Remove')
GUICtrlSetTip (-1, 'Remove the selected channel from the notifier list.')
$Notifier_List = GUICtrlCreateList ('', 11, 104, 208, 200)
GUISetState (@SW_SHOW, $GUI)
WinSetOnTop ($GUI, '', 1)

; Add GUI
$Add_GUI = GUICreate ('Add', 220, 213, -1, -1, -1, 128)
GUISetOnEvent ($GUI_EVENT_CLOSE, '_Toggle_Hide')
$Add_List = GUICtrlCreateList ('', 0, 0, 220, 200)
GUICtrlCreateButton ('Add', 0, 191, 35, 20)
GUICtrlSetOnEvent (-1, '_Add')
GUICtrlSetTip (-1, 'Add the selected channel to the notifier list.')
GUICtrlCreateButton ('Add All', 37, 191, 45, 20)
GUICtrlSetOnEvent (-1, '_Add_All')
GUICtrlSetTip (-1, 'Add all of your channels to the notifier list.')
GUISetState (@SW_SHOW, $Add_GUI)
WinSetState ($Add_GUI, '', @SW_HIDE)
WinSetOnTop ($Add_GUI, '', 1)

; Notifier
If GUICtrlRead ($Notifier) == 'Enabled' Then
    _Notifier_List ()
    AdlibRegister ('_Refresh', (GUICtrlRead ($Delay) * (1000 * 60)))
Else
    GUICtrlSetState ($Delay, $GUI_DISABLE)
    GUICtrlSetState ($Add, $GUI_DISABLE)
    GUICtrlSetState ($Remove, $GUI_DISABLE)
    GUICtrlSetState ($Notifier_List, $GUI_DISABLE)
EndIf
    
_Refresh ()

; Main Loop
While 1
    Sleep (150)
WEnd

; Custom Functions
Func _Refresh ()
    Local $rUsername = GUICtrlRead ($Username)
    If $rUsername == '' Then Return
    ; Disable TreeView.
    GUICtrlSetState ($Channel_Tree, $GUI_DISABLE)
    ; Reset TreeView.
    _GUICtrlTreeView_DeleteAll ($Channel_Tree)
    ; Local vars.
    Local $Live_URL = 'http://api.justin.tv/api/user/favorites/' & $rUsername & '.xml?limit=100&offset=0&live=true'
    Local $All_URL = 'http://api.justin.tv/api/user/favorites/' & $rUsername & '.xml?limit=100&offset=0'
    Local $Live_XML = @TempDir & '\live.xml'
    Local $All_XML = @TempDir & '\all.xml'
    Local $Nodes, $A, $Title, $Len
    ; Check for any old XML files.
    If FileExists ($Live_XML) Then FileDelete ($Live_XML)
    If FileExists ($All_XML) Then FileDelete ($All_XML)
    ; Load live channels.
    INetGet ($Live_URL, $Live_XML)
    _XMLFileOpen ($Live_XML)
    $Nodes = _XMLGetNodeCount ('/channels/channel')
    Global $Live_Nodes = $Nodes
    If $Nodes > 0 Then
        Global $Live_sTitles[$Nodes + 1], $Live_Titles[$Nodes + 1], $Live_URLs[$Nodes + 1], $Live_Status[$Nodes + 1], $Live_C[$Nodes + 1], $Live_SC[$Nodes + 1]
        For $A = 1 To $Nodes
            $Title = _XMLGetFirstValue ('/channels/channel[' & $A & ']/title')
            ; Make sure the title isn't too long.
            If StringLen ($Title) > 25 Then $Title = StringLeft ($Title, 25) & '...'
            $Live_sTitles[$A] = $Title
            $Live_Titles[$A] = _XMLGetFirstValue ('/channels/channel[' & $A & ']/title')
            $Live_URLs[$A] = _XMLGetFirstValue ('/channels/channel[' & $A & ']/channel_url')
            ; Notifier
            If GUICtrlRead ($Notifier) == 'Enabled' Then
                If $Last_Live_URLs == 0 And _Check ($Live_URLs[$A]) == 1 Or _ArraySearch ($Last_Live_URLs, $Live_URLs[$A]) < 0 And _Check ($Live_URLs[$A]) == 1 Then
                    WinSetOnTop ($GUI, '', 0) 
                    $Msg = MsgBox (BitOr (4, 32), 'Live Channel Notice', $Title & ' is live, would you like to view this stream?')
                    WinSetOnTop ($GUI, '', 1)
                    GUICtrlSetState ($Channel_Tree, $GUI_DISABLE)
                    If $Msg == 6 Then _URL ($Live_URLs[$A])
                    GUICtrlSetState ($Channel_Tree, $GUI_ENABLE)
                EndIf
            EndIf
            $Live_Status[$A] = _XMLGetFirstValue ('/channels/channel[' & $A & ']/status')
            ; Make sure the status isn't too long.
            $Len = StringLen ($Live_Status[$A])
            If $Len > 74 Then
                If $Len > 148 Then
                    $Live_Status[$A] = StringLeft ($Live_Status[$A], 74) & @CRLF & StringMid ($Live_Status[$A], 75, 74) & @CRLF & StringRight ($Live_Status[$A], $Len - 148)
                ElseIf $Len = 148 Then
                    $Live_Status[$A] = StringLeft ($Live_Status[$A], 74) & @CRLF & StringRight ($Live_Status[$A], 74)
                Else
                    $Live_Status[$A] = StringLeft ($Live_Status[$A], 74) & @CRLF & StringRight ($Live_Status[$A], $Len - 74)
                EndIf
            EndIf
            If $Live_Status[$A] == '' Then $Live_Status[$A] = 'Status not set.'
            $Live_C[$A] = _XMLGetFirstValue ('/channels/channel[' & $A & ']/category_title')
            If $Live_C[$A] == '' Then $Live_C[$A] = 'Not Set'
            $Live_SC[$A] = _XMLGetFirstValue ('/channels/channel[' & $A & ']/subcategory_title')
            If $Live_SC[$A] == '' Then $Live_SC[$A] = 'Not Set'
            GUICtrlCreateTreeViewItem ($Title, $Channel_Tree)
            GUICtrlSetOnEvent (-1, '_Process')
            GUICtrlSetColor (-1, 0x0000FF)
        Next
        ; Add the current URLs to the last live URLs.
        If GUICtrlRead ($Notifier) == 'Enabled' Then
            Global $Last_Live_URLs[$Nodes + 1]
            For $A = 1 To $Nodes
                $Last_Live_URLs[$A] = $Live_URLs[$A]
            Next
        EndIf
    EndIf
    FileDelete ($Live_XML)
    ; Load all channels.
    INetGet ($All_URL, $All_XML)
    _XMLFileOpen ($All_XML)
    $Nodes = _XMLGetNodeCount ('/channels/channel')
    Global $All_Nodes = $Nodes
    If $Nodes > 0 Then
        Global $All_sTitles[$Nodes + 1], $All_Titles[$Nodes + 1], $All_URLs[$Nodes + 1], $All_Status[$Nodes + 1], $All_C[$Nodes + 1], $All_SC[$Nodes + 1]
        For $A = 1 To $Nodes
            $Title = _XMLGetFirstValue ('/channels/channel[' & $A & ']/title')
            ; Make sure the title isn't too long.
            If StringLen ($Title) > 25 Then $Title = StringLeft ($Title, 25) & '...'
                $All_sTitles[$A] = $Title
                $All_Titles[$A] = _XMLGetFirstValue ('/channels/channel[' & $A & ']/title')
                $All_URLs[$A] = _XMLGetFirstValue ('/channels/channel[' & $A & ']/channel_url')
                $All_Status[$A] = _XMLGetFirstValue ('/channels/channel[' & $A & ']/status')
                ; Make sure the status isn't too long.
                $Len = StringLen ($All_Status[$A])
                If $Len > 74 Then
                    If $Len > 148 Then
                        $All_Status[$A] = StringLeft ($All_Status[$A], 74) & @CRLF & StringMid ($All_Status[$A], 75, 74) & @CRLF & StringRight ($All_Status[$A], $Len - 148)
                    ElseIf $Len = 148 Then
                        $All_Status[$A] = StringLeft ($All_Status[$A], 74) & @CRLF & StringRight ($All_Status[$A], 74)
                    Else
                        $All_Status[$A] = StringLeft ($All_Status[$A], 74) & @CRLF & StringRight ($All_Status[$A], $Len - 74)
                    EndIf
                EndIf
                If $All_Status[$A] == '' Then $All_Status[$A] = 'Status not set.'
                $All_C[$A] = _XMLGetFirstValue ('/channels/channel[' & $A & ']/category_title')
                If $All_C[$A] == '' Then $All_C[$A] = 'Not Set'
                $All_SC[$A] = _XMLGetFirstValue ('/channels/channel[' & $A & ']/subcategory_title')
                If $All_SC[$A] == '' Then $All_SC[$A] = 'Not Set'
            If _ArraySearch ($Live_Titles, $Title) == -1 Then
                GUICtrlCreateTreeViewItem ($Title, $Channel_Tree)
                GUICtrlSetOnEvent (-1, '_Process')
            EndIf
        Next
    EndIf
    FileDelete ($All_XML)
    ; Enable TreeView.
    GUICtrlSetState ($Channel_Tree, $GUI_ENABLE)
EndFunc

Func _Process ()
    If ControlGetFocus ($GUI) <> 'SysTreeView321' Or WinGetTitle ('[ACTIVE]') <> WinGetTitle ($GUI) Then Return
    ; Declare vars.
    Local $Live_Index, $All_Index, $Text = _GUICtrlTreeView_GetText ($Channel_Tree, GUICtrlRead ($Channel_Tree)), $Timer, $Rect
    ; Search for index.
    $Live_Index = _ArraySearch ($Live_sTitles, $Text)
    $All_Index = _ArraySearch ($All_sTitles, $Text)
    ; Check for double click.
    Do
        Sleep (15)
    Until _IsPressed (01) = False
    $Timer = TimerInit ()
    Do
        Sleep (15)
    Until _IsPressed (01) Or TimerDiff ($Timer) >= 150
    ; Process single click or double click.
    If TimerDiff ($Timer) >= 150 Then
        If $Live_Index <> -1 Then _ToolTip ($Live_Titles[$Live_Index], $Live_Status[$Live_Index], $Live_C[$Live_Index], $Live_SC[$Live_Index])
        If $All_Index <> -1 Then _ToolTip ($All_Titles[$All_Index], $All_Status[$All_Index], $All_C[$All_Index], $All_SC[$All_Index])
    Else
        If $Live_Index <> -1 Then _URL ($Live_URLs[$Live_Index])
        If $All_Index <> -1 And $Live_Index = -1 Then _URL ($All_URLs[$All_Index])
    EndIf
EndFunc

Func _URL ($aURL)
    TrayTip ('','Loading URL : ' & $aURL, 2000, 1)
    WinSetState ($GUI, '', @SW_MINIMIZE)
    WinSetState ($GUI, '', @SW_DISABLE)
    ShellExecuteWait ($aURL)
    WinSetState ($GUI, '', @SW_ENABLE)
EndFunc

Func _Update ()
    Local $rUsername = GUICtrlRead ($Username)
    Local $URL = 'http://www.justin.tv/' & $rUsername
    If _INetGetSource ($URL) = '' Then
        GUICtrlSetData ($Username, 'Username does not exist.')
    Else 
        IniWrite ('settings.ini','Settings','Username', GUICtrlRead ($Username))
        _Refresh ()
    EndIf
EndFunc

Func _Add ()
    If GUICtrlRead ($Add_List) == '' Then Return
    Local $List = @ScriptDir & '\notifier_list.txt', $Index = _ArraySearch ($Last_Live_URLs, $All_URLs[_ArraySearch ($All_sTitles, GUICtrlRead ($Add_List))])
    If $Index > 0 Then _ArrayDelete ($Last_Live_URLs, $Index)
    FileWriteLine ($List, $All_URLs[_ArraySearch ($All_sTitles, GUICtrlRead ($Add_List))])
    _Notifier_List ()
    _Toggle_Hide ()
EndFunc

Func _Add_All ()
    Local $List = @ScriptDir & '\notifier_list.txt', $A
    Global $Last_Live_URLs = 0
    FileDelete ($List)
    For $A = 1 To $All_Nodes
        FileWriteLine ($List, $All_URLs[$A])
    Next
    _Notifier_List ()
    _Toggle_Hide ()
EndFunc

Func _Toggle_Hide ()
    Local $A
    If $Toggle_Hide == 0 Then
        WinSetState ($Add_GUI, '', @SW_HIDE)
        $Toggle_Hide = 1
    Else
        GUICtrlSetData ($Add_List, '')
        For $A = 1 To $All_Nodes
            GUICtrlSetData ($Add_List, $All_sTitles[$A])
        Next
        WinSetState ($Add_GUI, '', @SW_SHOW)
        $Toggle_Hide = 0
    EndIf
EndFunc

Func _Check ($aURL)
    Local $List = @ScriptDir & '\notifier_list.txt', $A, $Count = _FileCountLines ($List)
    For $A = 1 To $Count
        If FileReadLine ($List, $A) = $aURL Then Return 1
    Next
    Return 0
EndFunc

Func _Remove ()
    Local $List = @ScriptDir & '\notifier_list.txt', $A, $Count = _FileCountLines ($List), $Line, $Selected = GUICtrlRead ($Notifier_List), $Temp = @ScriptDir & '\Temp_List.txt'
    If FileExists ($List) == 0 Or GUICtrlRead ($Notifier_List) == 'Disabled' Or $Selected == '' Then Return
    If $Count == 1 And FileReadLine ($List, 1) == $Selected Then 
        GUICtrlSetData ($Notifier_List, '')
        GUICtrlSetData ($Notifier_List, 'No channels currently added.')
        FileDelete ($List)
        Return
    EndIf 
    For $A = 1 To $Count
        $Line = FileReadLine ($List, $A)
        If $Selected <> $Line Then FileWriteLine ($Temp, $Line)
    Next
    FileCopy ($Temp, $List, 1)
    FileDelete ($Temp)
    _Notifier_List ()
EndFunc

Func _Notifier_List ()
    Local $List = @ScriptDir & '\notifier_list.txt', $Count = _FileCountLines ($List)
    If $Count == 0 Then
        GUICtrlSetData ($Notifier_List, 'No channels currently added.')
        Return
    EndIf
    GUICtrlSetData ($Notifier_List, '')
    For $A = 1 To $Count
        GUICtrlSetData ($Notifier_List, FileReadLine ($List, $A))
    Next
EndFunc

Func _Save_Settings ()
    Local $Control = ControlGetFocus ($GUI), $Saved, $Current
    ; Determine which control was clicked.
    If $Control == 'Edit2' Then
        $Saved = IniRead ('settings.ini','Settings','Notifier','Disabled')
        $Current = GUICtrlRead ($Notifier)
        If $Saved <> $Current Then IniWrite ('settings.ini','Settings','Notifier', $Current)
        If $Saved <> 'Enabled' And $Current == 'Enabled' Then
            _Notifier_List ()
            AdlibRegister ('_Refresh', (GUICtrlRead ($Delay) * (1000 * 60)))
            GUICtrlSetState ($Delay, $GUI_ENABLE)
            GUICtrlSetState ($Add, $GUI_ENABLE)
            GUICtrlSetState ($Remove, $GUI_ENABLE)
            GUICtrlSetState ($Notifier_List, $GUI_ENABLE)
        ElseIf $Current == 'Disabled' Then
            AdlibUnRegister ('_Refresh')
            GUICtrlSetState ($Delay, $GUI_DISABLE)
            GUICtrlSetState ($Add, $GUI_DISABLE)
            GUICtrlSetState ($Remove, $GUI_DISABLE)
            GUICtrlSetState ($Notifier_List, $GUI_DISABLE)
        EndIf
    ElseIf $Control == 'Edit3' Then
        If GUICtrlRead ($Notifier) <> 'Enabled' Then Return
        $Saved = IniRead ('settings.ini','Settings','Delay', 10)
        $Current = GUICtrlRead ($Delay)
        If $Saved <> $Current Then IniWrite ('settings.ini','Settings','Delay', $Current)
        AdlibUnRegister ('_Refresh')
        AdlibRegister ('_Refresh', (GUICtrlRead ($Delay) * (1000 * 60)))
    EndIf
EndFunc

Func _Toggle ()
    If $Toggle = 0 Then
        WinSetState ($GUI, '', @SW_HIDE)
        TrayItemSetText ($Tray_Toggle, 'Show')
        $Toggle = 1
    Else
        WiNSetState ($GUI, '', @SW_SHOW)
        TrayItemSetText ($Tray_Toggle, 'Hide')
        $Toggle = 0
    EndIf
EndFunc

Func _Open_JTV ()
    _URL ('http://www.justin.tv')
EndFunc

Func _XMLGetFirstValue ($Node)
    Local $rVal
    $rVal = _XMLGetValue ($Node)
    If IsArray ($rVal) Then
        Return ($rVal[1])
    Else
        Return SetError (1, 3, 0)
    EndIf
EndFunc

Func _ToolTip ($Title, $Status, $C, $SC, $Delay = 3500)
    Local $Pos = MouseGetPos (), $Timer, $Pos2
    ToolTip ($Status & @CRLF & $C & ' -> ' & $SC, $Pos[0] + 13, $Pos[1], $Title)
    $Timer = TimerInit ()
    Do
        Sleep (10)
        $Pos2 = MouseGetPos ()
    Until $Pos[0] <> $Pos2[0] Or $Pos[1] <> $Pos2[1] Or TimerDiff ($Timer) >= $Delay
    ToolTip ('')
EndFunc

Func _Exit ()
    Exit
EndFunc

Settings.ini :

[Settings]
Username=
Notifier=Disabled
Delay=10

Download link (Source code and complied versions 64 and 32 bit) : http://www.mediafire.com/?yb3ew2on1fa121z

If you have any problems or suggestions, feel free to post them below :)!

Enjoy,

- John

Edited by z0mgItsJohn

Latest Projects :- New & Improved TCP Chat

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...