All pastes #553995 Raw Edit

makedvd.py

public text v1 · immutable
#553995 ·published 2007-06-09 23:35 UTC
rendered paste body
#!/usr/bin/python
##I have taken the concept of this script from http://s91928265.onlinehome.us/hfamily/mythtv/myth_ubuntu.html
##The script has not been updated in awhile and since Ubuntu Feisty came out, it no longer works
##I asked in #bash and everyone agreed that the original writer did not do a very good job. So I am going
##to take over and convert it to python and hopefully keep it up to date and working. I hope to add some extra ##features to it
##like an option to burn the dvd after creating the iso file!
##James Middendorff a.k.a riddlebox
##06/09/07
##
##USAGE: python makedvd.py ProjectName filename.mpg/nuv
##Depends on dvdauthor
##########################################################################################################
##
##Notes to myself while writing this!
##  1. Use sys.argv to pass arguments at the commandline!
##  2. Use sys.argv to create a -h to show the description and how to properly use the script
##  3. Create Functions to do the actual work!
##  4. use os to run the commands instead of popen3
##  5. add error detection features, and possibly a gui to go along with it
##  6. have a gui or even commandline option to burn the dvd directly instead of creating the iso
import os
import sys


#create the variables for python to create the project name and take the file name
#will eventually have more than one filename
projName = sys.argv[1]
file1 = sys.argv[2]
#file2 = sys.argv[3]
#file3 = sys.argv[4]


###These lines will setup our commands to actually do the work!
def cleanUp():
	os.remove('aud0')
        os.remove('vid0')
        os.remove('dvdmpg')
	os.system('rm -rf dvdproj')
        print 'finished cleaning up files'
	print 'Successfully completed the project, now you must burn the iso and enjoy!'

def sub_mkiso():
	print 'Starting the mkisofs process.....'
	sub_mkisofs = os.system('mkisofs -dvd-video -udf -V MythDVD -r dvdproj/ > MythDVD.iso')
	if sub_mkisofs == 0:
		print 'Success creating the iso file'
		cleanUp()
	else:
		print 'An error occured'
        
def sub_dvdAuth2():
	print 'Starting the second round of dvdauthor.....'
	sub_dvdauth2 = os.system('dvdauthor -o dvdproj -T')
	print 'Success with dvdauthor -o dvdproj -T'
	sub_mkiso()

def sub_dvdAuth1():
	print 'Starting the first round of dvdauthor'
	sub_dvdauthor = os.system('dvdauthor -o dvdproj -f dvdmpg')
	if sub_dvdauthor == 0:
		print 'Success with dvdauthor -o dvdproj -f titlename'
		sub_dvdAuth2()
	else:
		print 'An error occured'


def sub_mplex():
	print 'Starting the mplex'
	sub_mplexAll = os.system('mplex -f 8 -V -o dvdmpg aud0 vid0 &')
	if sub_mplexAll ==0:
		print 'Success with mplex -f 8 -V -o dvdmpg aud0 vid0'
		os.popen3('mkdir dvdproj')
        	str = "dvdmpg"
		sub_dvdAuth1()
	else:
		print 'Returned an error'

def sub_mv():
	print 'Starting to mpeg2desc the video'
	sub_mpeg_video = os.system('mpeg2desc -v0 < %s >  vid0 &'%file1)
	if sub_mpeg_video == 0:
		print 'Success with mpeg2desc -v0 <%s> vid0 '%file1
		sub_mplex()
	else:
		print 'Returned an error'


def sub_ma():
	print 'Starting to mpeg2desc the audio'
	sub_mpeg_audio = os.system('mpeg2desc -a0 <%s> aud0 &'%file1)
        if sub_mpeg_audio == 0:
		print 'Success with mpeg2desc -a0 <%s> aud0'%file1
		sub_mv()		
	else:
		print 'Returned an error'

##Here is the main app
##First we will show the description and how to properly use the script, which I will hope to make this part a help file of some sort
print ""
print "makedvd: From a set of MythTV recordings, create an ISO"
print "         file suitable for burning directly to"
print "         a DVD.  The output is nothing fancy; each"
print "         show is simply a chapter on the DVD, without" 
print "         menus and such."
print ""
print "Usage:   python makedvd.py dvdprojectname [list of .nuv files....]"
print "         The output file will be named dvdprojectname.iso." 
print ""
print ""

#This will pull the title info from the database using mythshows.sh
def Main_App():
    try:
        os.remove('TITLES.LOG') #this will try to remove the file TITLES.LOG
        print 'Removed TITLES.LOG, proceeding.'
        os.popen3('mytshows.sh |grep %s >> TITLES.LOG'%file1) #and if it is deleted then create the TITLES.LOG
    except:
        print 'No TITLES.LOG in this directory, proceeding.' #Will see there is no TITLES.LOG
        os.popen3('mythshows.sh |grep %s >> TITLES.LOG'%file1) #and will create the TITLES.LOG
#the line with os.popen3 take the filename and use mythshows.sh to create the log with the name of the show to convert
    
    finally:
        print '#######################################' #moves on to the rest of the script
        print 'DVD Project is: %s'%projName
#Eventually I want to display the filename and info that is being converted as well.
        print '#######################################'

        os.popen3('mkfifo aud0')
        os.popen3('mkfifo vid0')
        os.popen3('mkfifo dvdmpg')
        print 'made the fifo stuff'
        ##Start all of the defs here!!!! this will do most of the work
	#subprocess.call(["ls","-l"])
	sub_ma()
        
Main_App()