pkgsrc-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Recommendation requested - video player
Jonathan Schleifer wrote:
> "Jeremy C. Reed" <reed%reedmedia.net@localhost> wrote:
> > Last week I used pkgsrc/net/youtube-dl over ten times to download
> > Flash videos and mplayer played the .flv files fine.
Python? No thanks. It only requires a shell script and curl. See
the attached script.
> There is an mplayer plugin for Firefox and there's a User Script for
> the Greasemonkey Firefox Extension that uses that mplayer plugin to
> show YouTube videos - no need to download.
There are still people who are not using Firefox or Flash and consider
downloading as more convenient than streaming (no hickups, no bandwidth
issues, instant replay, seeking, timeshift).
That said, you can directly stream the video to MPlayer if you like:
youtube-dl --overwrite --output=/dev/stdout --silent -- URL | mplayer
-noconsolecontrols /dev/stdin
--
Christian
#! /bin/sh
set -e
# Initialize variables
output="video.flv"
silent=
help=
print_url=
overwrite=
usage="\
Usage: ${0##*/} [--silent] [--output PATH] URL
Options:
--silent: Suppress download progress.
--print-url: Print URL only and exit.
--output=PATH: Download to PATH (default: $output).
--overwrite: Overwrite output file if it exists.
"
# Handle command line arguments
while [ $# -gt 1 ]
do
option="$1"
case "$option" in
--) shift
break
;;
--print-url) print_url=1
;;
--overwrite) overwrite=1
;;
--output=*) output="${1#*=}"
;;
--silent) silent='--silent'
;;
--help|-help|-h)help=1
;;
-*) echo "ERROR: Unsupported argument \"$option\"" >&2
printf "%s" "$usage" >&2
exit 1
;;
*) shift
break
;;
esac
shift
done
if [ "X$help" != X ]
then printf "%s" "$usage"
exit 1
fi
case "$1" in
http://*) input_url="$1";;
*) echo "ERROR: Expected HTTP URL" >&2
printf "%s" "$usage" >&2
exit 1
;;
esac
# Sanitize PATH so it cannot look like an argument (no leading hyphen)
case "$output" in
'') echo "ERROR: Missing or empty --output argument" >&2
printf "%s" "$usage" >&2
exit 1
;;
/*|./*)
;;
*) output="./$output"
;;
esac
domain="${input_url#http://}"
domain="${domain%%/*}"
html_path="/${input_url#http://*/}"
case "$domain" in
youtube.com|*.youtube.com);;
*) echo "ERROR: This script can only download from youtube.com." >&2
exit 1
esac
case "$html_path" in
/watch[?]*) ;;
/v/*) html_path="/watch?v=${html_path#/v/}"
;;
*) # Try anyway
;;
esac
# Compose HTML URL
html_url="http://$domain$html_path"
# Extract the path of the FLV file from the HTML text
flv_path="$(curl --globoff --silent --location --url "$html_url" | \
sed -n
's,^.*[/]watch_fullscreen[?][a-zA-Z0-9._=&%-]*\(video_id[=][^&]*\).*\([&]t=[^&]*\).*$,/get_video?\1\2,p;
/get_video/q')"
case "$flv_path" in
/get_video*) ;;
*) echo "ERROR: Could not determine video URL." >&2
if ! command -v curl >/dev/null 2>&1
then echo "This script requires curl (http://curl.haxx.se/)."
>&2
fi
exit 1
;;
esac
# Compose FLV URL
flv_url="http://$domain$flv_path"
if [ "X$print_url" != X ]
then echo "$flv_url"
exit
fi
if [ "X$overwrite" = X ] && [ -e "$output" ]
then echo "ERROR: Output file \"$output\" exists, refusing to overwrite." >&2
exit 1
fi
# Fetch the FLV file and exit
exec curl --globoff --location ${silent} --output "$output" --url "$flv_url"
Home |
Main Index |
Thread Index |
Old Index