Ticket #3655: mythburn.py.patch

File mythburn.py.patch, 5.9 KB (added by robsbox@…, 13 years ago)

patch to mythburn.py for commercial skipping

  • mytharchive/mythburn/scripts/mythburn.py

     
    1414# paulh
    1515# 4 May 2006 - Added into mythtv svn
    1616
     17# robg
     18# 20 Jun 2007 - Added commercial skipping chapter marks
     19
    1720#For this script to work you need to have...
    1821#Python2.3.5
    1922#python2.3-mysqldb
     
    3134#******************************************************************************
    3235
    3336# version of script - change after each update
    34 VERSION="0.1.20070619-1"
     37VERSION="0.1.20070620-2"
    3538
    3639
    3740##You can use this debug flag when testing out new themes
     
    522525
    523526    write( "Video length is %s seconds. Each chapter will be %s seconds" % (lengthofvideo,segment))
    524527
    525     chapters=""
     528    chapters = createVideoChaptersFixedLength(itemnum, segment, lengthofvideo)
     529
    526530    thumbList=""
    527531    starttime=0
    528532    count=1
    529533    while count<=numofchapters:
    530         chapters+=time.strftime("%H:%M:%S",time.gmtime(starttime))
    531 
    532534        if starttime==0:
    533535            if thumboffset < segment:
    534536                thumbList+="%s," % thumboffset
     
    537539        else:
    538540            thumbList+="%s," % starttime
    539541
    540         if numofchapters>1:
    541             chapters+=","
    542542        starttime+=segment
    543543        count+=1
    544544
     
    548548
    549549    return chapters
    550550
    551 def createVideoChaptersFixedLength(segment, lengthofvideo):
    552     """Returns chapter marks spaced segment seconds through the file"""
     551def createVideoChaptersFixedLength(itemnum, segment, lengthofvideo):
     552    """Returns chapter marks at commercial ends, or spaced segment seconds through the file"""
     553
     554    # if there is a chapter list already available, use it
     555    infoDOM = xml.dom.minidom.parse(os.path.join(getItemTempPath(itemnum),"info.xml"))
     556    chapterlistNode = infoDOM.getElementsByTagName("chapterlist")
     557    if chapterlistNode.length > 0:
     558        chapterlist = getText(chapterlistNode[0])
     559        write("Using commercial end marks - %s" % chapterlist)
     560        return chapterlist
     561
    553562    if lengthofvideo < segment:
    554563        return "00:00:00"
    555564
     
    871880        node.appendChild(infoDOM.createTextNode(""))
    872881        top_element.appendChild(node)
    873882
    874         #if this a myth recording we still need to find the chanid, starttime and hascutlist
     883        #if this a myth recording we still need to find the chanid, starttime, hascutlist, and commercial end marks
    875884        if file.attributes["type"].value=="recording":
    876885            basename = os.path.basename(file.attributes["filename"].value)
    877886            sqlstatement  = """SELECT starttime, chanid FROM recorded
     
    918927                    node.appendChild(infoDOM.createTextNode("no"))
    919928                    top_element.appendChild(node)
    920929
     930                # find the commercial end marks if available
     931                sqlstatement  = """SELECT mark, type FROM recordedmarkup
     932                                WHERE chanid = '%s' AND starttime = '%s'
     933                                AND type = 5 ORDER BY mark""" % (chanid, starttime)
     934                cursor = db.cursor()
     935                # execute SQL statement
     936                cursor.execute(sqlstatement)
     937                # get the resultset as a tuple
     938                result = cursor.fetchall()
     939                if cursor.rowcount > 0:
     940                    res, fps, ar = getVideoParams(folder)
     941                    chapterlist="00:00:00"
     942                    #iterate through marks, adding to chapterlist
     943                    for record in result:
     944                        chapterlist += "," + frameToTime(int(record[0]), float(fps))
     945       
     946                    node = infoDOM.createElement("chapterlist")
     947                    node.appendChild(infoDOM.createTextNode(chapterlist))
     948                    top_element.appendChild(node)
     949
    921950                db.close()
    922951                del db
    923952                del cursor
     
    10161045                node.appendChild(infoDOM.createTextNode("no"))
    10171046                top_element.appendChild(node)
    10181047
     1048            # find the commercial end marks if available
     1049            sqlstatement  = """SELECT mark, type FROM recordedmarkup
     1050                                WHERE chanid = '%s' AND starttime = '%s'
     1051                                AND type = 5 ORDER BY mark""" % (chanid, starttime)
     1052            cursor = db.cursor()
     1053            # execute SQL statement
     1054            cursor.execute(sqlstatement)
     1055            # get the resultset as a tuple
     1056            result = cursor.fetchall()
     1057            if cursor.rowcount > 0:
     1058                res, fps, ar = getVideoParams(folder)
     1059                chapterlist="00:00:00"
     1060                #iterate through marks, adding to chapterlist
     1061                for record in result:
     1062                    chapterlist += "," + frameToTime(int(record[0]), float(fps))
     1063       
     1064                node = infoDOM.createElement("chapterlist")
     1065                node.appendChild(infoDOM.createTextNode(chapterlist))
     1066                top_element.appendChild(node)
     1067
    10191068        db.close()
    10201069        del db
    10211070        del cursor
     
    20662115            if wantChapterMenu:
    20672116                vob.setAttribute("chapters",createVideoChapters(itemnum,chapters,getLengthOfVideo(itemnum),False) )
    20682117            else:
    2069                 vob.setAttribute("chapters", createVideoChaptersFixedLength(chapterLength, getLengthOfVideo(itemnum)))
     2118                vob.setAttribute("chapters", createVideoChaptersFixedLength(itemnum,chapterLength, getLengthOfVideo(itemnum)))
    20702119
    20712120            vob.setAttribute("file",os.path.join(getItemTempPath(itemnum),"final.mpg"))
    20722121            pgc.appendChild(vob)
     
    22842333
    22852334        vob = dvddom.createElement("vob")
    22862335        vob.setAttribute("file", os.path.join(getItemTempPath(itemNum), "final.mpg"))
    2287         vob.setAttribute("chapters", createVideoChaptersFixedLength(chapterLength, getLengthOfVideo(itemNum)))
     2336        vob.setAttribute("chapters", createVideoChaptersFixedLength(itemNum, chapterLength, getLengthOfVideo(itemNum)))
    22882337        pgc.appendChild(vob)
    22892338
    22902339        del vob