summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/myth2mkv
diff options
context:
space:
mode:
authorBritney Fransen <brfransen@gmail.com>2014-02-11 21:31:51 (GMT)
committerBritney Fransen <brfransen@gmail.com>2014-02-11 21:31:51 (GMT)
commitdd0d1371a1ef3b0a5a71b32721b9cef2277d7caa (patch)
treee845fd741365d04983f7c349e5248e8e5799c90a /abs/core/LinHES-system/myth2mkv
parent73e217800ce2ebd6e64ae54db7f54c386f047cff (diff)
downloadlinhes_pkgbuild-dd0d1371a1ef3b0a5a71b32721b9cef2277d7caa.zip
linhes_pkgbuild-dd0d1371a1ef3b0a5a71b32721b9cef2277d7caa.tar.gz
linhes_pkgbuild-dd0d1371a1ef3b0a5a71b32721b9cef2277d7caa.tar.bz2
LinHES-system: myth2mkv: use jobqueue_helper.py for myth db access. refs #958
jobqueue_helper.py: initial inclusion.
Diffstat (limited to 'abs/core/LinHES-system/myth2mkv')
-rw-r--r--abs/core/LinHES-system/myth2mkv105
1 files changed, 69 insertions, 36 deletions
diff --git a/abs/core/LinHES-system/myth2mkv b/abs/core/LinHES-system/myth2mkv
index aedccff..1352476 100644
--- a/abs/core/LinHES-system/myth2mkv
+++ b/abs/core/LinHES-system/myth2mkv
@@ -2,13 +2,14 @@
#
# Convert video to AVC-1 / h264
#
-# version 0.25-004
+# version 0.27-001
#
# Prerequisites:
-# - mythtv >= 0.25
+# - mythtv >= 0.27
# - handbrake-cli
# - mplayer
# - mkvtoolnix
+# - jobqueue_helper.py
#
# Arguments
# $1 must be the directory/file of the recording
@@ -20,7 +21,9 @@
# $7 must be quality of encode
#
# As a MythTV user job:
-# myth2mkv "%DIR%/%FILE%" "%CHANID%" "%STARTTIME%" "%TITLE%" "%SUBTITLE%" "%JOBID%" HQ|MQ|LQ
+# myth2mkv "%DIR%/%FILE%" "%CHANID%" "%STARTTIME%" "%TITLE%" "%SUBTITLE%" "%JOBID%" "HP|HQ|MQ|LQ"
+# Select only 1 quality setting
+# HP is similar to the HandBrake built-in preset High Profile
########################
# #
@@ -47,12 +50,13 @@ TUNING=""
# Crop 160 pixels off the left and right for 4:3 image in 1280x720 frame
# <T:B:L:R>
# i.e. 0:0:240:240
-# Default: In HQ: CROP="0:0:0:0" (no cropping).
+# Default: In HP and HQ: CROP="0:0:0:0" (no cropping).
# IN MQ and LQ: autocrop.
CROP=""
# Force custom output resolution.
# Default: Keep same resolution as input file (less any cropping).
+# The HP quality setting always keeps the same resolution as the input file.
WIDTH=""
HEIGHT=""
@@ -69,15 +73,6 @@ DEINT="G"
# #
############################
-if [[ -e $HOME/.mythtv/mysql.txt ]] ; then
- . $HOME/.mythtv/mysql.txt
-else
- DBHostName=${DBHostName:-"localhost"}
- DBUserName=${DBUserName:-"mythtv"}
- DBPassword=${DBPassword:-"mythtv"}
- DBName=${DBName:-"mythconverg"}
-fi
-
if [[ ! -d ${TMPDIR} ]] ; then
mkdir -p ${TMPDIR}
fi
@@ -91,8 +86,7 @@ update_comment()
# Arg_1 = COMMENT
{
if [ ${NO_JOBID} -eq 0 ]; then
- SQL_CMD="update jobqueue set comment=\"${1}\" where id=\"${JOBID}\";"
- `${MYSQLCMD} "${SQL_CMD}"`
+ `jobqueue_helper.py -j ${JOBID} -cs "${1}"`
fi
}
@@ -101,17 +95,16 @@ check_background_progress()
{
while [ `tail -2 ${STATUSFILE} | grep -c "^HandBrake has exited"` = 0 ]
do
- sleep 10
+ sleep 15
check_myth_jobcmds
- pass=`tail -1 ${STATUSFILE} | egrep -o -e 'task [0-9]' | tail -1 | sed 's/task\ //g'`
+ pass=`tail -1 ${STATUSFILE} | egrep -o -e 'task [0-9] of [0-9], ' | tail -1 | sed 's/task\ /Pass\ /g'`
prog_percent=`tail -1 ${STATUSFILE} | egrep -o -e '[0-9]*\.[0-9]. %' | tail -1 | sed 's/\ %//g'`
current_FPS=`tail -1 ${STATUSFILE} | egrep -o -e 'avg [0-9.]*\.[0-9]* fps' | tail -1 | sed -e 's/avg\ //g' -e 's/\ fps//g'`
current_ETA=`tail -1 ${STATUSFILE} | egrep -o -e 'ETA [0-9.][0-9.]h[0-9.][0-9.]m[0-9.][0-9.]s' | tail -1`
if [ -n "$prog_percent" ]; then
- echo "Pass ${pass}, ${prog_percent}% @ ${current_FPS} fps. ${current_ETA}"
- update_comment "Pass ${pass} of 2, ${prog_percent}% @ ${current_FPS} fps. ${current_ETA}"
+ echo "${pass}${prog_percent}% @ ${current_FPS} fps. ${current_ETA}"
+ update_comment "${pass}${prog_percent}% @ ${current_FPS} fps. ${current_ETA}"
fi
- sleep 10
done
}
@@ -119,24 +112,24 @@ check_myth_jobcmds()
# check the myth database for stop pause or resume commands
{
if [[ ${NO_JOBID} -eq 0 ]] ; then
- CURRENT_CMD=`${MYSQLCMD} "select cmds from jobqueue where id = \"${JOBID}\";"`
+ CURRENT_CMD=`jobqueue_helper.py -m "select cmds from jobqueue where id = ${JOBID}"`
case "${CURRENT_CMD}" in
# JOB_RUN
0) ;;
# JOB_PAUSE
- 1) `${MYSQLCMD} "update jobqueue set status=\"6\" where id=\"${JOBID}\";"`
+ 1) `jobqueue_helper.py -j ${JOBID} -ss 6`
kill -s STOP ${handbrake_pid} ;;
# JOB_RESUME
- 2) `${MYSQLCMD} "update jobqueue set status=\"4\" where id=\"${JOBID}\";"`
- `${MYSQLCMD} "update jobqueue set cmds=\"0\" where id=\"${JOBID}\";"`
+ 2) `jobqueue_helper.py -j ${JOBID} -ss 4`
+ `jobqueue_helper.py -j ${JOBID} -cmds 0`
kill -s CONT ${handbrake_pid} ;;
# JOB_STOP
- 4) `${MYSQLCMD} "update jobqueue set status=\"5\" where id=\"${JOBID}\";"`
- `${MYSQLCMD} "update jobqueue set cmds=\"0\" where id=\"${JOBID}\";"`
+ 4) `jobqueue_helper.py -j ${JOBID} -ss 5`
+ `jobqueue_helper.py -j ${JOBID} -cmds 0`
kill -9 ${handbrake_pid} ${command_pid}
clean_up_files
echo "Encode Cancelled" >> ${LOGFILE}
- `${MYSQLCMD} "update jobqueue set status=\"320\" where id=\"${JOBID}\";"`
+ `jobqueue_helper.py -j ${JOBID} -ss 320`
exit ;;
esac
fi
@@ -200,7 +193,14 @@ if [[ -n ${HEIGHT} ]] ; then
HEIGHT="-l ${HEIGHT} -Y ${HEIGHT}"
fi
-if [[ ${QUALITY} = HQ ]] ; then
+if [[ ${QUALITY} = HP ]] ; then
+ if [[ -n ${CROP} ]] ; then
+ CROP="--crop ${CROP}"
+ else
+ CROP="--crop 0:0:0:0 --strict-anamorphic"
+ fi
+ HB_OPTS="-o ${TMPFILE} -e x264 ${TUNING} -q 20.0 -a 1,1 -E copy:ac3,faac -B 160,160 -6 dpl2,auto -R Auto,Auto -D 0.0,0.0 --audio-copy-mask aac,ac3,dtshd,dts,mp3 --audio-fallback ffac3 -f mkv --decomb --loose-anamorphic --modulus 2 -m --x264-preset medium --h264-profile high --h264-level 4.1 ${CROP} -s 1"
+elif [[ ${QUALITY} = HQ ]] ; then
if [[ -n ${CROP} ]] ; then
CROP="--crop ${CROP}"
else
@@ -260,10 +260,18 @@ echo " <Simple>" >> "${TAG_FILE}"
echo " <Name>DATE_RELEASED</Name>" >> "${TAG_FILE}"
echo " <String>${OAD}</String>" >> "${TAG_FILE}"
echo " </Simple>" >> "${TAG_FILE}"
+echo " <Simple>" >> "${TAG_FILE}"
+echo " <Name>SEASON</Name>" >> "${TAG_FILE}"
+echo " <String>${SEASON}</String>" >> "${TAG_FILE}"
+echo " </Simple>" >> "${TAG_FILE}"
+echo " <Simple>" >> "${TAG_FILE}"
+echo " <Name>EPISODE</Name>" >> "${TAG_FILE}"
+echo " <String>${EPISODE}</String>" >> "${TAG_FILE}"
+echo " </Simple>" >> "${TAG_FILE}"
echo " </Simple>" >> "${TAG_FILE}"
echo " </Simple>" >> "${TAG_FILE}"
echo " <Simple>" >> "${TAG_FILE}"
-echo " <Name>ENCODER</Name>" >> "${TAG_FILE}"
+echo " <Name>ENCODED_BY</Name>" >> "${TAG_FILE}"
echo " <String>HandBrakeCLI ${HBCLIVER}</String>" >> "${TAG_FILE}"
echo " </Simple>" >> "${TAG_FILE}"
echo " <Simple>" >> "${TAG_FILE}"
@@ -308,9 +316,12 @@ STATUSFILE=/tmp/${TMPNAME}-status.log
HB_RETURN_CODE=/tmp/${TMPNAME}-hb_return_code
IDFILE=/tmp/${TMPNAME}-id.txt
TAG_FILE=/tmp/${TMPNAME}.xml
-MYSQLCMD="mysql -B --skip-column-names -u ${DBUserName} -p${DBPassword} -h ${DBHostName} -D ${DBName} -e"
-OAD=`${MYSQLCMD} "select originalairdate from recorded where basename LIKE '${BASE}';"`
-DESCR=`${MYSQLCMD} "select description from recorded where basename LIKE '${BASE}';" | sed 's/\&/and/g'`
+SEASON=`jobqueue_helper.py -m "select season from recorded where basename LIKE '${BASE}'"`
+SEASON=`printf "%02d" $SEASON`
+EPISODE=`jobqueue_helper.py -m "select episode from recorded where basename LIKE '${BASE}'"`
+EPISODE=`printf "%02d" $EPISODE`
+OAD=`jobqueue_helper.py -m "select originalairdate from recorded where basename LIKE '${BASE}'"`
+DESCR=`jobqueue_helper.py -m "select description from recorded where basename LIKE '${BASE}'" | sed 's/\&/and/g'`
USER=`whoami`
# check if %JOBID% is passed from command line
@@ -392,7 +403,11 @@ fi
# make output filename unique and do not clobber an existing file
# Build a final file name
-FILE=$( echo "${TITLE,,} ${OAD} ${SUBTITLE,,}" | tr -d [:punct:] | tr [:blank:] "_" | tr -s "_" )
+if [[ $SEASON != "00" && $EPISODE != "00" ]]; then
+ FILE=$( echo "${TITLE,,} s${SEASON}e${EPISODE} ${SUBTITLE,,}" | tr -d [:punct:] | tr [:blank:] "_" | tr -s "_" )
+else
+ FILE=$( echo "${TITLE,,} ${OAD} ${SUBTITLE,,}" | tr -d [:punct:] | tr [:blank:] "_" | tr -s "_" )
+fi
OUTPUTFILE="${OUTDIR}/${FILE}.mkv"
i=1
while [ -e "${OUTPUTFILE}" ]
@@ -422,9 +437,27 @@ if [ ${ERROR} -eq 0 ]; then
seconds=$((seconds % 3600))
minutes=$((seconds / 60))
seconds=$((seconds % 60))
- echo "Encoding took ${hours} hour\(s\) ${minutes} minute\(s\) ${seconds} second\(s\) @ ${current_FPS} fps." >> ${LOGFILE}
- `${MYSQLCMD} "update jobqueue set status = \"272\" where id = \"${JOBID}\";"`
- update_comment "Encode Successful. Encoding Time: ${hours} hour\(s\) ${minutes} minute\(s\) ${seconds} second\(s\)"
+ if [ $hours -eq 0 ]; then
+ hours=""
+ elif [ $hours -eq 1 ]; then
+ hours=" $hours hour"
+ else
+ hours=" $hours hours"
+ fi
+ if [ $minutes -eq 1 ]; then
+ minutes="$minutes minute"
+ else
+ minutes="$minutes minutes"
+ fi
+ if [ $seconds -eq 1 ]; then
+ seconds="$seconds second"
+ else
+ seconds="$seconds seconds"
+ fi
+
+ echo "Encoding took${hours} ${minutes} ${seconds} @ ${current_FPS} fps." >> ${LOGFILE}
+ `jobqueue_helper.py -j ${JOBID} -ss 272`
+ update_comment "Encode Successful. Encoding Time:${hours} ${minutes} ${seconds}"
else
echo "ERROR: ${ERROR}" >> ${LOGFILE}
fi