#!/bin/bash ## Run mplayer on given file or URL using youtube-dl to decipher youtube URLs. ## Usage: mp [-low] [-help] [-mplayer-help] [options] [url|path/]filename ## [options] are identical to mplayer except others listed here ## -help show this help screen ## -low use the lower bitrate youtube feed ## -mplayer-help same as "mplayer --help" ## mp 0.2 (c) 2008 Adam Katz , free under GPL v2+ if type youtube-dl >/dev/null 2>&1; then YOUTUBE=true BEST_QUALITY='-b' fi while [ -n "$1" ]; do i=$((${i:-0}+1)) # array index, equiv to c-style for(i=1; "$1"; i++) { } if [[ "$1" =~ "^-+low$" ]] # reminder: regex matching is bash-only then unset BEST_QUALITY elif [ "$1" = "-h" ] || [[ "$1" =~ "^-+help" ]] then sed -e '/^## /!d' -e 's///' "`which $0 || echo $0`"; exit 0 elif [[ "$1" =~ "^-+mplayer" ]] then mplayer --help; exit $? elif [[ "$1" =~ "^[fh]t?tp://.*youtube\.com/.." ]] then if [ -n "$YOUTUBE" ] then ARGS[$i]=$(youtube-dl -g $BEST_QUALITY "$1") else echo "${0##*/}: Trying to play youtube video without youtube-dl" >&2 ARGS[$i]="$1" fi fi shift done exec mplayer "${ARGS[@]}" # we use arrays to preserve spacing. requires bash.