Emerica Posted July 13, 2006 Share Posted July 13, 2006 (edited) Sopcast is a p2ptv Application, Sopcast.com/.orgThis is Tcp listen Server for Sopcast, it allows you to open and close Sopcast as well as change channels.This application comes in handy as you can build other scripts and applications to make use of it.I've been working on a Python script for Xbox media center, meaning no more getting up off the couch to change the sopcast channel.. wow, lazy.expandcollapse popup;Sopcast Remote V0.0.1 ;Shane Andrusiak ;http://www.projectxnetwork.com #include <GUIConstants.au3> #include <String.au3> Opt("RunErrorsFatal", 0) #NoTrayIcon Opt("TrayMenuMode",1) Dim $pid = -1 Dim $msg,$recv,$old_status,$new_status,$end $Form1 = GUICreate("SopRemote V0.0.1", 335, 441, 336, 132) $logo = GUICtrlCreatePic("logo.bmp", 0, 0, 335, 127) $Group1 = GUICtrlCreateGroup("Sopcast Login Options", 8, 136, 321, 105) $suser = GUICtrlCreateRadio("Login as the selected user", 16, 168, 305, 17) $annon = GUICtrlCreateRadio("Login as an anonymous user", 16, 152, 297, 17) GUICtrlSetState(-1, $GUI_CHECKED) $userlist = GUICtrlCreateCombo("", 16, 192, 305, 21) $new = GUICtrlCreateButton("New", 160, 216, 50, 20) $edit = GUICtrlCreateButton("Edit", 216, 216, 50, 20) $delete = GUICtrlCreateButton("Delete", 272, 216, 50, 20) $Group2 = GUICtrlCreateGroup("SopRemote ", 8, 248, 321, 185) $iplist = GUICtrlCreateCombo("", 16, 280, 241, 21) $debug = GUICtrlCreateEdit("", 16, 312, 305, 89, $ES_READONLY, $WS_EX_STATICEDGE) GUICtrlSetData($debug, "SopRemote by Shane Andrusiak") $start = GUICtrlCreateButton("Start", 272, 408, 50, 20) GUICtrlCreateLabel("Select listening Ip Address", 16, 264, 128, 15) $port = GUICtrlCreateInput("8905", 264, 280, 57, 20, -1, $WS_EX_CLIENTEDGE) GUICtrlCreateLabel("Listen Port", 264, 264, 54, 15) If @IPAddress1 <> "0.0.0.0" Then $ips = @IPAddress1 If @IPAddress2 <> "0.0.0.0" Then $ips = $ips & "|" & @IPAddress2 If @IPAddress3 <> "0.0.0.0" Then $ips = $ips & "|" & @IPAddress3 If @IPAddress4 <> "0.0.0.0" Then $ips = $ips & "|" & @IPAddress4 GUICtrlSetData($iplist,$ips, @IPAddress1) $sopver = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\SopCast", "DisplayVersion") If @Error Then MsgBox(0, "Cannot find Sopcast Version", "Could not find Sopcast version information, please install sopcast.") If int(StringReplace($sopver,".","")) < 097 Then MsgBox(0, "Old Sopcast Version", "Your Sopcast version may be too old so SopRemote.") $info = GUICtrlCreateLabel("Found Sopcast Version: "&$sopver, 16, 408, 246, 17, $SS_SUNKEN) ;TRAY $Show = TrayCreateItem("Show") $Hide = TrayCreateItem("Hide") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() user_load() GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() $tmsg = TrayGetMsg() Select Case $msg = $GUI_EVENT_CLOSE WinSetState ( "SopRemote V0.0.1", "", @SW_HIDE ) Case $tmsg = $exititem ExitLoop Case $tmsg = $Show WinSetState ( "SopRemote V0.0.1", "", @SW_SHOW ) Case $tmsg = $Hide WinSetState ( "SopRemote V0.0.1", "", @SW_HIDE ) Case $msg = $new user_new() Case $msg = $edit user_edit() Case $msg = $delete user_delete() Case $msg = $start GUICtrlSetData($start,"Stop") TCPStartUp() $MainSocket = TCPListen(GUICtrlRead($iplist),GUICtrlRead($port)) If $MainSocket = -1 Then Exit While 1 AND $end <> 1 $msg = GuiGetMsg() $tmsg = TrayGetMsg() If $msg = $start OR $tmsg = $exititem Then $end =1 ExitLoop ElseIf $tmsg = $Show Then WinSetState ( "SopRemote V0.0.1", "", @SW_SHOW ) ElseIf $tmsg = $Hide OR $msg = $GUI_EVENT_CLOSE Then WinSetState ( "SopRemote V0.0.1", "", @SW_HIDE ) EndIf Dim $ConnectedSocket = -1 GUICtrlSetData($debug, "Waiting for connection" & @CRLF & GUICtrlRead($debug)) Do $ConnectedSocket = TCPAccept($MainSocket) $msg = GuiGetMsg() $tmsg = TrayGetMsg() If $msg = $start OR $tmsg = $exititem Then $end =1 ExitLoop ElseIf $tmsg = $Show Then WinSetState ( "SopRemote V0.0.1", "", @SW_SHOW ) ElseIf $tmsg = $Hide OR $msg = $GUI_EVENT_CLOSE Then WinSetState ( "SopRemote V0.0.1", "", @SW_HIDE ) EndIf Until $ConnectedSocket <> -1 Dim $szIP_Accepted = SocketToIP($ConnectedSocket) If $szIP_Accepted <> 0 Then GUICtrlSetData($debug, "New Connection from:" & $szIP_Accepted & @CRLF & GUICtrlRead($debug)) EndIf While 1 $msg = GUIGetMsg() $tmsg = TrayGetMsg() If $msg = $start OR $tmsg = $exititem Then $end =1 ExitLoop ElseIf $tmsg = $Show Then WinSetState ( "SopRemote V0.0.1", "", @SW_SHOW ) ElseIf $tmsg = $Hide OR $msg = $GUI_EVENT_CLOSE Then WinSetState ( "SopRemote V0.0.1", "", @SW_HIDE ) EndIf $recv = TCPRecv( $ConnectedSocket, 2048 ) If @error Then ExitLoop If $recv <> "" Then GUICtrlSetData($debug, $szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($debug)) If $recv <> "" Then $new_status = $recv $parts = StringSplit($recv, "|") If $parts[0] > 0 Then If $parts[1] == "channel" Then Sop_play(StringStripWS($parts[2],8)) ElseIf $parts[1] == "open" Then Sop_open() ElseIf $parts[1] == "close" Then Sop_close() EndIf EndIf EndIf EndIf WEnd If $ConnectedSocket <> -1 Then TCPCloseSocket( $ConnectedSocket ) WEnd TCPShutDown() $end = 0 GUICtrlSetData($start,"Start") GUICtrlSetData($debug, "Listening Stopped, Socket shutdown" & @CRLF & GUICtrlRead($debug)) Case Else ;;;;;;; EndSelect WEnd Exit Func SocketToIP($SHOCKET) Local $sockaddr = DLLStructCreate("short;ushort;uint;char[8]") Local $aRet = DLLCall("Ws2_32.dll","int","getpeername","int",$SHOCKET, _ "ptr",DLLStructGetPtr($sockaddr),"int_ptr",DLLStructGetSize($sockaddr)) If Not @error And $aRet[0] = 0 Then $aRet = DLLCall("Ws2_32.dll","str","inet_ntoa","int",DLLStructGetData($sockaddr,3)) If Not @error Then $aRet = $aRet[0] Else $aRet = 0 EndIf $sockaddr = 0 Return $aRet EndFunc Func Sop_open() $path = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\SopCast.exe","") $pid = Run( $path, "", @SW_MINIMIZE) If @error Then MsgBox(0, "Failed to find sopcast.exe","Please install Sopcast from http://www.sopcast.com") Else WinWait("SopCast") If GUICtrlRead($suser) == $GUI_CHECKED Then $sel = GUICtrlRead($userlist) If $sel == 0 OR $sel == "" Then MsgBox(0, "Select user to edit", "Please select a user first "&$sel) Else $sel = _StringEncrypt (1, $sel, "F9FA161EFBB9EBDCC7CC167B7FED8D69223EC7C8C1FAB7780E6B8CD3071EA4C8", 5 ) $var = IniRead("sopremote.ini", $sel, "key", 0) If @error Then return 0 Else $var = _StringEncrypt (0, $var, "F9FA161EFBB9EBDCC7CC167B7FED8D69223EC7C8C1FAB7780E6B8CD3071EA4C8", 5 ) ControlCommand ( "SopCast - Login", "", "Button3","Check", "" ) ControlSetText("SopCast - Login", "", "Edit1", GUICtrlRead($userlist)) ControlSetText("SopCast - Login", "", "Edit2", $var) ControlClick ( "SopCast - Login", "", "Button1" ) EndIf EndIf Else ControlCommand ( "SopCast - Login", "", "Button2","Check", "" ) ControlClick ( "SopCast - Login", "", "Button1" ) EndIf EndIf EndFunc Func Sop_close() ;Close Sopcast Client on the pc ProcessClose ( $pid ) $new_status = "SopCast Closed" EndFunc Func Sop_play($id) WinSetState ( "SopCast", "", @SW_RESTORE ) WinActivate("SopCast") WinWait("SopCast") ControlClick ( "", "Close", "Button4" ) Sleep(3000) ControlSend("SopCast", "", "Edit1", "sop://broker.sopcast.com:3912/"&$id) ControlClick ( "SopCast", "", "Button1") Sleep(5000) ControlClick ( "", "Close", 1014 ) WinSetState ( "SopCast", "", @SW_MINIMIZE ) $new_status = "Loading Channel" EndFunc Func Sop_status() If($old_status <> $new_status) Then $old_status = $new_status Endif EndFunc Func user_new() $email = InputBox("Enter Sopcast Login Email","Enter your Sopcast login email address","","",250,120) If @Error Then return 0 $pass = InputBox("Enter Sopcast Login Password","Enter your Sopcast login password","","*",250,120) If @Error Then return 0 $e_email = _StringEncrypt (1, $email, "F9FA161EFBB9EBDCC7CC167B7FED8D69223EC7C8C1FAB7780E6B8CD3071EA4C8", 5 ) $e_pass = _StringEncrypt (1, $pass, "F9FA161EFBB9EBDCC7CC167B7FED8D69223EC7C8C1FAB7780E6B8CD3071EA4C8", 5 ) IniWrite("sopremote.ini", $e_email, "key", $e_pass) user_load() EndFunc Func user_edit() $sel = GUICtrlRead($userlist) If $sel == 0 OR $sel == "" Then MsgBox(0, "Select user to edit", "Please select a user first "&$sel) Else $sel = _StringEncrypt (1, $sel, "F9FA161EFBB9EBDCC7CC167B7FED8D69223EC7C8C1FAB7780E6B8CD3071EA4C8", 5 ) $var = IniRead("sopremote.ini", $sel, "key", 0) If @error Then return 0 Else $email = InputBox("Update Sopcast Login Email","Update your Sopcast login email address",GUICtrlRead($userlist),"",250,120) If @Error Then return 0 $pass = InputBox("Update Sopcast Login Password","Update your Sopcast login password", $var,"*",250,120) If @Error Then return 0 $e_email = _StringEncrypt (1, $email, "F9FA161EFBB9EBDCC7CC167B7FED8D69223EC7C8C1FAB7780E6B8CD3071EA4C8", 5 ) $e_pass = _StringEncrypt (1, $pass, "F9FA161EFBB9EBDCC7CC167B7FED8D69223EC7C8C1FAB7780E6B8CD3071EA4C8", 5 ) IniDelete("sopremote.ini", $sel) IniWrite("sopremote.ini", $e_email, "key", $e_pass) EndIf EndIf GUICtrlSetData($userlist,"") user_load() EndFunc Func user_delete() $sel = GUICtrlRead($userlist) If $sel == 0 OR $sel == "" Then MsgBox(0,"Select a user first", "You must select a user to delete first") Else $val = MsgBox(4,"Are you sure", "Are you sure you want to remove: "&$sel&" ?") If $val == 6 Then $sel = _StringEncrypt (1, $sel, "F9FA161EFBB9EBDCC7CC167B7FED8D69223EC7C8C1FAB7780E6B8CD3071EA4C8", 5 ) IniDelete ("sopremote.ini", $sel ) Else return 0 EndIf EndIf GUICtrlSetData($userlist,"") user_load() EndFunc Func user_load() $var = IniReadSectionNames("sopremote.ini") If @error Then return 0 Else $out="" For $i = 1 To $var[0] $e_email = _StringEncrypt (0, $var[$i], "F9FA161EFBB9EBDCC7CC167B7FED8D69223EC7C8C1FAB7780E6B8CD3071EA4C8", 5 ) $out = $out & $e_email & "|" Next GUICtrlSetData($userlist,"") GUICtrlSetData($userlist,$out, $e_email) EndIf EndFunc Func get_user() $sel = GUICtrlRead($userlist) If $sel == 0 OR $sel == "" Then MsgBox(0, "Select user to edit", "Please select a user first "&$sel) Else $sel = _StringEncrypt (1, $sel, "F9FA161EFBB9EBDCC7CC167B7FED8D69223EC7C8C1FAB7780E6B8CD3071EA4C8", 5 ) $var = IniRead("sopremote.ini", $sel, "key", 0) If @error Then return 0 Else $parts = GUICtrlRead($userlist) & "|" & $var return StringSplit($parts, "|") EndIf EndIf EndFuncLogo.bmp --->>>> http://pxn.ca/Projects/sopcast/Software/SopRemote/logo.bmpI have an uncompleted version of the python script hereNOTE: You will need to change the listening IP/PORT at the top of the xbmc script if you try to use it.Examples ImagesPc Listen ServerXbox Media Center Client Edited July 13, 2006 by Emerica Project X Network StreamDrive Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now