[mythtv-users] WAF Just went way up :)

jedi jedi at mishnet.org
Fri Dec 5 01:17:32 UTC 2008


On Thu, Dec 04, 2008 at 07:02:59PM -0600, Brent Norris wrote:
> jedi wrote:
> > 
> >     I have a wrapper for my external player that keeps track of what the
> > last watched show is and can present the next epissode in sequence.
> 
> Link?

   Well, you asked for it...

   I've been thinking about making this more db centric with stored
procedures and stuff rather than touching the filesystem since 
anything that's playable should be in the database anyways. Initially, 
this started out not using the database but that wasn't sufficiently 
mobile.

------------- db stuff --------------

create table xine_wrapper (
vob_source varchar(1000),
last_played_id int,
last_played_file varchar(200)
)

create table xine_wrapper_play_log (
vob_source varchar(1000),
vob_file varchar(1000),
start_time datetime,
stop_time datetime
)

------------ ctl examples  -------------

::::::::::::::
StarTrek_000+CurrentEpisode.vob
::::::::::::::
###--- /home/media/DVD/StarTrek/StarTrek_000+CurrentEpisode.vob -- xine wrapper control file ---###
VOB_SOURCE=/home/media/DVD/StarTrek
ACTION=current
::::::::::::::
StarTrek_000+NextEpisode.vob
::::::::::::::
###--- /home/media/DVD/StarTrek/StarTrek_000+NextEpisode.vob -- xine wrapper control file ---###
VOB_SOURCE=/home/media/DVD/StarTrek
ACTION=next

--------------- xine-wrapper.sh ---------------

#!/bin/bash

########################################################################
###
###
###
### Version: 2.4
### Date: 13-Oct-2008
###
### Changes: 13-Oct-2008 -- Added proper handling for single quotes in
###          filenames. Decided this was better than stripping them out
###          of all the filenames.
###
### Version: 2.3
### Date: 2-Oct-2008
###
### Changes: 2-Oct-2008 -- Adding a field to the history table so I
###          can track which frontends are being used. I suspect that
###          frankie is being neglected since Seth mostly plays the
###          Wii these days (rather than watching TV).
###
### Version: 2.2
### Date: 24-DEC-2007
###
### Changes: 24-DEC-2007 -- Altered the ordering of when and where 
###          VOB_SOURCE is set so that playing a file normally will
###          set the last file played pointers. This also prevents
###          vob_source from being set to "blank" in the play log.
###
########################################################################

CROP_ME="SpaceBalls.vob"

########################################################################
########################################################################
########################################################################
function _mysql_exec {

host=$(cat ~/.mythtv/mysql.txt | grep 'DBHostName=' | sed 's/DBHostName=//g')
user=$(cat ~/.mythtv/mysql.txt | grep 'DBUserName=' | sed 's/DBUserName=//g')
pass=$(cat ~/.mythtv/mysql.txt | grep 'DBPassword=' | sed 's/DBPassword=//g')

echo "$1" | mysql --user=$user --password=$pass -h lars -D mythconverg

}
########################################################################
function _log_last_played_start {

_vob_source="$1"
_last_played_file="$2"
_hostname=$(hostname)

_last_played_file=$( echo "$_last_played_file" | sed "s/'/''/g" )

_query="insert into xine_wrapper_play_log(vob_source,vob_file,start_time,hostname)
values ('$_vob_source','$_last_played_file',now(),'$_hostname');"


_out=$(_mysql_exec "$_query" )

echo $_out
}
########################################################################
function _log_last_played_stop {

_vob_source="$1"
_last_played_file="$2"
_hostname=$(hostname)

_last_played_file=$( echo "$_last_played_file" | sed "s/'/''/g" )

_query="select max(start_time) from 
                    xine_wrapper_play_log
                    where vob_source='$_vob_source'
                    and vob_file='$_last_played_file'
                    and hostname='$_hostname';"

_start=$(_mysql_exec "$_query" | tail -1 )

_query="update xine_wrapper_play_log 
set stop_time=now()
where vob_source='$_vob_source'
  and vob_file='$_last_played_file'
  and start_time = '$_start'
  and hostname='$_hostname';"

_out=$(_mysql_exec "$_query" )

echo $_out
}
########################################################################
function _get_last_played {

_vob_source="$1"

_query="select last_played_file
from xine_wrapper 
where vob_source='$_vob_source';"

_out=$(_mysql_exec "$_query" | egrep -v 'last_played_file' )

if [ "$_out" = "" ]; then
    query="insert into xine_wrapper values ('$_vob_source',0,'none');"
    _out=$(_mysql_exec "$_query")
    echo "none"
else
    echo "$_out"
fi
}
########################################################################
function _set_last_played {

_vob_source="$1"
_last_played_file="$2"

_last_played_file=$( echo "$_last_played_file" | sed "s/'/''/g" )

echo "<vob_source>$_vob_source"
echo "<last_played_file>$_last_played_file"

### Don't update the file if it is a playlist
_flag=$(echo $_vob_source | egrep  'm3u$' |wc -l)
if [ $_flag -gt 0 ]; then
    return
fi

_query="select last_played_file 
from xine_wrapper 
where vob_source='$_vob_source';"

_out=$(_mysql_exec "$_query" | egrep -v 'last_played_file' )

if [ "$_out" = "" ]; then
    _query="insert into xine_wrapper 
          values ('$_vob_source',0,'none');"
    _out=$(_mysql_exec "$_query")
    echo "$_last_played_file"
else
    _query="update xine_wrapper
	  set last_played_file='$_last_played_file'
	  where vob_source='$_vob_source';"
    _out=$(_mysql_exec "$_query")
    echo "$_last_played_file"
fi


}
######################################################
function _episode_list {
    ls *vob *avi *iso 2> /dev/null \
	| egrep -v '000'  \
	| grep -n . | sort -n
}
###-------------------------------------------------###
function _first_episode {
    _episode_list | sed 's/^[0-9]*://g' | head -1
}
###-------------------------------------------------###
function _max_episode_number {
    _episode_list | sed 's/:.*//g' | tail -1 
}
###-------------------------------------------------###
function _last_episode_watched {
    ###_out=$(cat $LAST)
    _out=$(_get_last_played "$VOB_SOURCE")

    _out=$(_episode_list | grep ":$_out$" | sed 's/:.*//g' )

    if [ "$_out" = "" ]; then
	_out=99999
    fi

    echo $_out
}
###-------------------------------------------------###
function _current_episode {
    next=$(_last_episode_watched)
    next=$(_episode_list | grep "^$next:" | sed 's/^[0-9]*://g' )
    echo $next
}
###-------------------------------------------------###
function _next_episode {

    last=$(_last_episode_watched)
    max=$(_max_episode_number)

    if [ $last -ge $max ]; then
	next=1
    else 
	next=$(expr $last + 1 )
    fi

    next=$(_episode_list | grep "^$next:" | sed 's/^[0-9]*://g' )
    echo $next
}
######################################################
function _episode_count {
    _episode_list | tail -1 | sed 's/:.*//g' 
}
###########################################
function _random_episode {

_MAX_RAND=32767
_EPISODES=$(_episode_count)

_rep=$(expr $RANDOM % $_EPISODES)
#echo $_rep
_episode_list | grep "^$_rep:" | sed 's/^.*://g' 
}
############################################
function _build_random_playlist {
out="$HOME/z+RandomEpisodes.m3u"
cp /dev/null $out

_size=3
n=0
while [ $n -le $_size ]; do
    _ep=$(_random_episode)
    if [ "$_ep" != ""  ]; then
	echo "$path/$_ep" >> $out
    fi
    n=$(expr $n + 1)
done

echo $out
}
#############################################

########################################################################
########################################################################
########################################################################

###--------------- Normal file processing ------------------###
###--------------- Argument processing ---------------------###
file=$1
type=$2

path=$(echo $file | grep '\/' | sed 's/\/[^\/]*$//g')
file=$(echo $file | sed 's/.*[\/]//g')
ext=$(echo $file | sed 's/.*[.]//g' | tr [a-z] [A-Z] )

if [ "$path" = "" ]; then
    path=$PWD
fi

VOB_SOURCE=$path


options="--hide-gui --no-splash --stdctl -f"
options=""

if [ "$type" = "MythTV" ]; then
    options="--hide-gui --no-splash --stdctl -f "
    options=" -pfhq --no-splash "
fi

if [ "$type" = "mythtv" ]; then
    options="--hide-gui --no-splash --stdctl -f "
    options=" -pfhq --no-splash "
fi

###-------------- Control file processing ------------------###
###--------------- Argument processing ---------------------###
file=$1

ACTION=default
FILETYPE=$( file $file | sed 's/.*: //g' | sed 's/,.*//g' )

###if [ "$ext" = "VOB" ]; then ### Only fake out control files for vobs

    if [ "$FILETYPE" = "ASCII text" ]; then
	echo "This is a control file, not real data!"

	ACTION=$(cat $file | grep ACTION | sed 's/.*=//g')
	VOB_SOURCE=$(cat $file | grep VOB_SOURCE | sed 's/.*=//g')

	path=$VOB_SOURCE
    fi

###fi

echo "<input> $file"

###---------------------------------------------------------###

echo "<path>$path <vob_source>$VOB_SOURCE"

_get_last_played "$VOB_SOURCE"

###--------------- Argument processing ---------------------###

PREFIX=$(ls *vob *avi *iso 2> /dev/null | sed 's/_.*//g' | sort -u )
METADATA=$HOME/.xine-wrapper/$path
mkdir -p $METADATA
LAST=$METADATA/.last-file-played

cd $VOB_SOURCE

################################################################
################################################################
################################################################


#echo "_episode_list()"
#_episode_list
this_avi=$(echo "$1" | sed 's/.*\///g' )
### echo "<Previous> $(cat $LAST)"

case $ACTION in 
    first) file=$(_first_episode) ;;
    next)  file=$(_next_episode) ;;
    current) file=$(_current_episode);;
    previous) file=$(_current_episode);;
    random_list) file=$(_build_random_playlist);path=$HOME  ;;
    random) file=$(_random_episode)  ;;
    play) path=$VOB_SOURCE; file=$this_avi;;
    web) path=""; file=$VOB_SOURCE ;
         echo "xine $file $options"
         xine $file $options
         exit
	 ;;
    *);;
esac

echo "FILE $file "

if [ "$file" = "" ]; then
    file=$(_first_episode)
fi

###--- Get the extension of the final playback file ---###
ext=$(echo $file | sed 's/.*[.]//g' | tr [a-z] [A-Z] )
file=$(echo $file | sed 's/.*\///g' )
echo $path $file $ext


###-------------- Play the file ---------###

###----------------------------------- Force correct aspect ratio ----------###

MP_DATA=$(mplayer -identify -frames 0 \
    -vc null -vo null -ao null $path/$file \
    | tr ' ' '\n' | grep ID )

MP_ASPECT=$( echo "$MP_DATA" | tr ' ' '\n' \
    | grep "ID_VIDEO_ASPECT=" | sort -u \
    | sed 's/ID_VIDEO_ASPECT=//g')


MP_HEIGHT=$( echo "$MP_DATA" | tr ' ' '\n' \
    | grep "ID_VIDEO_HEIGHT=" | sort -u \
    | sed 's/ID_VIDEO_HEIGHT=//g')


MP_WIDTH=$( echo "$MP_DATA" | tr ' ' '\n' \
    | grep "ID_VIDEO_WIDTH=" | sort -u \
    | sed 's/ID_VIDEO_WIDTH=//g')

MP_ASPECT2=$(echo "scale=2; $MP_WIDTH / $MP_HEIGHT" | bc)

echo $MP_ASPECT $MP_HEIGHT $MP_WIDTH $MP_ASPECT2



if [ "$MP_ASPECT" = "1.33" ]; then
    OPT_ASPECT="-r 4:3"
elif [ "$MP_ASPECT" = "1.3333" ]; then
    OPT_ASPECT="-r 4:3"
elif [ "$MP_ASPECT2" = "1.77" ]; then
    OPT_ASPECT="-r anamorphic"
else
    OPT_ASPECT="" 
fi

echo "<MP_ASPECT> [$MP_ASPECT]"
echo "<OPT_ASPECT> $OPT_ASPECT"


_log_last_played_start "$VOB_SOURCE" "$file"


if [ "$ext" = "AVI" ]; then
    options=" $options $OPT_ASPECT "
fi
###----------------------------------- Force correct aspect ratio ----------###

if [ "$ext" = "ISO" ]; then
    if [ "$DISPLAY" != "" ]; then
	xine dvd://$path/$file/ $options
    fi
else
    if [ "$DISPLAY" != "" ]; then
	echo "Running xine @ $(date)..."
        if [ "$path" != "" ]; then
	    echo "	xine $path/$file $options"
	    xine $path/$file $options
        else
	    echo "	xine $file $options"
	    xine $file $options
        fi
    else
	echo "DISPLAY not set!"
    fi
fi

_log_last_played_stop "$VOB_SOURCE" "$file"

###-------------- Play the file ---------###

echo "db last file played -> "
_set_last_played "$VOB_SOURCE" "$file"

### Record the last show watched ###
echo $file > $LAST
### Record the last show watched ###


cat $LAST



More information about the mythtv-users mailing list