LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Passing some mplayer options to smplayer from a script

Posted 12-18-2014 at 12:56 PM by the dsc
Updated 12-28-2014 at 06:22 PM by the dsc (fixing the method)

PS/edit.: renamed the title as it's really something that makes more sense from within scripts, not from the command line itself. Unless perhaps one makes a wrapper script that edits smplayer.ini with whatever parameters are set by command line and resets afterwards, while still somehow preserving smplayer's own syntax, if that's even possible.


Major edit:

Apparently the best way to go is to dinamically edit or switch/rename the smplayer.ini file, in the following line:

Code:
mplayer_additional_options=--ss=<seconds> -af scaletempo -speed <speed>
It probably requires that the options aren't set elsewhere in the GUI's settings.



The the original post remains below, just in case there's still something useful.

PS.: the time "grepping" can be better achieved with:

Code:
greptime=$(mpc | grep "playing" | grep  % | awk '{print $3}' | sed 's|/.*||')

mintosec=$(echo $greptime | awk -F':' '{if (NF == 2) {print $1 * 60 + $2} else {print $1 * 60 * 60 + $2 * 60 + $3}}' )
This awk black-magic line (I saw on stackoverflow or something) converts any "clock" format in seconds, regardless of there being hours or just minutes ("mintosec" is a misnomer then, it's still there just due to laziness).

And it's useless with this line, but it's perhaps worth mentioning that the "editing" of the time would be somewhat more nicely done not only at the very least having both sed expressions in a single sed command, with 's/a/b/;s/c/d/', but even ditching sed altogether:

Code:
min=${greptime/:*/}

sec=${greptime/*:/}

But as I've said before, the awk line solves it much more efficiently.


------------------------------------------------


Smplayer apparently doesn't have full "command line compatibility" with mplayer (I think it should have something like "--mplayercommands"), you'd have to go to the GUI's options and set permanent options for mplayer there, which won't always be the ideal for command line scriptery.

But as it's often the case with many things in life, it can be fixed with some ugly hack.

Basically you change the mplayer executable to a script, which in turn can have the options you want changed in some way you conceive.


For example, I have MPC playing podcasts, but sometimes it benefits from gui control and playing at a faster tempo, which (s)mplayer can do. In order to have my mpc script pass the current track and time to smplayer I have the mplayer executable as this script:

Code:
mplayer $(cat /dev/shm/mplayer-options) $@
Saved as "mplayersh", set as executable, located in the user's $PATH.

The mplayer-options file is previously generated by my mpc script, in the following lines:

Code:
num="$(mpc | grep '#' | sed 's|.*#|(|g' | sed 's|/.*|)|g')" 
vlctrack="$(mpc playlist -f "[+-+(%position%)-++%file%]" | grep "^+-+$num" |  head -n 1 | sed 's|.*)-++||' )"

greptime=$(mpc | grep "playing" | grep  % | awk '{print $3}' | sed 's|/.*||')
min=$(echo $greptime | sed 's|:.*||' | sed 's/^0*//')
sec=$(echo $greptime | sed 's|.*:||' | sed 's/^0*//')

mintosec=$((min*60))
sttime=$((mintosec+sec-5))

echo " --ss=$sttime -af scaletempo -speed 1.35" > /dev/shm/mplayer-options

mpc stop

smplayer -close-at-end -mpcgui "/home/$USER/music/$vlctrack" && mpc next

rm /dev/shm/mplayer-options
"-mpcgui" is not required at all, it's just the GUI I prefer.


EDIT: I don't think it works very well, I've tried some changes to fix something but it isn't quite working, I guess.
Posted in Uncategorized
Views 1815 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 12:46 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration