#!/bin/bash # Licensed under the GPL v3 # Version 0.2 Build 200906221945 # Added options and error checking # Version 0.1 Build 200906031245 - Original Ken Fallon (c) DEFAULTFORMAT=ogg usage() { SCRIPT=`basename $0` cat << EOF Usage: ${SCRIPT} [-h] [-t format] [-f filename] [-u] url Description: This script will convert a webpage into a audio file. OPTIONS: -h Show this message -t Type of audio file to use (wav, mp3, ogg, etc) -f Filename to save as -y Overwrite file -u URL of the webpage (Required) EXAMPLE: ${SCRIPT} http://en.wikipedia.org/wiki/Thin_lizzy ${SCRIPT} -t ogg -f lizzy.ogg -y -u http://en.wikipedia.org/wiki/Thin_lizzy EOF } # Check if the required tools are installed which basename sed wget html2text espeak ffmpeg > /dev/null || (echo "Missing required software." && exit 2) URL= TYPE= FILENAME= OVERWRITE= while getopts "hu:t::f::y" OPTION do case $OPTION in h) usage exit 1 ;; u) URL=$OPTARG ;; t) TYPE=$OPTARG ;; f) FILENAME=$OPTARG ;; y) OVERWRITE="-y" ;; esac done echo "$*" | grep "://" > /dev/null 2>&1 if [ "$?" -ne 0 ] || [ ! -n "$1" ] ;then usage exit fi if [ -z $URL ] ;then URL=$* fi if [ -z $TYPE ] ;then TYPE=$DEFAULTFORMAT fi if [ -z $FILENAME ] ;then FILENAME=`echo $URL|sed 's[^.*://[[g'|sed -e 's/[^[:alnum:]]/-/g'`.${TYPE} fi wget -q ${URL} -O - | \ html2text -nobs -ascii -o -| \ espeak --stdout | \ ffmpeg -v 2 ${OVERWRITE} -i - "${FILENAME}"