Howto; Youtube utan flash!
Postat: 29 apr 2009, 12:12
Då flash är det sämsta skit som någonsin skapats så tänkte jag dela med mig om hur man kan avinstallera skräpet utan att gå miste om alla youtube-videos man får skickade till sig.
Matcher för urxvt;
Kod: Markera allt
#!/bin/sh
# This script is intended to let you launch a youtube video in mplayer. Very
# handy if you primarily use text mode browsers with no javascript or flash
# support, such as lynx or w3m.
#
# Usage: youtube [url] [--exec program] [-- program options]
#
# If no url is given, the script expects to receive the html from the page on
# standard input.
#
# --exec can be used to specify which program to open the final flv url in.
# mplayer is used by default, but wget is another useful option.
#
# Examples:
#
# No fuzz, just play the video with mplayer:
# youtube.sh http://www.youtube.com/watch?v=...
#
# If you found a nice piece of music and just want to listen to it:
# youtube.sh http://www.youtube.com/watch?v=... -- -novideo
#
# Download a video:
# youtube.sh http://www.youtube.com/watch?v=... --exec wget -- -O foobar.flv
#
# If you use w3m, you can configure this script to be used as an external
# browser. This will allow you to browse youtube in w3m and simply press M to
# view the video.
#
extract_final_url()
{
# The javascript line containing "fullscreenUrl" contains the info we need.
# head -n1 makes sure only the first such line gets processed (otherwise the script would break if someone left a comment containing that string).
# sed does the actual extraction and assembles them as the final url.
# egrep at the end ensures that we only continue if sed did indeed manage to construct a correct url
grep 'fullscreenUrl' \
|head -n1 \
|sed 's#^.*[&?]\(video_id=[^&]\+\).*&\(t=[^&]\+\).*$#http://www.youtube.com/get_video?\1\&\2#g' \
|egrep '^http://.+\.youtube\.com/get_video\?video_id=.+&t=.+$'
if [ $? -ne 0 ]; then
echo "Could not extract the final url. Maybe youtube changed design?" 1>&2
return 1
fi
}
EXEC="mplayer"
# Parse parameters
while [ $# -gt 0 ]; do
case "$1" in
http://*)
HTML_URL="$1"
;;
--exec)
if [ $# -gt 1 ] && [ "$2" != "--" ]; then
EXEC="$2"; shift
else
echo "Parameter '$1' expects an option"
exit 2
fi
;;
--)
shift
break
;;
*)
echo "Unknown parameter '$1'" 1>&2
exit 3
;;
esac
shift
done
if [ "$HTML_URL" ]; then
# If a url was given, assume that it was the html url (e.g. http://www.youtube.com/watch?v=4Swzbt76wBM)
FINAL_URL="$(curl -s "$HTML_URL"|extract_final_url)"
else
# If no parameter was given, read the html on standard input
FINAL_URL="$(extract_final_url)"
fi
if [ "$FINAL_URL" ]; then
"$EXEC" "$FINAL_URL" "${@}"
else
echo "No final url found, not launching ${EXEC}" 1>&2
exit 2
fi
Kod: Markera allt
/(?:http:\/\/|www\.|http:\/\/www\.)youtube\.com\/watch\?\S*v=([^\s&\?\.,!]+)/