mirror of
https://gitlab.xiph.org/xiph/ezstream.git
synced 2024-12-04 14:46:31 -05:00
Add a more fancy playlist script.
git-svn-id: https://svn.xiph.org/trunk/ezstream@16523 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
parent
cae7e0029a
commit
ca4060f94c
2
NEWS
2
NEWS
@ -5,6 +5,8 @@ Changes in 0.5.6, released on XXXX-XX-XX:
|
||||
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:
|
||||
|
@ -6,6 +6,6 @@ dist_examples_DATA = \
|
||||
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 *~ .*~
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
123
examples/playlist-logger.sh
Executable file
123
examples/playlist-logger.sh
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user