[mythtv-users] MythArchive 0.27 mythburn.py patch for cutlist support (HD-PVR)

Will Dormann wdormann at gmail.com
Thu May 8 12:28:44 UTC 2014


On 5/8/14, 5:22 AM, John Pilkington wrote:
> I looked briefly at the patch you posted at the start of this thread,
> but I wasn't sure I could cleanly pick out the bits you just applied.  I
> thought the UTC problem had been fixed for recent versions - see
> 
> https://code.mythtv.org/trac/ticket/11758
>


Hi John,

I realized that the other patch that needs to happen is the one that
recalculates the post-custlist running length, too.  That's required if
you make a DVD that uses a menu.

Attached is the patch that I'm currently using with success. When I
first looked at this problem, I recall manually searching the database
for the recording based on the time that mythburn.py was using, and it
*did* find the recording.   Plus my mythburn.py has the patch in the
ticket above.

Given that both aspects need to be patched (and everything else seems to
be working fine), I'm slightly less motivated to figure out what the
first issue is.  :-/


-WD

-------------- next part --------------
--- mythburn.py.orig	2014-05-07 18:44:51.246832972 -0400
+++ mythburn.py	2014-05-07 20:46:13.999386678 -0400
@@ -606,6 +606,26 @@
     return duration
 
 #############################################################
+# Gets the duration of a video file from its stream info file
+
+def getOrigLengthOfVideo(index):
+    """Returns the length of a video file (in seconds)"""
+
+    #open the XML containing information about this file
+    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_orig.xml'))
+    file = infoDOM.getElementsByTagName("file")[0]
+    if file.attributes["cutduration"].value != 'N/A':
+        duration = int(file.attributes["cutduration"].value)
+    else:
+        duration = 0;
+
+    return duration
+
+#############################################################
 # Gets the audio sample rate and number of channels of a video file 
 # from its stream info file
 
@@ -1697,6 +1717,16 @@
 
     # print out the streaminfo.xml file to the log
     infoDOM = xml.dom.minidom.parse(xmlFilename)
+    if os.path.basename(filename) == "newfile2.mpg":
+        # This is a newly-written video file, and mytharchivehelper isn't going to find the cutlist
+        write("Obtaining cutlist details from original recording")
+        index = int(os.path.split(os.path.dirname(filename))[-1])
+        cutduration = str(getOrigLengthOfVideo(index))
+        write("Cut duration: %s" % cutduration)
+        file = infoDOM.getElementsByTagName("file")[0]
+        file.attributes['cutduration'].value = cutduration
+        WriteXMLToFile (infoDOM, xmlFilename)
+        
     write(xmlFilename + ":-\n" + infoDOM.toprettyxml("    ", ""), False)
 
 #############################################################
@@ -1770,7 +1800,22 @@
 def generateProjectXCutlist(chanid, starttime, folder):
     """generate cutlist_x.txt for ProjectX"""
 
-    rec = DB.searchRecorded(chanid=chanid, starttime=starttime).next()
+    try:
+        rec = DB.searchRecorded(chanid=chanid, starttime=starttime).next()
+    except StopIteration:
+        try:
+            write("Cannot find recording on channel %s at %s. Falling back to filename search." % (chanid, starttime))
+            # Fall back to finding recording by filename
+            streaminfofile = os.path.join(folder, 'streaminfo_orig.xml')
+            streaminfoDOM = xml.dom.minidom.parse(streaminfofile)
+            fileNodes = streaminfoDOM.getElementsByTagName("file")
+            fileNode = fileNodes[0]
+            if fileNode.hasAttribute("filename"):
+                filename = fileNode.attributes["filename"].value
+            rec = DB.searchRecorded(basename=os.path.basename(filename)).next()
+        except StopIteration:
+            fatalError("Failed to get recording details from the DB for %s" % filename)
+            
     starttime = rec.starttime.utcisoformat()
     cutlist = rec.markup.getcutlist()
 


More information about the mythtv-users mailing list