Friday, January 28, 2011

YouTube true fullscreen video in linux


I got tired to buggy playback with flash player and the inability to play fullsize fullscreen video. Here is a little script designed to improve the quality of life.

What it does is first get the url of the video and then start downloading it. Once it fills the predefined buffer set in the script or the download finishes, it will start playing the video.

If the youtube-dl script from a repository doesn't work try getting it straight from here: http://rg3.github.com/youtube-dl/

For pure lazyness I also made a desktop icon where I can drag an url and it will automagically start playing the video.

Try it. It's good. :)




Setting up the script in Fedora
sudo su
yum -y install youtube-dl 
wget -O /usr/local/bin/youtube-play http://sebastianmaki.fi/files/youtube-play
chmod a+x /usr/local/bin/youtube-play




/usr/local/bin/youtube-play
#!/bin/bash
#youtube-player by Sebastian Mäki

if [ $# -eq 0 ]; then
 echo "Usage: $(basename $0) \$URL"
exit 0;
fi


PLAYER_NAMES="gnome-mplayer gmplayer mplayer"

for PLAYER_CANDIDATE in $PLAYER_NAMES; do 
 if which $PLAYER_CANDIDATE > /dev/null; then 
  PLAYER=$PLAYER_CANDIDATE; 
  break; 
 fi;
done;

BUFFER=$((1024*1024*2)) #initial buffer size 2MB


TMP=`mktemp`
COOKIES=`mktemp`
rm $COOKIES

URL=$(youtube-dl --cookies=$COOKIES --get-url $1)

wget -q --load-cookies=$COOKIES -O $TMP $URL &
PID=$!

SIZE=0;
while [ $SIZE -lt $BUFFER ]; do
 if ps -lp $PID > /dev/null; then 
  SIZE=$(stat -c%s $TMP)
 else
  SIZE=$(($BUFFER+1))
 fi
 sleep 1;
done;
$PLAYER $TMP
kill -9 $PID
rm -f $TMP $COOKIES




Youtube-Player.desktop <-- put this shortcut file to your desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Name=Youtube Player
Name[fi_FI]=Youtube Soitin
Name[sv_SE]=Youtube Spelare
Exec=youtube-play %U

Icon=/usr/share/icons/YouTube_icon.png

Tip me if you like what you're reading