WM Recorder 11 GUI automation script

6 posts in this topic

Maxim Vexler 0

I've written a little automation for WM Recorder because that is the only application I could find that would record the propriaty mms streaming protocol.

Here it is, in the hope that It would be useful to some one.

It works pretty well but it's not perfect and some features are still missing.

Enjoy!

;AutoIt 3 automation script for WM Recorder 11.0;Copyright (C) 2006 Maxim Veksler hq4ever-@-gmail-com ;;This program is free software; you can redistribute it and/or;modify it under the terms of the GNU General Public License;as published by the Free Software Foundation; either version 2;of the License, or (at your option) any later version.;;This program is distributed in the hope that it will be useful,;but WITHOUT ANY WARRANTY; without even the implied warranty of;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the;GNU General Public License for more details.;;http://www.gnu.org/copyleft/gpl.html;;;;;;;;;;;;; FUNCTIONSFunc_nixNOW()Return@MON&@MDAY&@HOUR&@MIN&@YEAR&@SECEndFuncFunc FileNameFromURI($uri)$_position=StringInStr($uri,"/",0,-1)$_filename=StringMid($uri,$_position+1)Return$_filenameEndFuncFunc FileNameFromPath($file_path)$_position=StringInStr($file_path,"\",0,-1)$_filename=StringMid($file_path,$_position+1)Return$_filenameEndFuncFunc RecordingPath($uri)LocalConst$ROOT_PATH="c:\videos"$_position_from=StringInStr($uri,"/",0,-2)$_position_to=StringInStr($uri,"/",0,-1)$_fldr_name=StringMid($uri,$_position_from+1,($_position_to-$_position_from)-1)Return$ROOT_PATH&$_fldr_nameEndFuncFunc WaitDownload($mainwnd_hndl,$dest_file_pattern,$dest_file_path)LocalConst$GRACE_TIMER=50000Dim$_ctrl_status_init_time=TimerInit()Dim$_ctrl_status_lastrun_textWhile1=1$_ctrl_status_text=ControlGetText($mainwnd_hndl,"","Edit1")$_status=StringSplit(StringStripWS($_ctrl_status_text,4)," ");; TODO: First check should be how many times we've run this baby (based on time diff);; Could be we're in some nice endless loop, and as you know it : Endless loops are not nice;;;;;; Check to see if we oversteped permitted run times; if TRIED TO DOWNLOAD TOO MUCH TIMES() > HOW_MUCH_TIMES_CAN_I_RUN then; return -4;;;;;; Wait until we get "real status" from extenal application and not some unknown junkif($_status[0]<>7)thenIf($_status[1]=="Mode:")thenReturn-1;Elsesleep(250)ContinueLoopEndifEndif;;;;;; Check If download finished;; example text: "0. Numerical%20... 100% 82.436 MB 0 Kbps"If(($_status[3]=="100%")AND($_status[6]=="0"))thenReturn0;Downloaded (finished)Endif;;;;;; Check if download hungif($_ctrl_status_text==$_ctrl_status_lastrun_text)thenif(TimerDiff($_ctrl_status_init_time)>$GRACE_TIMER)thenReturn-1;Download stopped (hung)EndifElse$_ctrl_status_init_time=TimerInit()Endif;;;;;; Do total file size logic as soon as possible, i.e. as we reach 2%If((NotIsDeclared("_total_fl_size"))AND(Number(StringTrimRight($_status[3],1))==1))then$_1percent_fl_size=Number($_status[4])EndifIf((NotIsDeclared("_total_fl_size"))AND(Number(StringTrimRight($_status[3],1))==3))then$_2percent_fl_size=Number($_status[4])$_total_fl_size=(($_2percent_fl_size-$_1percent_fl_size)*100)$_ondisk_dest_files= FileFindToArray($dest_file_pattern,$dest_file_path)IfIsArray($_ondisk_dest_files)then$_ondisk_dest_file_size=FileGetSize($dest_file_path&$_ondisk_dest_files[0])/1048576Else$_ondisk_dest_file_size=(-999999999)EndifIf(IsDeclared("_total_fl_size")ANDIsDeclared("_ondisk_dest_file_size"))thenIf(Abs($_total_fl_size-$_ondisk_dest_file_size)<6)thenreturn-2;File exists full (downloaded)EndifEndifEndif;;;;;; Loop internal variable initialization$_ctrl_status_lastrun_text=ControlGetText($mainwnd_hndl,"","Edit1")Sleep(250)WendEndFuncFunc delay_WaitForControl($handle,$text,$controlID,$delay_ms_limit=300000)Dim$_ctrl_delay_init_time=TimerInit()DoIf(TimerDiff($_ctrl_delay_init_time)>$delay_ms_limit)thenReturn@errorEndifsleep(5)AutoItSetOption("WinTitleMatchMode",4)ControlGetPos($handle,$text,$controlID)Until(@error==0)Return@errorEndFuncFunc FileFindToArray($filename_pattern,$path="");;;; Will return an array of files name, sorted by biggest first.;; Note the case of return value (-1) if no files found.;;Dim$MatchFileName[1]If((StringLen($path)>0)AND(StringRight($path,1)<>"\"))then$path=$path&"\"Endif$search=FileFindFirstFile($path&$filename_pattern)If$search=(-1)ThenReturn0EndIfWhile1=1$file=FileFindNextFile($search)If@errorThenExitLoop$MatchFileName[Ubound($MatchFileName)-1]=$fileReDim$MatchFileName[UBound($MatchFileName)+1]WEnd; Close the search handleFileClose($search)ReDim$MatchFileName[UBound($MatchFileName)-1]For$i=(UBound($MatchFileName)-2)to0Step-1; (-2) because = 1 for UBound, 1 to loop not reaching last object.for$j=0to$iIfFileGetSize($path&$MatchFileName[$j])<FileGetSize($path&$MatchFileName[$j+1])then$swap=$MatchFileName[$j]$MatchFileName[$j]=$MatchFileName[$j+1]$MatchFileName[$j+1]=$swapEndifNextNextReturn$MatchFileNameEndFuncFunc_Change_Folder_WMR11($folder_path)
delay_WaitForControl("classname=#32770","General","Button4")ControlClick(WinGetHandle("classname=#32770","General"),"","Button4")
delay_WaitForControl("classname=#32770","If you are using an older version of WM Recorder","Button1")ControlClick(WinGetHandle("classname=#32770","If you are using an older version of WM Recorder"),"","Button1")
delay_WaitForControl("classname=#32770","Recordings directory","Edit1")ControlSetText(WinGetHandle("classname=#32770","Recordings directory"),"","Edit1", RecordingPath($folder_path))
delay_WaitForControl("classname=#32770","Recordings directory","Button2")ControlClick(WinGetHandle("classname=#32770","Recordings directory"),"","Button2")
delay_WaitForControl("classname=#32770","General","Button8")ControlClick(WinGetHandle("classname=#32770","General"),"","Button8")EndFuncFunc_Close_Recording_Window_WMR11()
delay_WaitForControl("classname=#32770","Right click the File Name for options","Button1")ControlClick(WinGetHandle("classname=#32770","Right click the File Name for options"),"","Button1")If delay_WaitForControl("classname=#32770","This will stop all current recordings","Button1",7000)==0thenControlClick(WinGetHandle("classname=#32770","This will stop all current recordings"),"","Button1")EndifEndFuncFunc SearchWindowByTitle($WindowList,$TitleText)Dim$i=0For$i=1to$WindowList[0][0]If($WindowList[$i][0]==$TitleText)thenReturn$WindowList[$i][1]EndifNextReturn0EndFuncFunc WindowMakeActive($handle)$_wnd_state=WinGetState($handle)WinSetState($handle,"",@SW_ENABLE)WinSetState($handle,"",@SW_SHOW)WinSetState($handle,"",@SW_RESTORE)WinActivate($handle)Return$_wnd_stateEndFuncFunc WindowRestoreState($handle,$wnd_state)IfBitAnd($wnd_state,4)thenWinSetState($handle,"",@SW_ENABLE)ElseWinSetState($handle,"",@SW_DISABLE)EndifIfBitAnd($wnd_state,2)thenWinSetState($handle,"",@SW_SHOW)ElseWinSetState($handle,"",@SW_HIDE)EndifSelectcaseBitAnd($wnd_state,16)WinSetState($handle,"",@SW_MINIMIZE)caseBitAnd($wnd_state,32)WinSetState($handle,"",@SW_MAXIMIZE)EndSelectEndFunc;; An enhanced MouseClick that would do anything it can to click-that-buttonFunc MouseKick($wnd_handle=0,$x="XPOS",$y="YPOS",$aio_MouseCoordMode=0,$mouse_button="primary",$clicks=1,$speed=0)AutoItSetOption("MouseCoordMode",$aio_MouseCoordMode)$_app_state= WindowMakeActive ($wnd_handle)If(IsNumber($x)ANDIsNumber($y))thenMouseClick($mouse_button,$x,$y,$clicks,$speed)Else$pos=MouseGetPos()MouseClick($mouse_button,$pos[0],$pos[1],$clicks,$speed)Endif
WindowRestoreState ($wnd_handle,$_app_state)EndFunc;;;;;;;;;;;;; DATADim$StreamingSources[7];; StringFormat = "protocol://URI/static-name,TRAILING-ZEROS,FROM-COUNT,TO-COUNT,.extension"$StreamingSources[0]="mms://video.sub.domain.tld/path/to/streaming/source/FILENAME-,2,6,27,.wmv"$StreamingSources[1]="mms://video.sub.domain.tld/path/to/streaming/source/OTHERNAME_,2,1,28,.wmv"; Example: $StreamingSources[0] = "mms://video.site.com/video/hot/movie-,5,1,4,.wmv" would download :; mms://video.site.com/video/hot/movie-00001.wmv; mms://video.site.com/video/hot/movie-00002.wmv; mms://video.site.com/video/hot/movie-00003.wmv; mms://video.site.com/video/hot/movie-00004.wmv;;;;;;;;;;;;; INITIALIZATIONAutoItSetOption("WinTitleMatchMode",4)AutoItSetOption("MouseCoordMode",0)AutoItSetOption("TrayIconDebug",1)$_wmr_winlist=WinList("classname=#32770");;;;;;;;;;;;; START HELPER APPLICATIONS;; So, what am I doing here ? ;; If all checks for application parts return false: I'm assuming application is not launched.;; If all checks for application parts return true: I'm assuming application is launched and active;; If some parts return true and others say false: I'm assuming application is semi loaded, so lets reload itIf((SearchWindowByTitle($_wmr_winlist,"")==0)AND_(SearchWindowByTitle($_wmr_winlist,"WM Recorder - Windows Media")==0)AND_(SearchWindowByTitle($_wmr_winlist,"WM Recorder - Recording Window")==0))then;; Good, no memory resistent copies of application, launch itrun("C:\Program Files\WMR11\WMR11.exe")Elseif((SearchWindowByTitle($_wmr_winlist,"")<>0)AND_(SearchWindowByTitle($_wmr_winlist,"WM Recorder - Windows Media")<>0)AND_(SearchWindowByTitle($_wmr_winlist,"WM Recorder - Recording Window")<>0))then;; looks like the application is fully loaded, let it bemsgbox(0,"","Looks fine to me, application is active")Else;; If we got here that means part of the application is still in memory;; Kill all available parts and then reload.WinKill( SearchWindowByTitle($_wmr_winlist,""))WinKill( SearchWindowByTitle($_wmr_winlist,"WM Recorder - Windows Media"))WinKill( SearchWindowByTitle($_wmr_winlist,"WM Recorder - Recording Window"))ProcessClose("WMR11.exe")ProcessWaitClose("WMR11.exe")run("C:\Program Files\WMR11\WMR11.exe")endif;; Loop until splashscreen gone, which has the same classname and same text :(
delay_WaitForControl("classname=#32770","","Edit2");; Second run of WinList() to include changes occured after HELPER APPLICATION logic$_wmr_winlist=WinList("classname=#32770");;;;;;;;;;;;; RUN MAIN RECORDING LOOPifWinWait("classname=#32770")then$handle_mainwnd= SearchWindowByTitle($_wmr_winlist,"")For$indx=0toUBound($StreamingSources)-1$_strmInfo=StringSplit($StreamingSources[$indx],",")DirCreate( RecordingPath($_strmInfo[1]))For$i=Number($_strmInfo[3])toNumber($_strmInfo[4]);; download from [number] to [how many there are]...$_strformat="%."&$_strmInfo[2]&"d"&$_strmInfo[5]$_waitdl_file= FileNameFromURI($_strmInfo[1])&StringFormat($_strformat,$i)$_waitdl_file_pattern= FileNameFromURI($_strmInfo[1])&StringFormat("%."&$_strmInfo[2]&"d*"&$_strmInfo[5],$i)
delay_WaitForControl($handle_mainwnd,"","Edit2")ControlSetText($handle_mainwnd,"","Edit2",$_waitdl_file)ControlSetText($handle_mainwnd,"",321,$_strmInfo[1]&StringFormat($_strformat,$i));; STATR: Folder change sequance for application
MouseKick($handle_mainwnd,250,50)_Change_Folder_WMR11( RecordingPath($_strmInfo[1]));; END: Do folder change sequance;; Click on the record button
MouseKick($handle_mainwnd,45,75)$_waitdl_ret= WaitDownload($handle_mainwnd,$_waitdl_file_pattern, RecordingPath($_strmInfo[1])&"\")Selectcase$_waitdl_ret==(-1);; msgbox (1, "", "WaitDownload sayed -1 == application did nothing for Xms time");; OK, wait a couple of min and try again will'ya ;)sleep(15000)$i=$i-1case$_waitdl_ret==0; Very Cool !; Here we go for the biggest of them all with FileFindToArray() and then delete all the rest(?)$_ondisk_media_files= FileFindToArray($_waitdl_file_pattern, RecordingPath($_strmInfo[1])&"\")IfIsArray($_ondisk_media_files)thenfor$ifile=1toUBound($_ondisk_media_files)-1FileMove( RecordingPath($_strmInfo[1])&"\"&$_ondisk_media_files[$ifile],_
RecordingPath($_strmInfo[1])&"\"&_nixNOW()&"_"&$_ondisk_media_files[$ifile])NextFileMove( RecordingPath($_strmInfo[1])&"\"&$_ondisk_media_files[0],_
RecordingPath($_strmInfo[1])&"\"&$_waitdl_file)Endifcase$_waitdl_ret==(-2); Very Cool !; Here we go for the biggest of them all with FileFindToArray() and then delete all the rest(?)$_ondisk_media_files= FileFindToArray($_waitdl_file_pattern, RecordingPath($_strmInfo[1])&"\")IfIsArray($_ondisk_media_files)thenfor$ifile=1toUBound($_ondisk_media_files)-1FileMove( RecordingPath($_strmInfo[1])&"\"&$_ondisk_media_files[$ifile],_
RecordingPath($_strmInfo[1])&"\"&_nixNOW()&"_"&$_ondisk_media_files[$ifile])NextFileMove( RecordingPath($_strmInfo[1])&"\"&$_ondisk_media_files[0],_
RecordingPath($_strmInfo[1])&"\"&$_waitdl_file)Endifcase$_waitdl_ret==(-4); msgbox (1, "", "WaitDownload sayed -4 == dude, your over your limits"); Fuck it, fuck him, fuck everyone. "If YOU don't want to be downloaded I am surely not going to do it for you ;)"$_foo="foo"caseelsemsgbox(1,"","WaitDownload sayed "&$_waitdl_ret&"(wtf?)")Endselect;; Helper application logic: End recording session before starting new one_Close_Recording_Window_WMR11()NextNextendif

Share this post

Link to post

Share on other sites

Maxim Vexler 0

I tried not to, but you are forcing me to do promotion for the product

WM Recorder is an application wrapper for common streaming protocols such as mms and rtsp, it uses the open source libpcap library on windows to record the network traffic the comes from the streaming source to the viewer and then dumps this stream to a file on the hard disk for later review. Very useful and works great. The only downside is that it's (like most windows applications) totaly non scriptable and GUI only based, that's when I believe my script comes into play allowing to interface with the application using it's GUI.

I'm using it to record video lectures for later viewing and to save bandwidth if I wish to view the same lecture twice.

Share this post

Link to post

Share on other sites

Maxim Vexler 0

I think that even you guys who don't use WM Recorder could find this code useful, for example check MouseKick() function.

Enjoy !

Maxim.

;AutoIt 3 automation script for WM Recorder 11.0;Copyright (C) 2006 Maxim Veksler hq4ever-@-gmail-com ;;This program is free software; you can redistribute it and/or;modify it under the terms of the GNU General Public License;as published by the Free Software Foundation; either version 2;of the License, or (at your option) any later version.;;This program is distributed in the hope that it will be useful,;but WITHOUT ANY WARRANTY; without even the implied warranty of;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the;GNU General Public License for more details.;;http://www.gnu.org/copyleft/gpl.html;;;;;;;;;;;;; FUNCTIONSFunc_nixNOW()Return@MON&@MDAY&@HOUR&@MIN&@YEAR&@SECEndFuncFunc FileNameFromURI($uri)Local$_position=StringInStr($uri,"/",0,-1)Local$_filename=StringMid($uri,$_position+1)Return$_filenameEndFuncFunc FileNameFromPath($file_path)Local$_position=StringInStr($file_path,"\",0,-1)Local$_filename=StringMid($file_path,$_position+1)Return$_filenameEndFuncFunc RecordingPath($uri)Local$_position_from=StringInStr($uri,"/",0,-2)Local$_position_to=StringInStr($uri,"/",0,-1)Local$_fldr_name=StringMid($uri,$_position_from+1,($_position_to-$_position_from)-1)Return$_fldr_nameEndFuncFunc WaitDownload($mainwnd_hndl,$dest_file_pattern,$dest_file_path)LocalConst$GRACE_TIMER=120000Local$_ctrl_status_init_time=TimerInit()Local$_ctrl_status_lastrun_textWhile1=1Local$_ctrl_status_text=ControlGetText($mainwnd_hndl,"","Edit1")Local$_status=StringSplit(StringStripWS($_ctrl_status_text,4)," ");; TODO: First check should be how many times we've run this baby (based on time diff);; Could be we're in some nice endless loop, and as you know it : Endless loops are not nice;;;;;; Wait until we get "real status" from extenal application and not some unknown junkif($_status[0]<>7)thenIf(($_status[1]=="Mode:")AND(TimerDiff($_ctrl_status_init_time)>$GRACE_TIMER))thenReturn-1;Elsesleep(250)ContinueLoopEndifEndif;;;;;; Check If download finished;; example text: "0. Numerical%20... 100% 82.436 MB 0 Kbps"If(($_status[3]=="100%")AND($_status[6]=="0")AND(TimerDiff($_ctrl_status_init_time)>15000))thenReturn0;Downloaded (finished)Endif;;;;;; Check if download hungif($_ctrl_status_text==$_ctrl_status_lastrun_text)thenif(TimerDiff($_ctrl_status_init_time)>$GRACE_TIMER)thenReturn-1;Download stopped (hung)EndifElse$_ctrl_status_init_time=TimerInit()Endif;;;;;; Do total file size logic as soon as possible, i.e. as we reach 2%If((NotIsDeclared("_total_fl_size"))AND(Number(StringTrimRight($_status[3],1))==1))thenLocal$_1percent_fl_size=Number($_status[4])EndifIf((NotIsDeclared("_total_fl_size"))AND(Number(StringTrimRight($_status[3],1))==3))thenLocal$_2percent_fl_size=Number($_status[4])Local$_total_fl_size=(($_2percent_fl_size-$_1percent_fl_size)*100)Local$_ondisk_dest_files= FileFindToArray($dest_file_pattern,$dest_file_path)IfIsArray($_ondisk_dest_files)thenLocal$_ondisk_dest_file_size=FileGetSize($dest_file_path&$_ondisk_dest_files[0])/1048576ElseLocal$_ondisk_dest_file_size=(-999999999)EndifIf(IsDeclared("_total_fl_size")ANDIsDeclared("_ondisk_dest_file_size"))thenIf(Abs($_total_fl_size-$_ondisk_dest_file_size)<6)thenreturn-2;File exists full (downloaded)EndifEndifEndif;;;;;; Check to see if we oversteped permitted run times; if TRIED TO DOWNLOAD TOO MUCH TIMES() > HOW_MUCH_TIMES_CAN_I_RUN then; return -4;;;;;; Loop internal variable initialization$_ctrl_status_lastrun_text=ControlGetText($mainwnd_hndl,"","Edit1")Sleep(250)WendEndFuncFunc_delay_WaitForControl($handle,$text,$controlID,$delay_ms_limit=20000)Local$_ctrl_delay_init_time=TimerInit()DoIf(TimerDiff($_ctrl_delay_init_time)>$delay_ms_limit)thenReturn0Endifsleep(5)AutoItSetOption("WinTitleMatchMode",4)ControlGetPos($handle,$text,$controlID)Until(@error==0)Return(@error==0)EndFuncFunc FileFindToArray($filename_pattern,$path="");;;; Will return an array of files name, sorted by biggest first.;; Note the case of return value (-1) if no files found.;;Local$MatchFileName[1]If((StringLen($path)>0)AND(StringRight($path,1)<>"\"))thenLocal$path=$path&"\"Endif$search=FileFindFirstFile($path&$filename_pattern)If$search=(-1)ThenReturn0EndIfWhile1=1Local$file=FileFindNextFile($search)If@errorThenExitLoop$MatchFileName[Ubound($MatchFileName)-1]=$fileReDim$MatchFileName[UBound($MatchFileName)+1]WEnd; Close the search handleFileClose($search)ReDim$MatchFileName[UBound($MatchFileName)-1]Local$iFor$i=(UBound($MatchFileName)-2)to0Step-1; (-2) because = 1 for UBound, 1 to loop not reaching last object.for$j=0to$iIfFileGetSize($path&$MatchFileName[$j])<FileGetSize($path&$MatchFileName[$j+1])thenLocal$swap=$MatchFileName[$j]$MatchFileName[$j]=$MatchFileName[$j+1]$MatchFileName[$j+1]=$swapEndifNextNextReturn$MatchFileNameEndFuncFunc_change_Folder_WMR11($folder_path)_delay_WaitForControl("classname=#32770","General","Button4")ControlClick(WinGetHandle("classname=#32770","General"),"","Button4")_delay_WaitForControl("classname=#32770","If you are using an older version of WM Recorder","Button1")ControlClick(WinGetHandle("classname=#32770","If you are using an older version of WM Recorder"),"","Button1")_delay_WaitForControl("classname=#32770","Recordings directory","Edit1")ControlSetText(WinGetHandle("classname=#32770","Recordings directory"),"","Edit1",$ROOT_RECORDING_PATH& RecordingPath($folder_path))_delay_WaitForControl("classname=#32770","Recordings directory","Button2")ControlClick(WinGetHandle("classname=#32770","Recordings directory"),"","Button2")_delay_WaitForControl("classname=#32770","General","Button8")ControlClick(WinGetHandle("classname=#32770","General"),"","Button8")EndFuncFunc_close_Recording_Window_WMR11($handle_recwnd)_delay_WaitForControl($handle_recwnd,"","Button1")ControlClick($handle_recwnd,"","Button1")If_delay_WaitForControl("classname=#32770","This will stop all current recordings","Button1",3500)thenControlClick(WinGetHandle("classname=#32770","This will stop all current recordings"),"","Button1")EndifEndFuncFunc SearchWindowByTitle($WindowList,$TitleText)Local$i=0For$i=1to$WindowList[0][0]If($WindowList[$i][0]==$TitleText)thenReturn$WindowList[$i][1]EndifNextReturn0EndFuncFunc WindowMakeActive($handle)Local$_wnd_state=WinGetState($handle)WinSetState($handle,"",@SW_ENABLE)WinSetState($handle,"",@SW_SHOW)WinSetState($handle,"",@SW_RESTORE)WinActivate($handle)Return$_wnd_stateEndFuncFunc WindowRestoreState($handle,$wnd_state)IfBitAnd($wnd_state,4)thenWinSetState($handle,"",@SW_ENABLE)ElseWinSetState($handle,"",@SW_DISABLE)EndifIfBitAnd($wnd_state,2)thenWinSetState($handle,"",@SW_SHOW)ElseWinSetState($handle,"",@SW_HIDE)EndifSelectcaseBitAnd($wnd_state,16)WinSetState($handle,"",@SW_MINIMIZE)caseBitAnd($wnd_state,32)WinSetState($handle,"",@SW_MAXIMIZE)EndSelectEndFunc;; An enhanced MouseClick that would do anything it can to click-that-buttonFunc MouseKick($wnd_handle=0,$x="XPOS",$y="YPOS",$aio_MouseCoordMode=0,$mouse_button="primary",$clicks=1,$speed=0)AutoItSetOption("MouseCoordMode",$aio_MouseCoordMode)Local$_app_state= WindowMakeActive ($wnd_handle)If(IsNumber($x)ANDIsNumber($y))thenMouseClick($mouse_button,$x,$y,$clicks,$speed)ElseLocal$pos=MouseGetPos()MouseClick($mouse_button,$pos[0],$pos[1],$clicks,$speed)Endif
WindowRestoreState ($wnd_handle,$_app_state)EndFuncFunc TouchHttpCGI($static_serverurl,$dynamic_dirurl,$static_fileurl,$dynamic_fileurl,$static_servparam,$local_path)Local$_url=$static_serverurl&$dynamic_dirurl&$static_fileurl&$dynamic_fileurl&$static_servparamDirCreate($local_path&"_stream_source\")InetGet($_url,$local_path&"_stream_source\"&$static_fileurl&$dynamic_fileurl&".asx")EndFuncFunc IsIntStr ($str_value);; This function is a work around for IsInt();; Return value: True when string contains only digitsReturn(($str_value>0)or($str_value==0)or($str_value<0))EndFuncFunc ReadMarker ($marker_path)Local$file=FileOpen($marker_path&"\_stream_source\download_marker.txt",0)If($file==-1)ThenReturn"NULL"EndifLocal$line=FileReadLine($file,1)FileClose($file)If(@error==1)OR(Not IsIntStr($line))thenReturn"NULL"ElseReturnInt($line)EndifEndFuncFunc WriteMarker ($marker_path,$marker_value)Local$file=FileOpen($marker_path&"\_stream_source\download_marker.txt",2)If($file==-1)ThenReturn"NULL"EndifFileWriteLine($file,$marker_value)FileClose($file)EndFunc;;;;;;;;;;;;; DATADim$StreamingSources[7];; StringFormat = "protocol://URI/static-name,TRAILING-ZEROS,FROM-COUNT,TO-COUNT,.extension"$StreamingSources[0]="mms://demo.domain.com/path/to_stream/FILEINITIAL-,2,1,27,.wmv";;;;;;;;;;;;; INITIALIZATIONAutoItSetOption("WinTitleMatchMode",4)AutoItSetOption("MouseCoordMode",0)AutoItSetOption("TrayIconDebug",1)Global$_wmr_winlist=WinList("classname=#32770")GlobalConst$ROOT_RECORDING_PATH="I:\place_to_store\videos\";;;;;;;;;;;;; START HELPER APPLICATIONS;; So, what am I doing here ? ;; If all checks for application parts return false: I'm assuming application is not launched.;; If all checks for application parts return true: I'm assuming application is launched and active;; If some parts return true and others say false: I'm assuming application is semi loaded, so lets reload itIf((SearchWindowByTitle($_wmr_winlist,"")==0)AND_(SearchWindowByTitle($_wmr_winlist,"WM Recorder - Windows Media")==0)AND_(SearchWindowByTitle($_wmr_winlist,"WM Recorder - Recording Window")==0))then;; Good, no memory resistent copies of application, launch itrun("C:\Program Files\WMR11\WMR11.exe")Elseif((SearchWindowByTitle($_wmr_winlist,"")<>0)AND_(SearchWindowByTitle($_wmr_winlist,"WM Recorder - Windows Media")<>0)AND_(SearchWindowByTitle($_wmr_winlist,"WM Recorder - Recording Window")<>0))then;; looks like the application is fully loaded, let it beElse;; If we got here that means part of the application is still in memory;; Kill all available parts and then reload.WinKill( SearchWindowByTitle($_wmr_winlist,""))WinKill( SearchWindowByTitle($_wmr_winlist,"WM Recorder - Windows Media"))WinKill( SearchWindowByTitle($_wmr_winlist,"WM Recorder - Recording Window"))ProcessClose("WMR11.exe")ProcessWaitClose("WMR11.exe")run("C:\Program Files\WMR11\WMR11.exe")endif;; Loop until splashscreen gone, which has the same classname and same text :(_delay_WaitForControl("classname=#32770","","Edit2");; Second run of WinList() to include changes occured after HELPER APPLICATION logic$_wmr_winlist=WinList("classname=#32770");;;;;;;;;;;;; RUN MAIN RECORDING LOOPifWinWait("classname=#32770")then$handle_mainwnd= SearchWindowByTitle($_wmr_winlist,"")For$indx=0toUBound($StreamingSources)-1$_strmInfo=StringSplit($StreamingSources[$indx],",")DirCreate($ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1]));; Do a quick marker check, maybe we can skip a few loops ;)$_marker_from= ReadMarker ($ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1]))if($_marker_from=="NULL")then$_marker_from=Number($_strmInfo[3])EndifFor$i=$_marker_fromtoNumber($_strmInfo[4]);; download from [number] to [how many there are]...$_strformat="%."&$_strmInfo[2]&"d"&$_strmInfo[5]$_waitdl_file= FileNameFromURI($_strmInfo[1])&StringFormat($_strformat,$i)$_waitdl_file_pattern= FileNameFromURI($_strmInfo[1])&StringFormat("%."&$_strmInfo[2]&"d*"&$_strmInfo[5],$i)_delay_WaitForControl($handle_mainwnd,"","Edit2")ControlSetText($handle_mainwnd,"","Edit2",$_waitdl_file)ControlSetText($handle_mainwnd,"",321,$_strmInfo[1]&StringFormat($_strformat,$i));; STATR: Folder change sequance for application
MouseKick($handle_mainwnd,250,50)_change_Folder_WMR11($ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1]));; END: Do folder change sequance;; Fool remote server into thinking IE is "doing him"$_server_cgi_root="http://demo.domain.com/path/to/video/STATIC?url/"
TouchHttpCGI($_server_cgi_root, RecordingPath($_strmInfo[1])&"/", FileNameFromURI($_strmInfo[1]),_StringFormat("%."&$_strmInfo[2]&"d",$i),"&mswmext=.asx",_$ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\");; Start recording (click the button)
MouseKick($handle_mainwnd,45,75)$_waitdl_ret= WaitDownload($handle_mainwnd,$_waitdl_file_pattern,$ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\")Selectcase$_waitdl_ret==(-1);; msgbox (1, "", "WaitDownload sayed -1 == application did nothing for Xms time");; OK, wait a couple of min and try again will'ya ;)$i=$i-1sleep(30000)case$_waitdl_ret==0; Download finished
WriteMarker ($ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1]),$i+1)sleep(600000)$_ondisk_media_files= FileFindToArray($_waitdl_file_pattern,$ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\")IfIsArray($_ondisk_media_files)thenfor$ifile=1toUBound($_ondisk_media_files)-1FileMove($ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\"&$_ondisk_media_files[$ifile],_$ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\"&_nixNOW()&"_"&$_ondisk_media_files[$ifile])NextFileMove($ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\"&$_ondisk_media_files[0],_$ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\"&$_waitdl_file)Endifcase$_waitdl_ret==(-2); A file in the requested download size has been identified on the hardisk
WriteMarker ($ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1]),$i+1)sleep(30000)$_ondisk_media_files= FileFindToArray($_waitdl_file_pattern,$ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\")IfIsArray($_ondisk_media_files)thenfor$ifile=1toUBound($_ondisk_media_files)-1FileMove($ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\"&$_ondisk_media_files[$ifile],_$ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\"&_nixNOW()&"_"&$_ondisk_media_files[$ifile])NextFileMove($ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\"&$_ondisk_media_files[0],_$ROOT_RECORDING_PATH& RecordingPath($_strmInfo[1])&"\"&$_waitdl_file)Endifcase$_waitdl_ret==(-4); msgbox (1, "", "WaitDownload sayed -4 == dude, your over your limits"); Fuck it, fuck him, fuck everyone. "If you don't want to be downloaded then I am surely not going to do it for you"$_foo="foo"caseelsemsgbox(1,"","WaitDownload sayed "&$_waitdl_ret&"(wtf?)")Endselect;; Helper application logic: End recording session before starting new one_close_Recording_Window_WMR11( SearchWindowByTitle($_wmr_winlist,"WM Recorder - Recording Window"))NextNextendif