From 353058148c76c17a424ff6ba98467d10785a8a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Sat, 25 Sep 2010 01:20:26 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9mon=20mplayer,=20commande=20=C3=A0=20dis?= =?UTF-8?q?tance=20pour=20la=20lecture,=20filtrage=20de=20l'info=20"titre"?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config | 7 +++++++ mplayerd | 21 +++++++++++++++++++++ mplayerd-getinfo | 28 ++++++++++++++++++++++++++++ mplayerd-play | 5 +++++ 4 files changed, 61 insertions(+) create mode 100644 config create mode 100755 mplayerd create mode 100755 mplayerd-getinfo create mode 100755 mplayerd-play diff --git a/config b/config new file mode 100644 index 0000000..9ccd62f --- /dev/null +++ b/config @@ -0,0 +1,7 @@ +#!/bin/bash + +V="-8" +MP_CONTROL="/dev/shm/mplayer-contol$V" +MP_OUTPUT="/dev/shm/mplayer-output$V" +MP_PID="/dev/shm/mplayer-pid$V" +MP_ERROR="/tmp/mplayer-errors.log" diff --git a/mplayerd b/mplayerd new file mode 100755 index 0000000..5883004 --- /dev/null +++ b/mplayerd @@ -0,0 +1,21 @@ +#!/bin/bash + +source "$(dirname "$0")/config" + +if [ "$1" == "stop" ]; then + if [ -e /dev/shm/mplayer-pid ]; then + if ! kill "$(<"$MP_PID")"; then + echo "Failed to kill mplayer" + exit 2 + fi + else + echo "Can't find $MP_PID ." + exit 3 + fi +else + [ -p "$MP_CONTROL" ] || mkfifo "$MP_CONTROL" + [ -p "$MP_OUTPUT" ] || mkfifo "$MP_OUTPUT" + + mplayer -quiet -slave -input file="$MP_CONTROL" -idle > "$MP_OUTPUT" 2> "$MP_ERROR" & + echo "$!" > /dev/shm/mplayer-pid +fi diff --git a/mplayerd-getinfo b/mplayerd-getinfo new file mode 100755 index 0000000..9a08812 --- /dev/null +++ b/mplayerd-getinfo @@ -0,0 +1,28 @@ +#!/bin/bash + +source "$(dirname "$0")/config" + +q="'" + +old_titre="" + +cat "$MP_OUTPUT" \ +| while read ligne; do + # TODO : utiliser grep n'est pas du tout efficace ! + if grep -q "^[a-zA-Z_][a-zA-Z0-9_]*='"<<<"$ligne"; then + cle="${ligne%%=$q*}" + valeur="${ligne#*=$q}" + valeur="${valeur%$q}" + case "$cle" in + ANS_META_TITLE) + old_titre="$titre" + titre="$valeur" + if [ "$titre" != "$old_titre" ]; then + echo "TITRE = $titre" + fi + ;; + esac + else + (echo "get_meta_title" > "$MP_CONTROL") & + fi +done diff --git a/mplayerd-play b/mplayerd-play new file mode 100755 index 0000000..cfed186 --- /dev/null +++ b/mplayerd-play @@ -0,0 +1,5 @@ +#!/bin/bash + +source "$(dirname "$0")/config" + +echo "loadfile '$(readlink -f "$1")' 0" > "$MP_CONTROL"