I am a linux user (PcLinuxOs desktop 64bit kde5). I am looking for a script (bash or python) to autopause clementine (a music player) on skype call. VLC works: autopause on skype call and at the end resume). Clementine automute, but not autopause, on skype call.
I am absolute beginner with the scripts, so I need your help.
Bash comman to pause clementine is "clementine --pause", but witch command for "if" or "when" or "while"?
I believe that under Skype settings -> Notifications you can execute a script on a number of events, why not create a script to do clementine --pause under the incoming call Notification:
Your help solved the bulk of the problem, but remain some things to perfect, i.e. how don't start clementine if before the skype call was stopped. How i.e. resume only if paused and not if stopped.
Now I put this script after the call:
#!/bin/bash
if pgrep -x "clementine" > /dev/null
then
clementine --play
fi
Could you help me (another bash script)?
Tried with fg, but don't works.
Oh, you want it to do nothing if the music is stopped. OK. You'll need to ask clementine whether it's paused or not somehow. That's not something pgrep or fg can tell you, since clementine isn't actually "stopped" in a program sense, just a "not playing" sense.
Does clementine show any status information? I don't have any way to test it on this end.
Oh, that digs deep into /proc/ to figure out if clementine has an audio device open. If they're going to those desperate lengths, then no, Clementine does not print status information. But maybe we can work with that.
PID=$(pgrep -x "clementine")
[ -z "$PID" ] && exit # Skip if Clementine's not running
if ls -l /proc/$PID/fd | egrep -q 'audio|video'
then
# clementine is playing or paused
clementine -t
fi
This depends on the names of the device files though. If you could show what ls -l /proc/clementinepid/fd/ really looks like during playback, during pause, and when stopped, that would help.
#!/bin/bash
#Written by Matthew Headlee 20170208
#Send all output to null, comment out for debugging.
exec &> /dev/null
#Function eClementineGetState() checks current state of media playback
#returns 0 if media is playing, 1 if paused, 2 if stopped, 3 if not running
eClementineGetState() {
iClemPID=$(pgrep -x clementine)
if [ ! -z "${iClemPID}" ]; then
for sFileDes in $(find /proc/${iClemPID}/fd -type l); do
if file -bi "$(readlink -f ${sFileDes})" | awk '!/video|audio/ {exit 1}'; then
#echo "Playing or Paused."
echo "Media File Handle is ${sFileDes}"
sFileDesInfo="/proc/${iClemPID}/fdinfo/$(basename ${sFileDes})"
iFilePosA=$(awk '/pos:/ {print $2}' "${sFileDesInfo}")
sleep .1
iFilePosB=$(awk '/pos:/ {print $2}' "${sFileDesInfo}")
if [ "${iFilePosA}" -ne "${iFilePosB}" ]; then
echo "Playing."
return 0
fi
echo "Paused."
return 1
fi
done
echo "Stopped."
return 2
fi
echo "Media Player Not Found."
return 3
}
eClementineGetState
[ "${?}" -eq 1 ] && clementine --play
Clementine resume the music only if before paused.