#!/bin/sh

##################################################
##    mplayer_setup.sh: version .00000003       ##
## Purpose:                                     ##
##   Setup mplayer and mplayerplug-in           ##
##                                              ##
## COPYRIGHT NOTICE:                            ##
##   License:    GPL                            ##
##   Created by: John Streeton Stile            ##
##   email:      john@stilen.com                ##
##################################################

#===========================================
#MPLAYTER
#========================================
# I wanted to see a lot of streamed move trailers
# And I use mplayer on linux.

# Proxy setup
Proxy_url=""
Proxy_user=""
Proxy_passwd=""
Proxy=""
echo "---------------------------------"
echo "Do you have a proxy"
read Answer
if [ $Answer == "yes" ]; then
  echo "Enter proxy url:"
  read Proxy_url
  echo "Enter proxy user name"
  read Proxy_user
  echo "Enter proxy user passwd"
  read Proxy_passwd
  
  Proxy="--proxy=$Proxy_url --proxy-user=$Proxy_user --proxy-passwd=$Proxy_passwd"
else
  echo "No proxy configured"
  Proxy="--proxy=off "
fi


echo "---------------------------------"
echo "Make a build dir",`date`
mkdir mplayer_build
cd  mplayer_build

echo "---------------------------------"
echo "Get needed codecs",`date`
mkdir codecs
pushd codecs
wget -c  -S --passive-ftp $Proxy ftp://ftp.lug.udel.edu/MPlayer/releases/codecs/*
 
echo "---------------------------------"
echo "Unpack Codecs ",`date`
FILES=`ls \`pwd\`/*.bz2 | grep -v -E "ppc|alpha|orig|lite"`
for FILE in $FILES; do echo "Unpacking $FILE";  tar -jxf $FILE; done

echo "---------------------------------"
echo "Put codecs in codec directory: /usr/local/lib/codecs",`date`
su -c '
mkdir /usr/local/lib/codecs
cp -f */* /usr/local/lib/codecs/
chown root.root /usr/local/lib/codecs/*
'
echo "---------------------------------"
echo "Going back to mplayer_build directory",`date`
popd

echo "---------------------------------"
echo "Done with codecs",`date`
ls /usr/local/lib/codecs

echo "---------------------------------"
echo "Get mplayer"
wget -c -S $Proxy  http://www1.mplayerhq.hu/MPlayer/releases/MPlayer-0.92.tar.bz2
# wget http://www1.mplayerhq.hu/MPlayer/releases/MPlayer-1.0pre3.tar.bz2

echo "---------------------------------"
echo "Unpack",`date`
sleep 1
tar -jxvf MPlayer-0.92.tar.bz2
# tar -xjvf MPlayer-1.0pre3.tar.bz2

echo "---------------------------------"
echo "Change into mplayer directory",`date`
pushd MPlayer-0.92/
# pushd MPlayer-1.0pre3/

echo "---------------------------------"
echo "Compile mplayer",`date`
./configure --enable-win32 --enable-gui

#=======================================
#This is how my MPlayer-0.92 compile turned out
#=======================================
#  Config files successfully generated by ./configure !
#
#  Install prefix: /usr/local
#  Data directory: /usr/local/share/mplayer
#  Config direct.: /usr/local/etc/mplayer
#
#  Byte order:     Little Endian
#  Optimizing for: pentium3 mmx mmx2 sse mtrr
#  
#  Enabled optional drivers:
#    Input:        streaming tv-v4l edl tv cdda mpdvdkit2 vcd 
#    Codecs:       qtx libdv libavcodec real xanim dshow/dmo win32 gif 
#    Audio output: oss mpegpes(dvb) 
#    Video output: xvidix vesa gif89a jpeg png mpegpes(dvb) fbdev opengl dga xv x11 dfbmga directfb 
#  Disabled optional drivers:
#    Input:        tv-bsdbt848 dvdnav dvdread dvdcss smb 
#    Codecs:       opendivx xvid libvorbis libmad liblzo 
#    Audio output: sgi sun alsa esd arts dxr2 nas win32 sdl 
#    Video output: bl zr dxr3 dxr2 directx sdl svga aa ggi xmga mga tdfxfb 3dfx 
#=======================================
#This is how my MPlayer-1.0pre compile turned out
#=======================================
#Config files successfully generated by ./configure !
#
#  Install prefix: /usr/local
#  Data directory: /usr/local/share/mplayer
#  Config direct.: /usr/local/etc/mplayer
#
#  Byte order: Little Endian
#  Optimizing for: pentium3 mmx mmx2 sse mtrr
#
#  Languages:
#    Messages/GUI: en
#    Manual pages: en (no localization selected, use --language=all)
#
#  Enabled optional drivers:
#    Input:        ftp network tv-v4l2 tv-v4l edl tv cdda mpdvdkit2 vcd dvb 
#    Codecs:       flac(internal) qtx libdv libavcodec real xanim dshow/dmo win32 faad2(internal) gif 
#    Audio output: oss mpegpes(dvb) 
#    Video output: xvidix cvidix vesa gif89a jpeg png mpegpes(dvb) fbdev opengl dga xv x11 xover df  bmga directfb tga 
#  Disabled optional drivers:
#    Input:        tv-bsdbt848 live.com matroska dvdread smb 
#    Codecs:       opendivx xvid libtheora libvorbis libmad liblzo 
#    Audio output: sgi sun alsa esd arts dxr2 nas win32 sdl macosx 
#    Video output: winvidix bl zr zr2 dxr3 dxr2 directx sdl svga aa ggi xmga mga xvmc tdfx_vid tdfx  fb 3dfx 
#=======================================

echo "---------------------------------"
echo "Running make mplayer",`date`
make 

echo "---------------------------------"
echo "Install mplayer as root",`date`
su -c 'make install'

if [ ! -x  /usr/local/bin/mplayer ]; then
	echo "no mplayer: /usr/local/bin/mplayer"
	exit
fi

echo "---------------------------------"
echo "Get out of the MPlayer-0.92 directory",`date`
cd ..

echo "---------------------------------"
echo "Get fonts",`date`
mkdir fonts
pushd fonts
wget -c  -S --passive-ftp $Proxy ftp://ftp.lug.udel.edu/MPlayer/releases/fonts/*

echo "---------------------------------"
echo "Unpack fonts",`date`
FILES=`ls \`pwd\`/*.bz2 `
for FILE in $FILES; do echo "Unpacking $FILE";  tar -jxf $FILE; done

echo "---------------------------------"
echo "Install fonts",`date`
su -c '
mkdir /usr/local/share/mplayer/font
cp -fr * /usr/local/share/mplayer/font
chown -R root.root /usr/local/share/mplayer/font/*
'
echo "---------------------------------"
echo "Going back to mplayer_build directory",`date`
popd; popd

echo "---------------------------------"
echo "  Get More skin(s) at http://www.mplayerhq.hu/homepage/dload.html"
echo "  for GUI, and extract to /usr/local/share/mplayer/Skin/"
echo "  This is what you have now:"
ls /usr/local/share/mplayer/Skin/

echo "---------------------------------"
echo "Configure your personal settings for mplayer",`date`
echo "   Creating $HOME/.mplayer/config"
mkdir $HOME/.mplayer/
cat > $HOME/.mplayer/config  << EOF
#Write your default config options here!
cachesize=65536
framedrop=1
hardframedrop=1
delay=-0.4
ao=sdl,arts,esd,oss
vo=gl,xv,x11
use-gui=yes
EOF

# personal codec settings in /home/jstile/.mplayer/codecs.conf
# but I left mine blank

#===========================================
echo "Go get Mplayerplug-in http://mplayerplug-in.sourceforge.net/ "
wget -c -S  $Proxy http://easynews.dl.sourceforge.net/sourceforge/mplayerplug-in/mplayerplug-in-1.2.tar.gz
tar -xzvf mplayerplug-in-1.2.tar.gz
cd mplayerplug-in
./configure --with-x
make

echo "---------------------------------"
echo "Settup for a User",`date`
echo "make install"
make install
# or cp mplayerplug-in.so ~/.mozilla/plugins 

ls -laF /home/jstile/.mozilla/plugins/
#      total 292
#      drwxr-xr-x    2 jstile   users	      88 Jan 27 06:31 ./
#      drwxr-xr-x    4 jstile   users	     120 Jan 27 06:31 ../
#      -rwxr-xr-x    1 jstile   users	  295417 Jan 27 06:31 mplayerplug-in.so*


echo "---------------------------------"
echo "Configure your personal settings for mplayerplug-in",`date`
echo "   Creating $HOME/.mplayer/mplayerplug-in.conf"
cat > ~/.mplayer/mplayerplug-in.conf << EOF
prefer-aspect=1
debug=1
cachesize=65535
download=1
dload=dir=$HOME
keep-download=0
use-gui=yes
EOF

echo "---------------------------------"
echo "I can't install system wide"
#su -c "make install"
# or 
#  cp mplayerplug-in.so /usr/lib/mozilla/plugins
#  Other places that may work depending on your browser:
#  /usr/lib/netscape/plugins
#  $HOME/.netscape/plugins

echo "---------------------------------"
echo "Getting out of mplayerplug-in directory"
cd ..

echo "---------------------------------"
echo "Test a mov file"
wget -c -S $Proxy http://fredrik.hubbe.net/plugger/test.mov
gmplayer test.mov

echo "---------------------------------"
echo "Test a stream"
gmplayer http://a772.g.akamai.net/5/772/51/20b9f288dddd83/1a1a1aaa2198c627970773d80669d84574a8d80d3cb12453c02589f25382f668c9329e0375e8177dec6493f758ca2f93f86ed743/daredevil-tlr_320.mov

echo "---------------------------------"
echo "Test scaling test1"
gmplayer -x 500 -y 200 http://a772.g.akamai.net/5/772/51/20b9f288dddd83/1a1a1aaa2198c627970773d80669d84574a8d80d3cb12453c02589f25382f668c9329e0375e8177dec6493f758ca2f93f86ed743/daredevil-tlr_320.mov

echo "---------------------------------"
echo "Test scaling test2"
mplayer -xy 500 http://a772.g.akamai.net/5/772/51/20b9f288dddd83/1a1a1aaa2198c627970773d80669d84574a8d80d3cb12453c02589f25382f668c9329e0375e8177dec6493f758ca2f93f86ed743/daredevil-tlr_320.mov


echo "---------------------------------"
echo "This worked better but my system is too slow"
gmplayer -vo gl -ao sdl -hardframedrop -cache 65536  http://a772.g.akamai.net/5/772/51/20b9f288dddd83/1a1a1aaa2198c627970773d80669d84574a8d80d3cb12453c02589f25382f668c9329e0375e8177dec6493f758ca2f93f86ed743/daredevil-tlr_320.mov
