Jump to content

Mplayer script


Skins
 Share

Recommended Posts

A script I Have just written to replace the one line batch file 'commented on the first line' that I had to change manually each time i used it.

Basically I needed to save streaming lectures of my unis media server so I could seek within them and things.

I was using the batch in conjunction with the firefox addon 'mediaplayerconnecticity' which gets media files urls and launches external media apps.

It should now feed my script a files url as a command line argument.

not sure if it's been done before.

Can anyone see any glaring flaws in this code? things that could be done better, smother?

Do i really need to define the working directory? (after first , in Run) I think mplayer needs a working dir to dump the file into but is this coming from this value?

is there one value for a 'can't use theses characters in a file name' array?

also it was launching mplayer recursively an i didn't figure out why i just changed something and it stopped, is this script terminating properly?

;START "whut" /D"Q:\Program Files\MPlayer for Windows\" mplayer.exe %1 -dumpstream -dumpfile week05b.wmv -batch to replace
Dim $ConfigFile
$ConfigFile = _GetConfigFile("mpdump.ini",false) ;read config file
$mplayerpath = IniRead($ConfigFile,"PATH","Dir","c:\Program Files\MPlayer for Windows\")
$playlist = IniRead($ConfigFile,"PLAYLIST","Flag","0")


dim $input1 = $CmdLineRaw ;getting output dump file name from last bit of url
dim $lasts = StringInStr($input1, "/", 0, -1) ; Find the last occurance of "/"
if $lasts = 0 Then
    $lasts = StringInStr($input1, "\", 0, -1) ; Find the last occurance of "\"
EndIf
Dim $tname = StringTrimLeft($CmdLineRaw, $lasts) ;clipping url
$tname = StringTrimRight($tname, 1) ;removing last "
dim $fname = StringRegExpReplace($tname, '[/\\|:?<>"*\s]', "_") ;replacing unsaveable characters with _
; Debugging notes
;MsgBox(0, "cmdline:", $input1)
;MsgBox(0, "slash:", $lasts)
;MsgBox(0, "name", $fname)
;
;If $playlist = 0 Then
;       MsgBox(0, $mplayerpath, "mplayer.exe " & $CmdLineRaw & " -dumpstream -dumpfile " & $fname)
;   Else
;       MsgBox(0, $mplayerpath, "mplayer.exe -playlist " & $CmdLineRaw & " -dumpstream -dumpfile " & $fname)
;EndIf
    
If $playlist = 0 Then ;running mplayer
        Run($mplayerpath & "mplayer.exe " & $CmdLineRaw & " -dumpstream -dumpfile " & $fname, $mplayerpath)
    Else
        Run($mplayerpath & "mplayer.exe -playlist " & $CmdLineRaw & " -dumpstream -dumpfile " & $fname, $mplayerpath) ; with playlist flag
    EndIf
Exit    

Func _GetConfigFile($filename, $silent = False) ;define config file
    Local $configfilename
    $configfilename = @ScriptDir & "\" & $filename
    If Not FileExists($configfilename) Then
        If Not $silent Then
            MsgBox(64, "File Missing", "The file " & $filename & " is not available." & @CRLF & "Please ensure that it is located in the " & @ScriptDir & " directory." & @CRLF & @CRLF & "The application will now Run with Default values." & @CRLF & "dir=C:\Program Files\MPlayer for Windows\ and no playlist flag" & @CRLF & @CRLF & "ini file should look like" & @CRLF & "---" & @CRLF & "[PATH]" & @CRLF & ";Mplayer Working Directory" & @CRLF & "Dir=c:\Program Files\MPlayer for Windows\" & @CRLF & @CRLF & "[PLAYLIST]" & @CRLF & ";Toggle -playlist flag" & @CRLF & "Flag=1" & @CRLF)
        EndIf
        SetError(1)
        Return "Error"
    EndIf
    Return $configfilename
EndFunc   ;==>_GetConfigFile

with ini file mpdump.ini

[PATH]
;Mplayer Working Directory
Dir=Q:\Program Files\MPlayer for Windows\

[PLAYLIST]
;Toggle -playlist flag
Flag=0
Link to comment
Share on other sites

Ok I have added

dim $lastq = StringInStr($tname, '"', 0, -1)
if $lastq <> 0 Then
    $tname = StringTrimRight($tname, 1) ;removing last "
EndIf

Because I was testing this with a drag and drop of a file onto the script and my command lines were wrapped in "s however urls do not come with "s and i was losing the last char of my file extensions.

&*bump* -wow this forum gets a lot topics through.

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