[xiph-commits] r16523 - in trunk/ezstream: . examples
moritz at svn.xiph.org
moritz at svn.xiph.org
Fri Aug 28 08:55:14 PDT 2009
Author: moritz
Date: 2009-08-28 08:55:13 -0700 (Fri, 28 Aug 2009)
New Revision: 16523
Added:
trunk/ezstream/examples/playlist-logger.sh
Modified:
trunk/ezstream/NEWS
trunk/ezstream/examples/Makefile.am
trunk/ezstream/examples/meta.sh
trunk/ezstream/examples/play.sh
Log:
Add a more fancy playlist script.
Modified: trunk/ezstream/NEWS
===================================================================
--- trunk/ezstream/NEWS 2009-08-28 08:42:36 UTC (rev 16522)
+++ trunk/ezstream/NEWS 2009-08-28 15:55:13 UTC (rev 16523)
@@ -5,6 +5,8 @@
Failure to open a resource (e.g. a media file) is no longer fatal
and operation will continue as far as possible. Idea from dhorton.
(Ticket #1585)
+ * examples/:
+ - [NEW] Add a real-world example playlist script with logging feature.
Changes in 0.5.5, released on 2009-08-01:
Modified: trunk/ezstream/examples/Makefile.am
===================================================================
--- trunk/ezstream/examples/Makefile.am 2009-08-28 08:42:36 UTC (rev 16522)
+++ trunk/ezstream/examples/Makefile.am 2009-08-28 15:55:13 UTC (rev 16523)
@@ -6,6 +6,6 @@
ezstream_reencode_theora.xml ezstream_reencode_vorbis.xml \
ezstream_stdin_vorbis.xml ezstream_vorbis.xml \
ezstream_metadata.xml
-dist_examples_SCRIPTS = meta.sh play.sh
+dist_examples_SCRIPTS = meta.sh play.sh playlist-logger.sh
CLEANFILES = core *.core *~ .*~
Modified: trunk/ezstream/examples/meta.sh
===================================================================
--- trunk/ezstream/examples/meta.sh 2009-08-28 08:42:36 UTC (rev 16522)
+++ trunk/ezstream/examples/meta.sh 2009-08-28 15:55:13 UTC (rev 16523)
@@ -1,6 +1,7 @@
#!/bin/sh
-# Example metadata script that has the behavior required by ezstream.
+# Minimalist example metadata script that has the behavior required by
+# ezstream.
test -z "${1}" && echo "Ezstream presents"
test x"${1}" = "xartist" && echo "Great Artist"
Modified: trunk/ezstream/examples/play.sh
===================================================================
--- trunk/ezstream/examples/play.sh 2009-08-28 08:42:36 UTC (rev 16522)
+++ trunk/ezstream/examples/play.sh 2009-08-28 15:55:13 UTC (rev 16523)
@@ -1,5 +1,6 @@
#!/bin/sh
-# Example playlist script that has the behavior required by ezstream.
+# Minimalist example playlist script that has the behavior required by
+# ezstream.
echo "Great_Artist_-_Great_Song.ogg"
Added: trunk/ezstream/examples/playlist-logger.sh
===================================================================
--- trunk/ezstream/examples/playlist-logger.sh (rev 0)
+++ trunk/ezstream/examples/playlist-logger.sh 2009-08-28 15:55:13 UTC (rev 16523)
@@ -0,0 +1,123 @@
+#!/bin/sh
+
+# Example playlist script, by Moritz Grimm
+# Public Domain where available. Anywhere else: all possible permissions
+# are granted and all warranties whatsoever are disclaimed. Use at your
+# own risk.
+#
+# The script plays a simple playlist, but also logs when and which new
+# song is queued. Because it writes the entire playlist each time it is
+# run, the script will probably not perform well with huge (500+kB)
+# playlist files.
+#
+# Before using it, the configuration variables below should be adjusted
+# appropriately.
+#
+# When using this script in multiple instances of ezstream, use
+# different STATE_DIR locations or rename the script to a unique name.
+
+
+#########################
+## BEGIN CONFIGURATION #######################################################
+#########################
+
+
+# STATE_DIR
+# Directory where this script keeps state. The directory should only be
+# writeable by the user and nobody else (therefore, /tmp is not
+# suitable.)
+STATE_DIR="."
+
+# PLAYLIST
+# The playlist that should be played by this script.
+PLAYLIST="playlist.txt"
+
+# LOGFILE (optional)
+# File to log song changes to. If not set, logging to file is disabled
+# (and this script can be replaced by $PLAYLIST.)
+LOGFILE="ezstream.log"
+
+# REPEAT (optional)
+# Set to 1 to repeat the playlist indefinitely, set to 0 or leave commented
+# out to allow ezstream to determine what to do at end-of-playlist.
+#REPEAT=1
+
+
+#######################
+## END CONFIGURATION #########################################################
+#######################
+
+_myname="$(basename $0)"
+
+# Check configuration above:
+if [ -z "${STATE_DIR}" -o ! -d "${STATE_DIR}" ]; then
+ echo "${_myname}: STATE_DIR is not configured, does not exist or is not a directory." >&2
+ exit 1
+fi
+if [ -z "${PLAYLIST}" -o ! -e "${PLAYLIST}" ]; then
+ echo "${_myname}: PLAYLIST is not configured or does not exist." >&2
+ exit 1
+fi
+test -n "${REPEAT}" || REPEAT=0
+
+# Set up helper files:
+_state="${STATE_DIR}/${_myname}.state"
+_playlist="`mktemp "${STATE_DIR}/${_myname}.XXXXXXXXXX"`"
+if [ $? -ne 0 ]; then
+ echo "${_myname}: Unable to create temporary file." >&2
+ exit 1
+fi
+trap 'rm -f ${_playlist}' 0
+trap 'rm -f ${_playlist}; exit 1' 2 15
+
+# Strip comments and empty lines from PLAYLIST, to support .m3u:
+sed -e 's,#.*,,g' < ${PLAYLIST} | grep -v '^[[:space:]]*$' >> ${_playlist}
+if [ $? -ne 0 ]; then
+ echo "${_myname}: Unable to prepare playlist." >&2
+ exit 1
+fi
+
+# Create state file, if it does not exist:
+test -f "${_state}" || touch "${_state}"
+if [ $? -ne 0 ]; then
+ echo "${_myname}: Unable to create state file." >&2
+ exit 1
+fi
+
+# Read current track no. from state file:
+read _track_no < "${_state}"
+if [ -z "${_track_no}" ]; then
+ _track_no=1
+fi
+
+# Count number of tracks in the playlist:
+_num_tracks="$(wc -l < ${_playlist})"
+if [ ${_num_tracks} -eq 0 ]; then
+ # Nothing to do, really.
+ exit 0
+fi
+
+# Handle the end-of-playlist case:
+if [ ${_track_no} -gt ${_num_tracks} ]; then
+ if [ ${REPEAT} -ne 1 ]; then
+ # We're done.
+ rm -f "${_state}"
+ exit 0
+ fi
+ _track_no=1
+fi
+
+# Get the current track from the playlist:
+_track="$(head -n ${_track_no} ${_playlist} | tail -n 1)"
+
+# Output:
+echo "${_track}"
+test -z "${LOGFILE}" || \
+ echo "$(date '+%b %d %H:%M:%S') playlist=\"${PLAYLIST}\" no=${_track_no} track=\"${_track}\"" \
+ >> "${LOGFILE}"
+
+# Increment track number and store:
+: $((_track_no += 1))
+echo "${_track_no}" > "${_state}"
+
+exit 0
Property changes on: trunk/ezstream/examples/playlist-logger.sh
___________________________________________________________________
Added: svn:executable
+ *
More information about the commits
mailing list