Difference between revisions of "User talk:Jedidiah"
(→Ripping Scripts (mythvideo)) |
(→Ripping Scripts (mythvideo)) |
||
Line 640: | Line 640: | ||
eject | eject | ||
+ | |||
+ | |||
+ | vob_rename.sh | ||
+ | |||
+ | #!/bin/bash | ||
+ | |||
+ | ### Update the variables in this top section to match your environment. | ||
+ | |||
+ | MANIFEST=/home/jedi/manifest.txt | ||
+ | RIPS=/home/media/DVD-RIP | ||
+ | |||
+ | |||
+ | ###cd $RIPS, will use $PWD instead | ||
+ | BUFFER=$(cat $MANIFEST | tr ' ' '_' | sed 's/^PREFIX~.*//g' | grep . ) | ||
+ | |||
+ | ####################################################################### | ||
+ | function _get_prefix { | ||
+ | cat $MANIFEST | grep "^PREFIX~$1:" | sed 's/.*://g' | ||
+ | } | ||
+ | ####################################################################### | ||
+ | |||
+ | VOBS=$( ls *vob ) | ||
+ | #echo "<vobs> $VOBS" | ||
+ | |||
+ | for vob in $VOBS; do | ||
+ | infile="$vob" | ||
+ | |||
+ | key=$(echo $vob | sed 's/.vob$//g' | tr '.' ':' ) | ||
+ | echo "<vob>$vob <key>$key" | ||
+ | |||
+ | ###------------- If we find a match, translate --------### | ||
+ | record=$(cat $MANIFEST | grep "^$key") | ||
+ | if [ "$record" != "" ]; then | ||
+ | echo "<record>$record" | ||
+ | |||
+ | line="$record" | ||
+ | line=$(echo $line | tr '~' '_' ) | ||
+ | disk=$(echo $line | awk -F ':' '{print $1}') | ||
+ | title=$(echo $line | awk -F ':' '{print $2}') | ||
+ | episode=$(echo $line | awk -F ':' '{print $3}') | ||
+ | label=$(echo $line | awk -F ':' '{print $4}') | ||
+ | |||
+ | PRE=$(_get_prefix $disk) | ||
+ | |||
+ | newfile="${PRE}_${episode}-${label}.vob" | ||
+ | newfile=$(echo "$newfile" | tr ' ' '_' ) | ||
+ | |||
+ | |||
+ | flag=$(ps -aef | grep $infile | egrep -v grep | wc -l) | ||
+ | if [ $flag -eq 0 ]; then | ||
+ | echo "mv $infile $newfile" | ||
+ | mv "$infile" "$newfile" | ||
+ | else | ||
+ | echo "SKIPPING $infile. Being read by another process." | ||
+ | fi | ||
+ | fi | ||
+ | ###------------- If we find a match, translate --------### | ||
+ | |||
+ | done | ||
+ | |||
+ | |||
+ | exit | ||
+ | ############################################################### | ||
+ | ### | ||
+ | ### | ||
+ | ### | ||
+ | ############################################################### | ||
+ | |||
+ | |||
+ | |||
+ | |||
manifest.txt | manifest.txt |
Latest revision as of 13:19, 11 March 2009
Contents
Personal Use Scripts
Transcoding Scripts (mythvideo)
Each of these has the same basic behaivor. Codec options are encoded in shell variables in the script. So there is some flexibility but for the most part the typical case options for each use case is built into the script and doesn't need to be thought about.
Each script can either take a single argument or run with no arguments.
If run with no arguments, the script will try to convert all vob files in the current directory. If you specify a file on the commandline, it will try to process that file.
The script will try to determine if the target file already exists and skip it if does.
Each of these scripts is essentially the same master script that has been adapted for different runtime options.
convert-shows.sh
Convert DVD extracted content to h264 (TV shows):
This originally started out as a divx script. Initially divx with a bitrate setting of 1500 seemed to be "good enough". However, I eventually ran into a Series for which this didn't hold true. Rather than have multiple scripts I decided to start doing all TV shows as h264.
Initially I only used h264 for feature films.
Another evolution of this script is preservation of the original soundtrack. Feature films always created this problem of muted audio when converting from 5.1 to stereo. I had used the amplification settings in the lame options but found this didn't always work.
I will probably make this change for my movie transcoding script as well.
#!/bin/bash if [ "$1" != "" ]; then FROM="$1" else FROM=$( ls *vob ) fi CROP_ME="TRUE" CROP_ME="FALSE" cp /dev/null convert.log ##################################################################### ###---------------------------------------------------------------### ###--- xvid defaults OPTIONS="-xvidencopts bitrate=800" MAIN_OPTS="-ovc xvid -oac mp3lame -alang en -slang en" ###--- h.264 high quality BITRATE=800 BITRATE=1200 BITRATE=1500 ### subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b ### subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b ### subq=4:bframes=2:b_pyramid:weight_b ###OPTIONS="-x264encopts subq=6:4x4mv:8x8dct:me=3:frameref=5:bframes=3:b_pyramid:weight_b:bitrate=$BITRATE " ### h264 High Quality options, 2 pass ### This is the default setting X264_PASS1="-ovc x264 -x264encopts subq=4:bframes=4:b_pyramid:weight_b:pass=1:psnr:bitrate=$BITRATE:turbo=1" X264_PASS2="-ovc x264 -x264encopts subq=5:partitions=4x4:8x8dct:frameref=3:me=hex:bframes=4:b_pyramid:pass=2:psnr:bitrate=$BITRATE" ### h264 basic options, 1 pass ### This is for problem content like Forever Knight #X264_PASS1="" #X264_PASS2="-ovc x264 -x264encopts bitrate=$BITRATE" ##X264_PASS2="-ovc x264 " CROP_OPTS=" -vf crop=720:360 -lavcopts aspect=16/9" LANG="-alang en -slang en -aid 128" MP3_AMP=":vol=8" MP3_AMP=":vol=6" MP3_AMP="" MP3_OPTS="-oac mp3lame -lameopts br=128${MP3_AMP}" MP3_OPTS="-oac copy" OPTIONS="" ###---------------------------------------------------------------### ##################################################################### for from in $FROM; do echo "Converting $from..." flag=$(file $from | sed 's/.*: //g' | grep ^MPEG | wc -l) if [ $flag -eq 1 ]; then ####---- Create the destination filename ----#### to=$( echo $from | sed 's/[.]vob$/.avi/g' ) ######################################################### ###---------------------------------------------------### flag=$(echo "$EXCLUDE" | tr ' ' '\n' | grep $from | wc -l ) exclude=0 ###---------------------------------------------------### if [ $flag -gt 0 ]; then echo "$to" echo "Source File on Exclusion List! Skipping..." exclude=1 fi ###---------------------------------------------------### if [ -f $to ]; then echo "$to" echo "Destination file already exists! Skipping..." exclude=1 fi if [ -f x264/$to ]; then echo "x264/$to" echo "Destination file already exists! Skipping..." exclude=1 fi ###---------------------------------------------------### ######################################################### ###################################################################### ###--- Determine if this is a letterboxed video by the filename ---### flag=$(echo "$from" | grep 'LB.vob' | wc -l ) echo "<crop_flag> $flag" if [ $flag -eq 1 ]; then CROP=" -vf crop=720:360 -lavcopts aspect=16/9" OPTIONS="$CROP" else OPTIONS="" CROP="" fi ###--- Determine if this is a letterboxed video by the filename ---### ###################################################################### ##################################################################### ###------------- Make sure we haven't converted it already -------### if [ $exclude -eq 0 ]; then echo "Converting $to..." basename=$(echo $from | sed 's/[.].*$//g' ) if [ "$X264_PASS1" != "" ]; then ###--- Pass #1 nice -20 mencoder -v $from $X264_PASS1 $OPTIONS \ -oac copy $LANG \ -o /dev/null ## -vobsubout $basename -vobsuboutindex 0 \ fi ###--- Pass #2 nice -20 mencoder -v $from $LANG \ $MP3_OPTS $X264_PASS2 $OPTIONS \ -o $to fi else echo "$from is NOT an MPEG file! Skipping..." | tee -a convert.log fi done exit nice -20 mencoder $from -o $to -oac mp3lame -ovc lavc \ -lavcopts vcodec=xvid:vpass=1:vbitrate=${BITRATE} $CROP nice -20 mencoder $from -o $to -oac mp3lame -ovc lavc \ -lavcopts vcodec=xvid:vpass=2:vbitrate=${BITRATE} $CROP
convert-movies.sh
Convert DVD extracted content to h264 (Feature Films):
This was originally a separate script because I used two different codecs to convert content that originated in Television versus feature films (35mm). Divx is good enough for most stuff made for TV and is a lot less computationally intensive.
#!/bin/bash EXCLUDE=$(cat convert-exclusions.txt) EXCLUDE=" $EXCLUDE " if [ "$1" != "" ]; then FROM="$1" else FROM=$( ls *vob | egrep -v '^a+') fi ###---------------------------------------------------------------### ###--- xvid defaults OPTIONS="-xvidencopts bitrate=800" MAIN_OPTS="-ovc xvid -oac mp3lame -alang en -slang en" ###--- h.264 high quality BITRATE=1500 OPTIONS="-x264encopts subq=6:4x4mv:8x8dct:me=3:frameref=5:bframes=3:b_pyramid:weight_b:bitrate=$BITRATE " X264_PASS1="-ovc x264 -x264encopts subq=4:bframes=4:b_pyramid:weight_b:pass=1:psnr:bitrate=$BITRATE:turbo=1" X264_PASS2="-ovc x264 -x264encopts subq=5:partitions=4x4:8x8dct:frameref=3:me=hex:bframes=4:b_pyramid:pass=2:psnr:bitrate=$BITRATE" LANG="-alang en -slang en -aid 128" MP3_OPTS="-oac mp3lame -lameopts br=128:vol=8" OPTIONS="" ###---------------------------------------------------------------### BITRATE=800 BITRATE=1200 #FROM="Girl_Interrupted.vob" for from in $FROM; do echo "Converting $from..." to=$( echo $from | sed 's/[.]vob$/.avi/g' ) flag=$(echo "$EXCLUDE" | tr ' ' '\n' | grep $from | wc -l ) exclude=0 ###---------------------------------------------------### if [ $flag -gt 0 ]; then echo "$to" echo "Source File on Exclusion List! Skipping..." exclude=1 fi ###---------------------------------------------------### if [ -f $to ]; then echo "$to" echo "Destination file already exists! Skipping..." exclude=1 fi if [ -f x264/$to ]; then echo "x264/$to" echo "Destination file already exists! Skipping..." exclude=1 fi ###---------------------------------------------------### ###------------- Make sure we haven't converted it already -------### if [ $exclude -eq 0 ]; then echo "Converting $to..." basename=$(echo $from | sed 's/[.].*$//g' ) mencoder -v $from $X264_PASS1 -oac copy $LANG \ -ofps 24000/1001 \ -vobsubout $basename -vobsuboutindex 0 \ -o /dev/null mencoder -v $from $LANG \ $MP3_OPTS $X264_PASS2 \ -ofps 24000/1001 \ -o $to fi done exit nice -20 mencoder $from -o $to -oac mp3lame -ovc lavc \ -lavcopts vcodec=xvid:vpass=1:vbitrate=${BITRATE} $CROP nice -20 mencoder $from -o $to -oac mp3lame -ovc lavc \ -lavcopts vcodec=xvid:vpass=2:vbitrate=${BITRATE} $CROP
convert-archos.sh
This script is for my Archos 605. I found that the options I had used in h264 for my feature films were not supported. This script just uses the default h264 options. Quality is degraded and files are significantly smaller.
This script will transcode to a temporary location and then copy to the Archos. This allows for more or less un-attached operation. This script will halt once it is ready to move a file into place and finds that the Archos is not plugged in.
#!/bin/bash echo "######################## convert-archos.sh #######################" ARCHOS="/media/archos/Video" TEMP="/tmp/convert-archos" mkdir -p $TEMP if [ -d $ARCHOS ]; then echo "Found Archos..." else echo "WARNING: Archos NOT MOUNTED!" fi GENRE=$( echo $PWD | sed 's/.*\///g' ) ###---------------------------### if [ "$1" != "" ]; then FROM="$*" else FROM=$( ls $PWD/*avi ) fi echo "<genre> $GENRE" echo "<from> $FROM" ###---------------------------### if [ "$2" != ]; then if [ "$3" = ]; then GENRE="$2" fi fi ###---------------------------### #FROM=$(echo "$FROM" | tr ' ' '~' ) if [ "$GENRE" = "" ]; then echo " A genre/category must be specified for this movie!" echo " Usage: $0 <movie> <genre>" exit fi ###---------------------------------------------------------------### ###--- xvid defaults OPTIONS="-xvidencopts bitrate=800" MAIN_OPTS="-ovc xvid -oac mp3lame -alang en -slang en" ###--- h.264 high quality BITRATE=1500 OPTIONS="-x264encopts subq=6:4x4mv:8x8dct:me=3:frameref=5:bframes=3:b_pyramid:weight_b:bitrate=$BITRATE " X264_PASS1="-ovc x264 -x264encopts subq=4:bframes=4:b_pyramid:weight_b:pass=1:psnr:bitrate=$BITRATE:turbo=1" X264_PASS2="-ovc x264 -x264encopts subq=5:partitions=4x4:8x8dct:frameref=3:me=hex:bframes=4:b_pyramid:pass=2:psnr:bitrate=$BITRATE" X264_SIMPLE="-ovc x264" LANG="" MP3_OPTS_AVI="-oac mp3lame -lameopts br=128" MP3_OPTS_VOB="-oac mp3lame -lameopts br=128:vol=8" OPTIONS="" ###---------------------------------------------------------------### BITRATE=800 BITRATE=1200 #FROM="Girl_Interrupted.vob" for from in $FROM; do echo "Converting $from..." from_ext=$(echo "$from" | sed 's/^.*[.]//g' | tr '[A-Z]' '[a-z]' ) to=$from ###Change path to archos device. to_file=$(echo $to | sed 's/.*\///g' | sed 's/[.][^.]*$/.avi/g' ) to_dir="/media/A605/Video/$GENRE" to="$to_dir/$to_file" flag=$(echo "$EXCLUDE" | tr ' ' '\n' | grep $from | wc -l ) exclude=0 ###---------------------------------------------------### if [ $flag -gt 0 ]; then echo "$to" echo "Source File on Exclusion List! Skipping..." exclude=1 fi ###---------------------------------------------------### if [ -f $to ]; then echo "$to" echo "Destination file already exists! Skipping..." exclude=1 fi if [ -f x264/$to ]; then echo "x264/$to" echo "Destination file already exists! Skipping..." exclude=1 fi ###---------------------------------------------------### ###------------- Make sure we haven't converted it already -------### if [ $exclude -eq 0 ]; then echo "Converting $to..." case $from_ext in vob) MP3_OPTS=$MP3_OPTS_VOB;; avi) MP3_OPTS=$MP3_OPTS_AVI;; *) MP3_OPTS=$MP3_OPTS_AVI;; esac echo "mencoder -v $from $LANG $MP3_OPTS $X264_SIMPLE -o $TEMP/$to_file" mencoder -v $from $LANG $MP3_OPTS $X264_SIMPLE -o $TEMP/$to_file ####################################################### ### Copy over the file once it is created. This may be ### tricky since the Archos can be unplugged. flag=0 while [ $flag -eq 0 ]; do ###-----------------------------------------------### if [ -d $ARCHOS ]; then echo "mv $TEMP/$to_file $to_dir/$to_file" mv $TEMP/$to_file $to_dir/$to_file flag=1 echo "rm $TEMP/$to_file" rm $TEMP/$to_file else echo " " echo "ERROR: Archos Media Player not Connected!" echo "Please re-connect Archos Media Player." select key in "Connect Archos" "QUIT" ; do echo "<key> $key" if [ "$key" = "QUIT" ]; then exit fi break; done fi ###-----------------------------------------------### done ####################################################### fi done exit
Ripping Scripts (mythvideo)
dvdrip.sh
#!/bin/bash #### Start of User modifiable script variables INPUT="/dev/scd0" INPUT="/dev/dvd" RIPS=/home/media/DVD-RIP #### End of User modifiable script variables ############################################################### ############################################################### RIP_TYPE=$1 DNAME=$2 function _usage { echo " " echo "Usage: $0 <rip_type> [disk_name]" echo "<rip_type> -> sitcom action film extras-only all" echo "sitcom -> 30 minutes per title" echo "action -> 60 minutes per title" echo "film -> 120 minutes per title" echo "extras-only -> 3 minutes per title" echo " " echo "all -> Anything between 3 and 200 minutes" echo " " } if [ "$RIP_TYPE" = "" ]; then _usage exit fi if [ -d $RIPS ]; then cd $RIPS else echo " " echo "RIPS directory [$RIPS] does not EXIST!" echo "Please reset RIPS variable in script." echo " " exit fi ############################################################### ############################################################### ###TYPE= sitcom,action,film,extras ###--- Control ripping based on expected size of shows ---### case $RIP_TYPE in "sitcom") EXPECTED_SIZE=30 MIN=$(expr $EXPECTED_SIZE '/' 2 ) MAX=$(expr $EXPECTED_SIZE '*' 2 ) ;; "action") EXPECTED_SIZE=60 MIN=$(expr $EXPECTED_SIZE '/' 2 ) MAX=$(expr $EXPECTED_SIZE '*' 2 ) ;; "film") EXPECTED_SIZE=120 MIN=$(expr $EXPECTED_SIZE '/' 2 ) MAX=$(expr $EXPECTED_SIZE '*' 2 ) ;; "all") MIN=3 MAX=200 ;; "extras-only") MIN=3 MAX=30 ;; *) _usage exit ;; esac ###--- Control ripping based on expected size of shows ---### ########################################################### ###------------- make sure there is a DVD in the drive ---### flag=$( lsdvd 2>&1 | grep "Can't open disc" | wc -l ) if [ $flag -eq 1 ]; then eject echo "Disc Not Found!" echo "Please insert a DVD. And hit enter to continue." read button fi echo "Continuing..." flag=$( lsdvd 2>&1 | grep "Can't open disc" | wc -l ) if [ $flag -eq 1 ]; then eject echo "Disc Not Found! Exiting" exit fi ###------------- make sure there is a DVD in the drive ---### echo "Getting DVD Title information..." ###------------------- Get the Title Details -------------### NAME=$(lsdvd $INPUT | grep "Disc Title" | sed 's/.*: //g') if [ "$DNAME" != "" ]; then NAME=$DNAME fi ###------------------- Get the Title Details -------------### echo "Disc Title is $NAME..." ########################################################### ###------------ Get title data --------------------------### TITLES=$(lsdvd $INPUT 2> /dev/null \ grep ':' | sed 's/Title: //g' | sed 's/, Length: /~/g' \ | sed 's/.*Longest.*//g' \ | sed 's/[.].*//g' | grep ':' \ | sed 's/:[^:]*$//g') ###------------ Get title data --------------------------### ###--- Find Titles that meet our rip criteria -----------### RIPME="" for title in $TITLES; do time=$(echo $title | sed 's/.*~//g' ) title=$(echo $title | sed 's/~.*//g' | sed 's/^0*//g' ) hour=$(echo $time | sed 's/:.*//g' ) minute=$(echo $time | sed 's/.*://g' ) minutes=$( echo " $hour * 60 + $minute " | bc ) if [ $minutes -ge $MIN ]; then if [ $minutes -le $MAX ]; then echo "Title $title should be ripped!" RIPME="$RIPME $title" else echo "Title $title is too big!" fi else echo "Title $title is too small!" fi done ###--- Find Titles that meet our rip criteria -----------### ###------------------ Rip the matching Titles -----------### echo $RIPME for title in $RIPME; do echo "mplayer -dumpstream dvd://$title -dumpfile $NAME.$title-1.vob" nice mplayer -dumpstream dvd://$title -dumpfile $NAME.$title-1.vob done ###------------------ Rip the matching Titles -----------### eject eject
vob_rename.sh
#!/bin/bash ### Update the variables in this top section to match your environment. MANIFEST=/home/jedi/manifest.txt RIPS=/home/media/DVD-RIP ###cd $RIPS, will use $PWD instead BUFFER=$(cat $MANIFEST | tr ' ' '_' | sed 's/^PREFIX~.*//g' | grep . ) ####################################################################### function _get_prefix { cat $MANIFEST | grep "^PREFIX~$1:" | sed 's/.*://g' } ####################################################################### VOBS=$( ls *vob ) #echo "<vobs> $VOBS" for vob in $VOBS; do infile="$vob" key=$(echo $vob | sed 's/.vob$//g' | tr '.' ':' ) echo "<vob>$vob <key>$key" ###------------- If we find a match, translate --------### record=$(cat $MANIFEST | grep "^$key") if [ "$record" != "" ]; then echo "<record>$record" line="$record" line=$(echo $line | tr '~' '_' ) disk=$(echo $line | awk -F ':' '{print $1}') title=$(echo $line | awk -F ':' '{print $2}') episode=$(echo $line | awk -F ':' '{print $3}') label=$(echo $line | awk -F ':' '{print $4}') PRE=$(_get_prefix $disk) newfile="${PRE}_${episode}-${label}.vob" newfile=$(echo "$newfile" | tr ' ' '_' ) flag=$(ps -aef | grep $infile | egrep -v grep | wc -l) if [ $flag -eq 0 ]; then echo "mv $infile $newfile" mv "$infile" "$newfile" else echo "SKIPPING $infile. Being read by another process." fi fi ###------------- If we find a match, translate --------### done exit ############################################################### ### ### ### ###############################################################
manifest.txt
This is the data that drives my renaming script vob_rename.sh. This file contains two types of data or "tables". First there are the dics in the form:
PREFIX~SJ_S2_D1:Street_Justice PREFIX~<disk name>:<show name> <disk name> -> the name of the disc as output by lsdvd. <show name> -> A Label of your choosing
Then there are the titles in the form:
SJ_S2_D3:1-1:210:Remember Me <disk name>:<track>:<episode number>:<title> <disk name> -> disk name from the disc list <track> -> track id spat out by my dvd rip script. <episode number> -> an episode code of your choosing. My code uses the format <season><episode>. <title> -> Show name of your choosing. I type these in from the DVD packaging.
Data Stub Creator:
If you have ripped your discs in order, this little bit of code will spit out a ready made set of blank entries for typing in your own episode names. You need to set DVD_KEY, SeriesName and Season appropriately.
n can also be set in those rare occasions where the first track in the collection is not the first episode of the season (like for example Sopranos season 6, volume 2).
function _generate { ###cd /home/media/DVD-RIP DVD_KEY="SJ_S2" SeriesName="Street_Justice" Season=2 n=1 titles=$(ls -tr *vob | egrep "$DVD_KEY" | sed 's/.vob//g' | tr '.' ':') echo $titles | tr ' ' '\n' | sed 's/:.*//g' | sort -u | sed "s/.*/PREFIX~&:$SeriesName/g" for title in $titles; do if [ $n -lt 10 ]; then tag="${Season}0${n}" else tag="${Season}${n}" fi echo "$title:$tag:" n=$(expr $n + 1 ) done } _generate
manifest.txt
function _generate { ###cd /home/media/DVD-RIP DVD_KEY="SJ_S2" SeriesName="Street_Justice" Season=2 n=1 titles=$(ls -tr *vob | egrep "$DVD_KEY" | sed 's/.vob//g' | tr '.' ':') echo $titles | tr ' ' '\n' | sed 's/:.*//g' | sort -u | sed "s/.*/PREFIX~&:$SeriesName/g" for title in $titles; do if [ $n -lt 10 ]; then tag="${Season}0${n}" else tag="${Season}${n}" fi echo "$title:$tag:" n=$(expr $n + 1 ) done } _generate #################################################################### #################################################################### #################################################################### PREFIX~SJ_S2_D1:Street_Justice PREFIX~SJ_S2_D2:Street_Justice PREFIX~SJ_S2_D3:Street_Justice PREFIX~SJ_S2_D4:Street_Justice PREFIX~SJ_S2_D5:Street_Justice SJ_S2_D1:1-1:201:Death Warmed Over SJ_S2_D1:2-1:202:Circle of Death SJ_S2_D1:3-1:203:Cross Fire SJ_S2_D1:4-1:204:Feet of Clay SJ_S2_D1:5-1:205:Each One,Teach One SJ_S2_D2:1-1:206:Country Justice SJ_S2_D2:2-1:207:Back from the Dead Again SJ_S2_D2:3-1:208:Innocent Blood SJ_S2_D2:4-1:209:Angel of Death SJ_S2_D3:1-1:210:Remember Me SJ_S2_D3:2-1:211:Black or Blue SJ_S2_D3:3-1:212:Bitter Fruit SJ_S2_D3:4-1:213:A Sense of Duty SJ_S2_D3:5-1:214:Obsession SJ_S2_D4:1-1:215:Honor and Trust SJ_S2_D4:2-1:216:On My Honor SJ_S2_D4:3-1:217:The Cost of Peace SJ_S2_D4:4-1:218:Countdown SJ_S2_D5:1-1:219:Hello Again SJ_S2_D5:2-1:220:The Wall SJ_S2_D5:3-1:221:My Brother's Keeper SJ_S2_D5:4-1:222:Desperate
Metadata Scripts (mythvideo)
scan-incoming.sh
This includes accomodations adding and removing files from the videometadata table as well as managing symbolic links for those of us that have multiple filesystems masquerading as one.
#!/bin/bash ######################################################################## DVD="/home/media/DVD" GENRES="Action Anime Childrens Comedy DarkComedy Drama Fantasy Horror James_Bond Marilyn_Monroe Music Musical Sci-Fi Thriller Western " DEST="/home/media/DVD" VOLUMES=".Volume01 .Volume02 .Volume03 .Volume04" COVER_DIR="/home/media/Posters" MYTV_DIR="/home/media/DVD/VirtualTV" INCOMING="Incoming" INCOMING="$INCOMING Wild_Wild_West James_Bond Childrens \ Drama Comedy Action" INCOMING="Comedy" INCOMING="Incoming $GENRES ALF" if [ "$1" != "" ]; then INCOMING="$*" fi ######################################################################## ######################################################################## ######################################################################## 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 _scan_incoming { for incoming in $INCOMING; do echo "Scanning $incoming..." mkdir -p $DVD/$incoming cd $DVD/$incoming FILES="" FILES=$(find . -ctime -7 | egrep 'flv$|avi$|mpg$|mov$|vob$' ) for file in $FILES; do file=$(echo $file | sed 's/^..//g') file="$DVD/$incoming/$file" file=$(echo "$file" | sed "s/'//g" ) #echo "$file" genre=$(echo "$file" | sed 's/.*\/DVD[^\/]*\///g' | sed 's/\/.*//g' ) is_genre=$(echo "$GENRES" | tr '\n' ' ' | grep "$genre" | wc -l ) query="select count(*) from videometadata where filename='$file';" flag=$(_mysql_exec "$query" | tail -1 ) if [ $flag -gt 0 ]; then echo "File already added! [$file]" > /dev/null else echo "Need to Add file!" if [ $is_genre -eq 0 ]; then ###------------- for TV --------------------------### _cover=$(echo "$file" | sed 's/^.*\///g' \ | sed 's/[0-9][0-9]-.*//g' ) _cover="$COVER_DIR/${_cover}-thumb.jpg" else ###------------ for Movies ----------------------### _cover=$(echo "$file" | sed 's/[.][^.]*$//g' | sed 's/.*\///g') _cover="$COVER_DIR/${_cover}-poster.jpg" fi _name=$(echo "$file" | sed 's/^.*\///g' \ | sed 's/[_]/ /g' | sed 's/[.][^.]*$//g' ) query="insert into videometadata (title,filename,coverfile,showlevel) values('$_name','$file','$_cover',1);" echo "$query" _mysql_exec "$query" fi done done ###/* next incoming */ } ###################################################################### function _check_videos { query="select filename from videometadata;" echo "Checking Files..." FILES=$( _mysql_exec "$query" | tr ' ' '~' | egrep -v '^filename$' ) for file in $FILES; do file=$(echo $file | tr '~' ' ') #echo "$file" if [ -f $file ]; then foo="bar" else echo "$file is MISSING!" key=$(echo "$file" | sed "s/'//g" ) query="delete from videometadata where filename='$key';" echo "$query" _mysql_exec "$query" fi done } ############################################################ function _makelinks { echo "Building Directories..." for vol in $VOLUMES; do cd $vol DIRS=$(find -type d | egrep -v 'lost.found|DVD-RIP|BACKUP' | sed 's/^..//g' ) for dir in $DIRS; do source="$DEST/$vol/$dir" target="$DEST/$dir" if [ -d $target ]; then echo "$target already exists!" > /dev/null ###rm $target/*000+*vob ###echo "cp $source/*000+*vob $target" ###cp $source/*000+*vob $target else echo "mkdir /home/media/DVD/$dir" mkdir /home/media/DVD/$dir cp $source/*000+*vob $target fi done cd .. done echo "Creating links to files..." for vol in $VOLUMES; do cd $vol FILES=$(find -type f | egrep -v 'lost.found|DVD-RIP|BACKUP' \ | egrep -v 'tar$|sh$' \ | sed 's/^..//g' \ | tr ' ' '~' ) for file in $FILES; do file=$(echo $file | tr '~' ' ' ) target="$DEST/$file" source="$DEST/$vol/$file" if [ -f "$target" ]; then echo "$target already exists!" > /dev/null else echo "ln -sf $source $target" ln -sf "$source" "$target" fi done cd .. done } ############################################################ function _linkcheck { cd $DVD LINKS=$(find . -type l | tr ' ' '~' | egrep -v [.]Volume | sed 's/^..//g' ) echo "Checking files..." for link in $LINKS; do link=$(echo $link | tr '~' ' ' ) if [ -f "$link" ]; then foo="bar" elif [ -d "$link" ]; then foo="bar" elif [ -h "$link" ]; then echo "File $link is MISSING!" echo "Removing..." echo "rm $DVD/$link" rm "$DVD/$link" else echo "File $link is BOGUS!" > /dev/null fi done } ############################################################ ############################################################ ############################################################ _makelinks _linkcheck _check_videos _scan_incoming
Feature Suggestions
1) Virtual TV -- Integrate MythTV and MythVideo so that you can pull shows from the "DVD jukebox" and make it appear as though they have been recorded. This could be used to tie into guide data and provide better quality "recordings". It would also be cool to follow through the entire run of a show that you might have on DVD by being fed a few episodes at a time through the main recordings interface.
Removal of a virtual episode would trigger the "recording" of another one.
No need to bother remembering which 251 episodes of MASH or 78 episodes of Star Trek or 150 episodes of Bewitched you watched last.
Tracking of "last recorded" in a particular directory would also be handy. This would easily allow for "play next" functionality within mythvideo.
I already have a shell script that does this. (xine-wrapper.sh)
Minor Gripes:
1) Any parts of the UI that require typing (IOW, a keyboard) probably need reworked.
In particular, I would like to see the ability to select from currently used media viewers in the MythVideo filetypes menu. Rather than typing something over, it would be cool if you could select from a drop down list of every other option that's already in place.
That list might look something like.
internal xine %s mplayer %s /usr/local/bin/xine-wrapper.sh %s mythtv
Using this sort of idea to trigger a single use custom command for a file from within the mythvideo play menus would be handy too. It would be nice to have the ability to try out different playback options without going to a lot of trouble to do so.
2) Emulating the Tivo method for searching show titles would be handy too. Doing a fullscan on the programs table anytime you want to find a new show to record is not really very scalable. That really bogs down on a poorly tweaked mysql setup.
3) Browsing in mythvideo is slow. It scans the entire directory tree on start. Perhaps it should only scan each directory as it descends into it and not do any recursion. Per directory configuration might also be useful. I have some directories that have dynamic content but most are pretty static.
Also, during the directory tree search it doesn't provide any user feedback that it's running. In general, a sort of "work in progress" dialog would be helpful. It would be comforting to be sure that MythTV hasn't suddenly died.