MPlayer SVN-r32999-4.4.5 (C) 2000-2011 MPlayer Team Playing http://v3.lscache2.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor&fexp=901031%2C907508%2C900304&algorithm=throttle-factor&itag=34&ipbits=8&burst=40&sver=3&signature=97D6F8D1A948EF2451FD4F093ECA7EF3795EE424.73F2B07D5F478ACEAFCEAC98E7BF2623FEED20EC&expire=1299384000&key=yt1&ip=97.0.0.0&factor=1.25&id=f2ecb156675a27ec. Resolving v3.lscache2.c.youtube.com for AF_INET6... Couldn't resolve name for AF_INET6: v3.lscache2.c.youtube.com Resolving v3.lscache2.c.youtube.com for AF_INET... Connecting to server v3.lscache2.c.youtube.com[74.125.15.14]: 80... Cache size set to 320 KBytes Cache fill: 19.54% (64036 bytes) libavformat file format detected. [flv @ 0x2acf540] Estimating duration from bitrate, this may be inaccurate [lavf] stream 0: video (h264), -vid 0 [lavf] stream 1: audio (aac), -aid 0 VIDEO: [H264] 640x360 0bpp 24.000 fps 557.2 kbps (68.0 kbyte/s) Clip info: duration: 162 starttime: 0 totalduration: 162 width: 640 height: 360 videodatarate: 544 audiodatarate: 97 totaldatarate: 649 framerate: 24 bytelength: 13120260 canseekontime: true sourcedata: B4A7D0F03HH1299359484777471 purl: pmsg: ========================================================================== Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264) ========================================================================== ========================================================================== Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders AUDIO: 44100 Hz, 2 ch, s16le, 99.0 kbit/7.02% (ratio: 12379->176400) Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio)) ========================================================================== [AO OSS] audio_setup: Can't open audio device /dev/dsp: Device or resource busy AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample) Starting playback... Movie-Aspect is 1.78:1 - prescaling to correct movie aspect. VO: [xv] 640x360 => 640x360 Planar YV12 [fs] A: 2.4 V: 2.4 A-V: -0.000 ct: 0.000 0/ 0 19% 15% 0.4% 7 0 47%
The original doesn't work for me - but this does. I'm guessing that Youtube updated the video page so the original doesn't work.
Streams youtube video with v=ID directly into the mplayer.
If exists, it uses the HD-quality stream.
If you don't want to watch it in HD-quality, you can use the shorter form:
ID=52DnUo6wJto; mplayer -fs $(echo "http://youtube.com/get_video.php?&video_id=$ID$(wget -qO - 'http://youtube.com/watch?v='$ID | perl -ne 'print $1."&asv=" if /^.*(&t=.*?)&.*$/')")
Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?
You must be signed in to comment.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
mplayer $(echo -s "http://youtube.com/get_video.php?$(curl $youtube_url | sed -n "/watch_fullscreen/s;.*\(video_id.\+\)&title.*;\1;p")&fmt=22")
...And &fmt=6 for HQ. Also, if you want to download videos, just add the -dumpstream option to mplayer. Best command ever! :Dvlc youtube-url-here
source get_youtube.bash
or whatever you called it. Then you can domplayer "$(get_url "$youtube_url")"
Which yeah might be less than 14 characters if you renamed the variable and the function. Is that the point? You could rewrite the whole thing into an single-line intestinal clog of jibberish... but given that it will probably break in a month anyway it seems better to have it be modular so you can fix it quickly. Though actually it might be much more modular to just install the "youtube-dl" package, or yeah use vlc -- thanks for the tip by the way. Seems a bit more Sun Tzu than Shao Lin, but who's complaining? Anyway this is perhaps an interesting example of using sed to generate what's basically an rc file. It should in theory exit on parsing errors instead of causing random code to be executed from your shell prompt.. but I wouldn't run it sudo. It may not be particularly portable, I'm pretty Linux-centric, specifically Ubuntu. Advisements will be taken under advisement. PS Hope that turned out okay presentation-wise.. are there tags to delimit code on this site? I used "[code] ... [/code]" ...as you can see if it didn't work.#!/bin/bash
# emit a last gasp of information
function croak {
echo "$0: $2" >&2; exit $1;
}
# parse incoming html and return evaluable bash code setting the t and video_id variables
function get_params {
grep '^[ ]*var[ ]\+swfArgs[ ]*=[ ]*{[ ]*' \
| sed 's/.*{\s*//; # remove begin section
s/}\s*;\s*$//; # remove end section
s/"\([^"]*\)"\s*:\s*\("[^"]*"\)\s*,\?\s*/\1=\2\n/g # translate js array mappings into bash assignments' \
| egrep '^(t|video_id)=' \
|| croak 1 "couldn't grep url parameters; pipe status='${PIPESTATUS[@]}'";
}
# get the html and make it parseable
function get_html {
{ curl -s "$1" || croak 2 "error $? from curl"; } | tidy -quiet -wrap 0 2>/dev/null;
}
# fetch the frontend web page and parse the backend url out of it
function get_url {
eval "$(get_html "$1" | get_params)";
echo "http://youtube.com/get_video.php?t=$t&video_id=$video_id";
}