From 4aa9339bc64b5477b022a786670be5437815b90b Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Mon, 16 Dec 2013 17:45:45 -0600
Subject: mythtv & mythplugins: update to latest fixes. refs #933.

update mythburn.py aspect ratio patch for .27
---
 abs/core/mythtv/stable-0.27/git_src/git_hash       |   2 +-
 abs/core/mythtv/stable-0.27/mythplugins/PKGBUILD   |   7 +-
 .../mythplugins/mythburn.py-aspectratio.patch      | 138 +++++++++++++++++++++
 abs/core/mythtv/stable-0.27/mythtv/PKGBUILD        |   2 +-
 4 files changed, 144 insertions(+), 5 deletions(-)
 create mode 100644 abs/core/mythtv/stable-0.27/mythplugins/mythburn.py-aspectratio.patch

diff --git a/abs/core/mythtv/stable-0.27/git_src/git_hash b/abs/core/mythtv/stable-0.27/git_src/git_hash
index 53e3e8d..fd8badd 100644
--- a/abs/core/mythtv/stable-0.27/git_src/git_hash
+++ b/abs/core/mythtv/stable-0.27/git_src/git_hash
@@ -1 +1 @@
-f7852552a089a87d7dd53b5da59958205fbae6fd
+39171be37ab8d63f0f44e5dbd5a78ca6893ceafa
diff --git a/abs/core/mythtv/stable-0.27/mythplugins/PKGBUILD b/abs/core/mythtv/stable-0.27/mythplugins/PKGBUILD
index 196f8be..8fe13bb 100644
--- a/abs/core/mythtv/stable-0.27/mythplugins/PKGBUILD
+++ b/abs/core/mythtv/stable-0.27/mythplugins/PKGBUILD
@@ -9,7 +9,7 @@ pkgname=('mytharchive'
          'mythweather'
          'mythzoneminder')
 pkgver=0.27
-pkgrel=6
+pkgrel=7
 arch=('i686' 'x86_64')
 url="http://www.mythtv.org"
 license=('GPL')
@@ -19,7 +19,7 @@ makedepends=('cdrkit' 'dvdauthor' 'dvd+rw-tools' 'ffmpeg' 'flac' 'libexif'
              'perl-json' 'perl-libwww' 'perl-soap-lite' 'perl-xml-sax'
              'perl-xml-simple' 'perl-xml-xpath' 'python-oauth' 'python-imaging'
              'python-pycurl' 'zlib')
-source=()
+source=('mythburn.py-aspectratio.patch')
 
 build() {
     if [ -e ${srcdir}/mythplugins ]
@@ -48,6 +48,7 @@ package_mytharchive() {
     depends=('cdrkit' 'dvdauthor' 'dvd+rw-tools' 'ffmpeg' "mythtv>=${pkgver}"
              'python-imaging')
     cd "${srcdir}/${_gitname}/${pkgbase}/mytharchive"
+    patch mythburn/scripts/mythburn.py < $srcdir/mythburn.py-aspectratio.patch || return 1
     make INSTALL_ROOT="${pkgdir}" install || return 1
 }
 
@@ -112,4 +113,4 @@ package_mythzoneminder() {
     make INSTALL_ROOT="${pkgdir}" install || return 1
 }
 
-md5sums=()
+md5sums=('e98c2a09bcb051fdde959fb4bb2e5ab2')
diff --git a/abs/core/mythtv/stable-0.27/mythplugins/mythburn.py-aspectratio.patch b/abs/core/mythtv/stable-0.27/mythplugins/mythburn.py-aspectratio.patch
new file mode 100644
index 0000000..377de95
--- /dev/null
+++ b/abs/core/mythtv/stable-0.27/mythplugins/mythburn.py-aspectratio.patch
@@ -0,0 +1,138 @@
+--- mythburn.py.orig	2013-12-16 22:41:31.532703825 +0000
++++ mythburn.py	2013-12-16 22:40:52.191109409 +0000
+@@ -98,6 +98,7 @@
+ from fcntl import ioctl
+ import CDROM
+ from shutil import copy
++from subprocess import Popen, PIPE
+ 
+ import MythTV
+ from MythTV import datetime
+@@ -440,7 +441,7 @@
+                 os.remove(os.path.join(root, name))
+ 
+ #############################################################
+-# Romoves all the objects from a directory
++# Removes all the objects from a directory
+ 
+ def deleteEverythingInFolder(folder):
+     for root, dirs, files in os.walk(folder, topdown=False):
+@@ -666,14 +667,14 @@
+ # Gets the aspect ratio of a video file from its stream info file
+ 
+ def getAspectRatioOfVideo(index):
+-    """Returns the aspect ratio of the video file (1.333, 1.778, etc)"""
++    """Returns the aspect ratio of the original video file (1.333, 1.778, etc)"""
+ 
+     #open the XML containing information about this file
+-    infoDOM = xml.dom.minidom.parse(os.path.join(getItemTempPath(index), 'streaminfo.xml'))
++    infoDOM = xml.dom.minidom.parse(os.path.join(getItemTempPath(index), 'streaminfo_orig.xml'))
+ 
+     #error out if its the wrong XML
+     if infoDOM.documentElement.tagName != "file":
+-        fatalError("Stream info file doesn't look right (%s)" % os.path.join(getItemTempPath(index), 'streaminfo.xml'))
++        fatalError("Stream info file doesn't look right (%s)" % os.path.join(getItemTempPath(index), 'streaminfo_orig.xml'))
+     video = infoDOM.getElementsByTagName("file")[0].getElementsByTagName("streams")[0].getElementsByTagName("video")[0]
+     if video.attributes["aspectratio"].value != 'N/A':
+         aspect_ratio = float(video.attributes["aspectratio"].value)
+@@ -1695,6 +1696,37 @@
+         fatalError("Failed while running mytharchivehelper to get stream information.\n"
+                    "Result: %d, Command was %s" % (result, command))
+ 
++    #open the XML containing information about this file
++    infoDOM = xml.dom.minidom.parse(xmlFilename)
++    
++    #error out if its the wrong XML
++    if infoDOM.documentElement.tagName != "file":
++        fatalError("This info file doesn't look right (%s)." % xmlFilename)
++    
++    file = infoDOM.getElementsByTagName("file")[0]
++    video = infoDOM.getElementsByTagName("file")[0].getElementsByTagName("streams")[0].getElementsByTagName("video")[0]
++    
++    #use ffmpeg to get display aspect ratio (DAR) of video
++    cmd = "mythffmpeg -i " + quoteCmdArg(file.attributes["filename"].value) + " 2>&1"
++    aspect_ratio = Popen(cmd, shell=True, stdout=PIPE).stdout.read()
++    if "DAR" in aspect_ratio:
++        #clean DAR string
++        aspect_ratio = aspect_ratio.split("DAR ")[-1].split(",")[0]
++        aspect_ratio = ''.join([c for c in aspect_ratio if c in '1234567890:']).split(":")
++    else:
++        #calculate aspect from video size
++        aspect_ratio = getVideoSize(xmlFilename)
++
++    #convert to decimal+
++    aspect_ratio = float(aspect_ratio[0]) / float(aspect_ratio[1])
++
++    write("Video %s aspect ratio is: %s" % (filename, aspect_ratio))
++
++    #set aspect ratio
++    video.setAttribute("aspectratio",str(aspect_ratio))
++    
++    WriteXMLToFile (infoDOM,xmlFilename)
++
+     # print out the streaminfo.xml file to the log
+     infoDOM = xml.dom.minidom.parse(xmlFilename)
+     write(xmlFilename + ":-\n" + infoDOM.toprettyxml("    ", ""), False)
+@@ -2010,7 +2042,7 @@
+ #############################################################
+ # Re-encodes a file to mpeg2
+ 
+-def encodeVideoToMPEG2(source, destvideofile, video, audio1, audio2, aspectratio, profile):
++def encodeVideoToMPEG2(source, destvideofile, video, folder, audio1, audio2, aspectratio, profile):
+     """Encodes an unknown video source file eg. AVI to MPEG2 video and AC3 audio, use mythffmpeg"""
+ 
+     profileNode = findEncodingProfile(profile)
+@@ -2035,6 +2067,35 @@
+             value = quoteCmdArg(destvideofile)
+         if value == "%aspect":
+             value = aspectratio
++        if value == "720x480" or value == "720x576":
++            videores, fps, videoAR = getVideoParams(folder)
++            videoWidth = int(videores.split("x")[0])
++            videoHeight = int(videores.split("x")[1])
++            
++            #add padding to correct for aspects > than 1.9:1
++            if float(videoAR) >= 1.9:
++                #check which video type and set the correct height
++                if videomode == "ntsc":
++                    videoModeHeight = 480
++                else:
++                    videoModeHeight = 576
++ 
++                #calculate the video height based on the aspect ratio of the video
++                #multiply by 1.185 to compensate for dvds non-square pixels
++                calVideoHeight = int(round((720 / float(videoAR)) * 1.185))
++                if calVideoHeight % 2 == 1:
++                    calVideoHeight = calVideoHeight + 1
++                #write("calVideoHeight: %s" % calVideoHeight)
++                
++                #use original video height if the calculated video height is close
++                if (calVideoHeight + 20 < videoHeight) or (calVideoHeight - 20 > videoHeight):
++                     videoHeight = calVideoHeight
++
++                cropPixels = videoModeHeight - videoHeight
++
++                write("Crop Pixels Total: %s" % cropPixels)
++                name = "-vf"
++                value = "\"scale=720:%d, setsar=1:1, pad=720:%d:0:%d:black\"" % (videoModeHeight - cropPixels, videoModeHeight, cropPixels / 2)
+ 
+         # only re-encode the audio if it is not already in AC3 format
+         if audio1[AUDIO_CODEC] == "AC3":
+@@ -4608,7 +4669,7 @@
+ 
+             #do the re-encode 
+             encodeVideoToMPEG2(mediafile, os.path.join(folder, "newfile2.mpg"), video,
+-                            audio1, audio2, aspectratio, profile)
++                            folder, audio1, audio2, aspectratio, profile)
+             mediafile = os.path.join(folder, 'newfile2.mpg')
+ 
+             #remove the old mediafile that was run through mythtranscode
+@@ -4762,7 +4823,7 @@
+ 
+             #do the re-encode 
+             encodeVideoToMPEG2(mediafile, os.path.join(folder, "newfile2.mpg"), video,
+-                            audio1, audio2, aspectratio, profile)
++                            folder, audio1, audio2, aspectratio, profile)
+             mediafile = os.path.join(folder, 'newfile2.mpg')
+ 
+     #remove an intermediate file
diff --git a/abs/core/mythtv/stable-0.27/mythtv/PKGBUILD b/abs/core/mythtv/stable-0.27/mythtv/PKGBUILD
index 59aa538..9a7e954 100644
--- a/abs/core/mythtv/stable-0.27/mythtv/PKGBUILD
+++ b/abs/core/mythtv/stable-0.27/mythtv/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=mythtv
 pkgver=0.27
-pkgrel=6
+pkgrel=7
 commit_hash=`cat ../git_src/git_hash`
 pkgdesc="A Homebrew PVR project $commit_hash"
 arch=('i686' 'x86_64')
-- 
cgit v0.12