From d3151cd65a8801ce9e285e1b8fd8710917d0a7bd Mon Sep 17 00:00:00 2001 From: moritz Date: Sun, 30 Aug 2009 12:49:06 +0000 Subject: [PATCH] Add new wrapper/convenience script ezstream-file.sh -- generates ezstreams on- the-fly. git-svn-id: https://svn.xiph.org/trunk/ezstream@16529 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- NEWS | 6 + configure.in | 3 + doc/Makefile.am | 14 ++- doc/ezstream-file.sh.1.in.in | 110 ++++++++++++++++++ doc/{ezstream.1.in => ezstream.1.in.in} | 6 +- src/Makefile.am | 1 + src/ezstream-file.sh.in | 145 ++++++++++++++++++++++++ 7 files changed, 277 insertions(+), 8 deletions(-) create mode 100644 doc/ezstream-file.sh.1.in.in rename doc/{ezstream.1.in => ezstream.1.in.in} (99%) create mode 100644 src/ezstream-file.sh.in diff --git a/NEWS b/NEWS index bc885ca..635caff 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,11 @@ Changes in 0.5.6, released on XXXX-XX-XX: + * ezstream-file.sh: + - [NEW] Add and install ezstream-file.sh, a new convenience shell script + that generates configuration and playlist from a template and + command line, respectively. (Bourne shell and POSIX utilities + required.) + See ezstream-file.sh(1) for details. * src/ezstream.c: - [MISC] Be more tolerant towards faulty playlists and similar issues. Failure to open a resource (e.g. a media file) is no longer fatal diff --git a/configure.in b/configure.in index 196268d..2350679 100644 --- a/configure.in +++ b/configure.in @@ -281,9 +281,12 @@ AC_CONFIG_FILES([ compat/Makefile compat/sys/Makefile doc/Makefile + doc/ezstream-file.sh.1.in + doc/ezstream.1.in examples/Makefile m4/Makefile src/Makefile + src/ezstream-file.sh win32/Makefile win32/shout/Makefile ]) diff --git a/doc/Makefile.am b/doc/Makefile.am index 050de65..5c32973 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,14 +1,16 @@ AUTOMAKE_OPTIONS = 1.9 foreign -man_MANS = ezstream.1 - -EXTRA_DIST = ezstream.1.in +man_MANS = ezstream.1 ezstream-file.sh.1 do_subst = sed \ - -e 's|!!EXAMPLES_DIR!!|@EXAMPLES_DIR@|g' \ - -e 's|!!BUILD_DATE!!|@BUILD_DATE@|g' + -e 's|!!EXAMPLES_DIR!!|@EXAMPLES_DIR@|g' + +.PHONY: $(man_MANS) ezstream.1: ezstream.1.in Makefile - $(do_subst) < $(srcdir)/ezstream.1.in > ezstream.1 + $(do_subst) < $(builddir)/ezstream.1.in > ezstream.1 + +ezstream-file.sh.1: ezstream-file.sh.1.in Makefile + $(do_subst) < $(builddir)/ezstream-file.sh.1.in > ezstream-file.sh.1 CLEANFILES = *~ *.core core $(man_MANS) diff --git a/doc/ezstream-file.sh.1.in.in b/doc/ezstream-file.sh.1.in.in new file mode 100644 index 0000000..0168d8b --- /dev/null +++ b/doc/ezstream-file.sh.1.in.in @@ -0,0 +1,110 @@ +.\" $Id$ +.\" +.\" Copyright (c) 2009 Moritz Grimm +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd @BUILD_DATE@ +.Dt EZSTREAM-FILE.SH 1 +.Os @PACKAGE_NAME@ @PACKAGE_VERSION@ +.Sh NAME +.Nm ezstream-file.sh +.Nd convenience script to stream files from the command line +.Sh SYNOPSIS +.Nm +.Bk -words +.Op Fl hnqVv +.Op Fl T Ar cfg_template +.Op Ar +.Ek +.Sh DESCRIPTION +The +.Nm +script uses an +.Nm ezstream +configuration file template to stream a list of files given on the command +line, or via standard input. +In other words, filenames are written to a temporary playlist, and a +template-based configuration is generated to stream them. +.Pp +The path to a configuration template must be provided, either by using the +.Fl T +command line argument, or the +.Dv EZSTREAM_TEMPLATE +environment variable. +.Pp +The configuration template must be a valid playlist configuration, and contain +the follwing configuration statement: +.Bd -literal -offset indent +\&%FILENAME%\& +.Ed +.Pp +If no input files are specified, the list of files to be streamed are read +from standard input. +.Pp +Lastly, the +.Dv EZSTREAM +environment variable allows to specify an alternate +.Nm ezstream +binary. +.Ss Command line parameters +.Bl -tag -width Ds +.It Fl h +Print a summary of available command line parameters with short descriptions +and exit. +.It Fl n +.Po +Passed to +.Nm ezstream . +.Pc +Normalize metadata strings by removing excess whitespaces. +.It Fl q +.Po +Passed to +.Nm ezstream . +.Pc +Be more quiet. +Suppress the output that external programs send to standard error. +.It Fl T Ar cfg_template +Use the configuration in +.Ar cfg_template , +overriding the default set in the +.Dv EZSTREAM_TEMPLATE +environment variable. +.It Fl V +Print the +.Nm +version number and exit. +.It Fl v +.Po +Passed to +.Nm ezstream . +.Pc +Produce more verbose output from +.Nm ezstream . +Use twice for even more verbose output. +.El +.Sh FILES +.Bl -tag -width "!!EXAMPLES_DIR!!" -compact +.It Pa !!EXAMPLES_DIR!! +Directory containing example configuration files for various uses of +.Nm ezstream , +as well as example playlist and metadata scripts. +.El +.Sh SEE ALSO +.Xr ezstream 1 +.Sh AUTHORS +.An -nosplit +.Nm +and this manual were written by +.An Moritz Grimm Aq mdgrimm@gmx.net . diff --git a/doc/ezstream.1.in b/doc/ezstream.1.in.in similarity index 99% rename from doc/ezstream.1.in rename to doc/ezstream.1.in.in index 5625704..292a7e9 100644 --- a/doc/ezstream.1.in +++ b/doc/ezstream.1.in.in @@ -3,9 +3,9 @@ .\" This document may be be used and/or modified under the licensing terms .\" of the Ezstream software. .\" -.Dd !!BUILD_DATE!! +.Dd @BUILD_DATE@ .Dt EZSTREAM 1 -.Os +.Os @PACKAGE_NAME@ @PACKAGE_VERSION@ .Sh NAME .Nm ezstream .Nd source client for Icecast with external de-/encoder support @@ -598,6 +598,8 @@ Directory containing example configuration files for various uses of .Nm , as well as example playlist and metadata scripts. .El +.Sh SEE ALSO +.Xr ezstream-file.sh 1 .Sh AUTHORS .Nm was written by: diff --git a/src/Makefile.am b/src/Makefile.am index 582aa37..643a3a7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,7 @@ AUTOMAKE_OPTIONS = 1.9 foreign bin_PROGRAMS = ezstream +bin_SCRIPTS = ezstream-file.sh ezstream_SOURCES = \ compat.c \ diff --git a/src/ezstream-file.sh.in b/src/ezstream-file.sh.in new file mode 100644 index 0000000..b6922fe --- /dev/null +++ b/src/ezstream-file.sh.in @@ -0,0 +1,145 @@ +#!/bin/sh + +# ezstream-file.sh +# Convenience/wrapper script that uses ezstream to stream one or more files +# given on the command line. + +# Copyright (c) 2009 Moritz Grimm +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +_myname="$(basename $0)" +_filename_placeholder="%FILENAME%" + +_opt_string="hnqT:Vv" +print_usage() +{ + echo "usage: ${_myname} [-hnqVv] [-T cfg_template] [file ...]" >&2 +} + +print_usage_help() +{ + cat << __EOT >&2 + + -h print this help and exit + -n [ezstream] normalize metadata strings + -q [ezstream] suppress STDERR output from external en-/decoders + -T template run ezstream using template for configuration + -V print the version number and exit + -v [ezstream] verbose output (use twice for more effect) + +The configuration template must contain the configuration statement + ${_filename_placeholder} + +See the ezstream-file.sh(1) manual for detailed information. +__EOT +} + +_normalize="" +_quiet="" +_verbose="" +_cfg_template="${EZSTREAM_TEMPLATE}" + +_args=`getopt ${_opt_string} $*` +if [ $? -ne 0 ]; then + print_usage + exit 2 +fi +set -- ${_args} +while [ $# -ge 0 ] +do + case "$1" in + -h) + print_usage + print_usage_help + exit 0 + ;; + -n) + _normalize="-n"; shift ;; + -q) + _quiet="-q"; shift ;; + -T) + _cfg_template="$2"; shift; shift ;; + -V) + echo "${_myname} @PACKAGE_VERSION@" + exit 0 + ;; + -v) + if [ -z "${_verbose}" ]; then + _verbose="-v" + else + _verbose="${_verbose}v" + fi + shift ;; + --) + shift; break ;; + esac +done + +if [ -z "${_cfg_template}" ]; then + echo "${_myname}: No configuration template supplied." >&2 + echo "Use -T or the EZSTREAM_TEMPLATE environment variable." >&2 + exit 2 +fi +if [ ! -e "${_cfg_template}" ]; then + echo "${_myname}: Configuration template ${_cfg_template} does not exist." >&2 + exit 2 +fi +if [ -z "$(grep ${_filename_placeholder} ${_cfg_template})" ]; then + echo "${_myname}: ${_cfg_template} lacks the ${_filename_placeholder} placeholder." >&2 + exit 2 +fi + +test -n "${EZSTREAM}" || EZSTREAM="$(which ezstream)" +if [ -z "${EZSTREAM}" ]; then + echo "${_myname}: Cannot find ezstream." >&2 + exit 2 +fi + +_temp_dir="`mktemp -t -d _ezstream.XXXXXXXXXX`" +if [ $? -ne 0 ]; then + echo "${_myname}: Unable to create temporary directory." >&2 + exit 1 +fi +trap 'rm -rf ${_temp_dir}' 0 +trap 'rm -rf ${_temp_dir}; exit 1' 2 15 + +_cfg="${_temp_dir}/config.xml" +_playlist="${_temp_dir}/playlist.txt" + +touch "${_cfg}" +if [ $? -ne 0 ]; then + echo "${_myname}: Unable to create configuration." >&2 + exit 1 +fi +chmod 0600 "${_cfg}" + +sed -e "s,${_filename_placeholder},${_playlist},g" \ + < "${_cfg_template}" \ + > "${_cfg}" + +if [ -n "$1" ]; then + for _file in $* + do + echo "${_file}" >> "${_playlist}" + done +else + while read _file + do + echo "${_file}" >> "${_playlist}" + done +fi + +"${EZSTREAM}" ${_normalize} ${_quiet} ${_verbose} -c "${_cfg}" + +exit $?