Jump to content

VCR type program to record live video streams.


rush4hire
 Share

Recommended Posts

Summary:

This is to control a media stream recorder called SDP Multimedia found at http://sdp.ppona.com/

GUI shot:

Posted Image

Well this one is made for the stream at 3abn.org, but you can adapt it for maniatv.com or some internet tv channel, or radio station.

Features include (at random):

- renames the files that are saved

- a few nifty doodads

- downloads and parses a program guide to give a list of programs to select.

- keeps the SDP program connected

- saves / loads settings

- plenty of comments in the code

Credits:

Thank you Jon and AutoIt moderators and helpful people here. I'm so happy when I can make neat stuff with this easy to use system!

Apology:

This is the very first release, so it might be messy or w/e.

I just made this in the last couple days. I will probably add and fix stuff.

This is the first night to test this. There are probably still bugs.

;sdp vcr v 1.00
;todo 
; open 3abn sched page for new users
; highlight in gui where we are
; mark what has been recorded
; indicate what is currently and / or next to record
; turn off red light if current show is unchecked . and rename the file 
FileInstall('sdp_vcr_readme.txt','sdp_vcr_readme.txt')

Global $readmetext = "v 1.00 beta"&@CRLF& _
""&@CRLF& _
"I just started this project, so it only records from 3abn.org and"&@CRLF& _
" there are some things to do to set it up."&@CRLF& _
""&@CRLF& _
"1. dl and install SDP if you don't have it. Get it at http://sdp.ppona.com/"&@CRLF& _
""&@CRLF& _
"2. Start the program and hit Open, and inter this url"&@CRLF& _
" http://mfile.akamai.com/22774/live/reflector:52608.asx?prop=n"&@CRLF& _
""&@CRLF& _
"3. Go to this page: http://www.3abn.org/broadcast_schedule.cfm "&@CRLF& _
"and set your timezone so it will give you the right timestamps"&@CRLF& _
""&@CRLF& _
"That's all I can think of."&@CRLF& _
""&@CRLF& _
""&@CRLF& _
""
If Not FileExists('sdp_vcr_readme.txt') Then FileWrite('sdp_vcr_readme.txt',$readmetext)

Global $url = "http://www.3abn.org/broadcast_schedule.cfm"
Global Const $DEFCOL = 0xECE9D8
Global $fso = ObjCreate("Scripting.FileSystemObject")

Global $start_year = @YEAR
Global $start_mon = @MON
Global $start_mday = @MDAY
Global $time

Global $ISRECORDING = False
Global $STAY_CONNECT_MODE = 0

Global $lasttime = 0
Global $cshow = 0
Global $nextrec
Global $nextend

Global $recmsg1 = "-- Not Recording --"
Global $recmsg2 = " Recording "
Global $ampm[2] = ["AM","PM"]
Global $dots

Global $GUIw = 560
Global $GUIh = 590
; data structure
; 0 time start
; 1 computer time start
; 2 computer time end
; 3 title
; 4 subject - host
; 5 checked to record or Not
; 6 id
;$sched[$ii][1]

;@@@@@@@@@@@@@@@@@@@
;@@     INTRO     @@
;@@@@@@@@@@@@@@@@@@@

Func gettime()
 $time = Number(@YEAR & @MON & @MDAY & @HOUR & @MIN)
EndFunc
gettime()


;~  Parse program schedule page and load up our data structure
Func sortpage()
$oldsettings = FileRead("sdpsettings.txt")
    
If fileistooold() Then InetGet($url, "broadcast_schedule.htm")
$text = FileRead("broadcast_schedule.htm")
$bigarr = StringSplit ($text, '<td width="120" align="right" bgcolor="#EEEEEE"><span class="BlueBoldMedium"> ', 1)
$text = ""
$o=""
Global $sched[$bigarr[0]+1][7]

For $i = 2 to $bigarr[0]
    $t = $bigarr[$i]
    $ii = $i - 2
    ; 0 time
    $arr = StringSplit($t, "</span>")
    $sched[$ii][0] = $arr[1]
;~  ; 1 converted Time
    $ctime = converttime($arr[1])
    $tno = Number($ctime)
    ; Here is where the date might change. at midnight.
    If $tno < $lasttime Then advanceoneday()
    $lasttime = $tno
    $ctime = Number($start_year & $start_mon & $start_mday & $ctime)
    $sched[$ii][1] = $ctime
;~  ; 2 time to stop 
    If $ii > 0 Then
        $sched[$ii-1][2] = $ctime
    EndIf
;~  ; 3 show title
    If $i == $bigarr[0] Then
        $sched[$ii-1][0] = $sched[$ii-1][0] &" - "& $arr[1]
        ExitLoop
    EndIf
    $sched[$ii][3] = _StringExtract ($t, '<td width="217" class="GreyMedium">', '</td>')
;~  ; 4 show subject and host
    $subject = _StringExtract ($t, '<span class="BlackBoldSmall">', '</span>', 1)
    $sched[$ii][4] = StringReplace(StringReplace(StringReplace(StringReplace($subject, @CRLF, ""), "/", "-by- "), "*", ""), "  ", "")
;~  ; 5 checked or not
    $sched[$ii][5] = Iif(StringInStr($oldsettings,String($sched[$ii][1])),1,0)
;~  ; 6 control ID
    $sched[$ii][6] = 0
Next

;;; deal with last endtime which we don't have available. we'll make it 1 hour later
; wait, let's just sacrifice the last program and just use the start time as our last end time ..
;~ $tno = $lasttime + 100
;~ If $tno >= 2400 Then
;~  $tno -= 2400
;~  advanceoneday()
;~ EndIf
;~ $ctime = String($tno)
;~ $ctime = StringMid ( "000" & $ctime, StringLen($ctime) )
;~ $sched[$ub][2] = $start_year & $start_mon & $start_mday & $ctime
;;; done with last endtime
;~ $numentries = $ub
;~ FileWrite ("testpage.txt", $text)

EndFunc
sortpage()
; This will advance our date of the schedule by one day

;@@@@@@@@@@@@@@@@@@@@
;@@ CONVERSION ETC @@
;@@@@@@@@@@@@@@@@@@@@


; only used when our time thing hits midnight when creating dates
; in the schedule
Func advanceoneday()
    $d = Number($start_mday)
    $m = Number($start_mon)
    $iNumDays = StringSplit('31,28,31,30,31,30,31,31,30,31,30,31', ',')
    $maxdays = Number( $iNumDays[$m] )
    If $m == 2 Then $maxdays += _DateIsLeapYear($start_year)
    If $d < $maxdays Then
        $d += 1
        If $d > 9 Then
            $start_mday = String($d)
        Else
            $start_mday = "0" & String($d)
        EndIf
        Return 1
    EndIf
    ; New month
    $start_mday = "01"
    $m += 1
    If $m > 12 Then
      $start_mon = "01"
      $start_year = String(Number($start_year)+1)
    ElseIf $m > 9 Then
      $start_mon = String($m)
    Else
      $start_mon = "0" & String($m)
    EndIf
EndFunc

;If _DateIsLeapYear($asDatePart[1]) Then $iNumDays[2] = 29
; takes string from between 2 strings 
Func _StringExtract ($string, $start, $end, $trim = 0)
    $temp = StringSplit( $string, $start, 1)
    If $temp[0] == 1 Then Return ''
    $temp = StringSplit($temp[2], $end, 1)
    If $temp[0] == 1 Then Return ''
    If $trim Then Return StringStripWS($temp[1], 3)
    Return $temp[1]
EndFunc

; if file last modified time + x hours is less than now, then it IS too old
; and needs to be updated fromt he web site
Func fileistooold($f = "broadcast_schedule.htm", $h = 1)
    If Not FileExists($f) Then Return 1
$filetime = Number (FileGetTime ($f, 0, 1))
$thistime = Number (@YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC)
Return Iif($filetime+(10000*$h) < $thistime, 1,0)
EndFunc


; converts normal timestamp to a simple number which would be equal to @HOUR & @MIN in string format too!
Func converttime($time)
    $arr = StringSplit($time, ":")
    $h = $arr[1]
    $m = StringSplit($arr[2]," ")
    ; fix hour
    If $m[2] = "PM" Then
        If $h <> "12" Then $h = String(Number($h)+12)
    ElseIf number($h) < 10 Then
        $h = "0" & $h
    ElseIf $h = "12" Then
        $h = "00"
    EndIf
    Return $h & $m[1]
EndFunc

Func Iif($x,$y,$z)
    If $x Then
        Return $y
    Else
        Return $z
    EndIf
EndFunc

Func _WriteText($filepath, $text)
$f = $fso.OpenTextFile($filepath,2,True)
$f.Write($text)
$f.Close
EndFunc


Func _DateIsLeapYear($iYear)
    If StringIsInt($iYear) Then
        Select
            Case Mod($iYear, 4) = 0 And Mod($iYear, 100) <> 0
                Return 1
            Case Mod($iYear, 400) = 0
                Return 1
            Case Else
                Return 0
        EndSelect
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc


;@@@@@@@@@@@@@@@@@@@
;@@ GUI FUNCS ETC @@
;@@@@@@@@@@@@@@@@@@@

Func pushbut ($e)
    ControlSend ( "SDP Multimedia", "", "TToolBar1", "!"&$e )
EndFunc

Func IsDisconnected()
    Return StringRight(ControlGetText ( "SDP Multimedia", "", "TRichEdit1" ), 14) == "Disconnected"&@CRLF
EndFunc

; data structure
; 0 time start
; 1 computer time start
; 2 computer time end
; 3 title
; 4 subject - host
; 5 checked to record or Not
; 6 id
;$sched[$ii][1]

Func NextRecordTime()
For $i = 0 to Ubound($sched)-1
    If $sched[$i][5] Then
        If $sched[$i][2] > $time Then
            $cshow = $i
            $nextrec = $sched[$i][1]
            $nextend = $sched[$i][2]
            Return
        EndIf
    EndIf
Next
$cshow = 99
$nextrec = 210000000000
$nextend = 210000000000
EndFunc

Func RenameFile()
$path = _StringExtract (ControlGetText ( "SDP Multimedia", "", "TRichEdit1" ), "> SAVE :    ", @CRLF)
If $path == '' Then Return 0
$newname = $sched[$cshow][3] &' -- '& $sched[$cshow][4] & ".asf"
$f = $fso.GetFile($path)
$f.Name = $newname
EndFunc


Global $colors[4] = [$DEFCOL,0xfffceb,0x00ff00,0x999966]
; when shows are checked and unchecked...
Func checkshow()
    $id = @GUI_CTRLID
    $x = Iif(GUICtrlRead ($id) == 1,1,0)
For $i = 0 to UBound($sched)-1
    If $sched[$i][6] == $id Then
        $sched[$i][5] = $x
        ExitLoop
    EndIf
Next
If $x Then
    GUICtrlSetBkColor ( $id, $colors[2] )
Else
    GUICtrlSetBkColor ( $id, $colors[mod($i,2)==0] )
EndIf
NextRecordTime()
EndFunc

;~ When stayConnected mode is checked / unchecked
Func togglecmode()
    $STAY_CONNECT_MODE = Iif(GUICtrlRead ($GUI_STAY_CONNECT_MODE) == 1,1,0)
    GUICtrlSetBkColor($GUI_STAY_CONNECT_MODE, Iif($STAY_CONNECT_MODE,0xff0000,$DEFCOL))
EndFunc

;~ When we close the gui
Func CLOSEClicked ()
    $o = ","
    For $i = $cshow to UBound($sched)-1
        If $sched[$i][5] Then
            If $sched[$i][2] > $time Then
                $o &= $sched[$i][1] & ','
            EndIf
        EndIf
    Next
    _WriteText("sdpsettings.txt", $o)
Exit
EndFunc

Global Const $GUI_EVENT_CLOSE           = -3
Global Const $GUI_EVENT_MINIMIZE        = -4
Global Const $GUI_EVENT_RESTORE         = -5
Global Const $GUI_EVENT_MAXIMIZE        = -6
Global Const $GUI_EVENT_PRIMARYDOWN     = -7
Global Const $GUI_EVENT_PRIMARYUP       = -8
Global Const $GUI_EVENT_SECONDARYDOWN   = -9
Global Const $GUI_EVENT_SECONDARYUP     = -10
Global Const $GUI_EVENT_MOUSEMOVE       = -11
Global Const $GUI_EVENT_RESIZED         = -12
Global Const $GUI_EVENT_DROPPED         = -13

Global Const $GUI_SHOW          = 16
Global Const $GUI_HIDE          = 32
Global Const $GUI_ENABLE        = 64
Global Const $GUI_DISABLE       = 128
Global Const $GUI_FOCUS         = 256
Global Const $GUI_DEFBUTTON     = 512


;~ Creating the GUI
Opt("GUICoordMode", 0)
Opt("GUIOnEventMode", 1)
$gui = GUICreate ( "SDP VCR", $GUIw, $GUIh, -1, -1, 0x00040000 + 0x00010000 + 0x00020000 )
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")


Func makeitems()
    $tw = $GUIw-20
    $mid = $GUIw/2-60
    Global $GUI_status = GUICtrlCreateLabel ( $recmsg1, $mid, 14, 120, 20, 0x01+0x1000 )
    GUICtrlCreateLabel ( "Shows for 3abn.org", -$mid+10, 0, 100, 20 )
    $add = 5
For $i = 0 to UBound($sched)-1
;StringMid("            ", StringLen($sched[$i][0])-6)
    If $sched[$i][3] == "" Then ExitLoop
    $x = GUICtrlCreateCheckbox ($sched[$i][0] & "    " & $sched[$i][3] &" -- "& $sched[$i][4], 0, 20+$add, $tw, 20 )
    $add = 0
    GUICtrlSetOnEvent($x, "checkshow")
    $sched[$i][6] = $x
    If $sched[$i][5] == 1 Then
        GUICtrlSetState ( -1, 1 )
        GUICtrlSetBkColor ( -1, $colors[2] )
    Else
        GUICtrlSetBkColor ( -1, $colors[mod($i,2)==0] )
    EndIf
;~  GUICtrlSetTip ( -1, $x )
Next

    Global $guitime = GUICtrlCreateLabel ( getguitime(), 0, 50 )

    Global $GUI_STAY_CONNECT_MODE = GUICtrlCreateCheckbox("StayConnected Mode",$tw-300, 0)
    GUICtrlSetOnEvent(-1, "togglecmode")
    GUICtrlSetTip(-1, "Use this when you ONLY want this program to keep your SDP connected.")

;~ GUICtrlCreateLabel ( "text", left, top [, width [, height [, style [, exStyle]]]] )
NextRecordTime()
EndFunc
makeitems()

Func getguitime()
    If $ISRECORDING Then
        $t=StringLeft("- - - -",$dots)
        GUICtrlSetData ($GUI_status, $t & $recmsg2 & $t )
        $dots += 2
        If $dots > 7 Then $dots = 1
    EndIf
$h = Number(@HOUR)
$x = 0
If $h > 12 Then
    $h-=12
    $x = 1
ElseIf $h == 0 Then
    $h = 12
EndIf
Return $h &":"& @MIN &":"& @SEC &" "& $ampm[$x]
EndFunc

GUISetState()

While 1
    Sleep (1000)
    GUICtrlSetData ($guitime, getguitime())
    Sleep (1000)
    GUICtrlSetData ($guitime, getguitime())
    Sleep (1000)
    GUICtrlSetData ($guitime, getguitime())
    If $STAY_CONNECT_MODE Then
        If IsDisconnected() Then pushbut ("b")
        ContinueLoop
    EndIf
    gettime()
    If $ISRECORDING Then
        If $time >= $nextend Then
            pushbut ("a")
            $ISRECORDING = False
            GUICtrlSetData ($GUI_status, $recmsg1)
            GUICtrlSetBkColor ($GUI_status, $DEFCOL)
            sleep(5000)
            RenameFile()
            NextRecordTime()
;~      See if we got disconnected!
        ElseIf IsDisconnected() Then
            pushbut ("b")
        EndIf
    Else
        If $time >= $nextrec Then
            pushbut ("b")
            $ISRECORDING = True
            GUICtrlSetData ($GUI_status, $recmsg2)
            GUICtrlSetBkColor ($GUI_status, 0xFF0000)
        EndIf
    EndIf
WEnd
Link to comment
Share on other sites

  • 1 year later...

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...