<commit_before>import sys
import subprocess
import os
import time
from easygui import multenterbox, choicebox, multchoicebox

# Store the filename for the XML sidecar.
revtmd_xmlfile = sys.argv[1] + '.xml'

# Store the filename without extension.
filename_without_path = os.path.basename(sys.argv[1])

# Store the current time in ISO8601 format.
time_date = time.strftime("%Y-%m-%dT%H:%M:%S")
date = time.strftime("%Y-%m-%d")
def get_audio_stream_count():
    audio_stream_count = subprocess.check_output(['ffprobe', '-v', 'error', '-select_streams', 'a', '-show_entries', 'stream=index', '-of', 'flat', sys.argv[1]]).splitlines()
    return len(audio_stream_count)
audio_tracks = get_audio_stream_count()
if audio_tracks > 0:
    sound = "Yes"
elif audio_tracks == 0:
    sound = "No"

# This function actually adds value to a specified xml element.    
def add_to_revtmd(element, value, xmlfile):
    subprocess.call(['xmlstarlet', 'ed', '--inplace', '-N', 'x=http://nwtssite.nwts.nara/schema/', '-u', element, '-v', value, xmlfile])

# Begin Interview using Easygui.
msg ="Which Workflow?"
title = "Workflows"
choices = ["Telecine One Light", "bestlight", "Telecine Grade", "Tape Ingest 1", "Tape Ingest 2", "Tape Edit Suite 1", "Tape Edit Suite 2"]
workflow = choicebox(msg, title, choices)

# Forking path in order to get more accurate info depending on workflow
if workflow not in ("Telecine One Light", "bestlight", "Telecine Grade"):
    no_of_emptyfields = 13 #temp, this will be a variable.
    msg ="Tape Deck?"
    title = "Pick a name yo!"
    choices = ["DVW-500P", "MiniDV-Something", "UVW-1400AP", "DVW-510P", "J-30", "J-H3", "UVW-1200P", "Unknown"]
    deck = choicebox(msg, title, choices)
    print deck
    if deck == "DVW-A500P":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'DVW-A500P', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', '10317', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[1]', 'Timecode = Auto', revtmd_xmlfile)  
    if deck == "DVW-510P":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'DVW-A510p', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', '11414', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[1]', 'Timecode = Auto', revtmd_xmlfile)   
    elif deck == "J-30":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'J-30', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', 'ABC123', revtmd_xmlfile)
    elif deck == "J-H3":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'J-H3', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', '11482', revtmd_xmlfile)    
    elif deck == "UVW-1400AP":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'UVW-1400AP', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'Component', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', '13697', revtmd_xmlfile) 
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[1]', 'Component out = Y-R,B', revtmd_xmlfile)   
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[2]', 'Timecode = LTC', revtmd_xmlfile)    
              
    elif deck == "UVW-1200P":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'UVW-1200P', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'Component', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', '13697', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[1]', 'Component out = Y-R,B', revtmd_xmlfile)   
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[2]', 'Timecode = LTC', revtmd_xmlfile)                  
if workflow == "Tape Ingest 1":
    def workstation(numbo):
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Host Computer', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Hewlett Packard', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'ABC123', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:version', 'ABC123', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', 'ABC123', revtmd_xmlfile)
    no_of_emptyfields = 6
elif workflow == "Tape Ingest 2":
    def workstation(numbo):
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Host Computer', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Hewlett Packard2', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'ABC123', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:version', 'ABC123', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', 'ABC123', revtmd_xmlfile)
# Currently unused, but I'll get around to it :[
else:
    no_of_emptyfields = 13
    if workflow == "Telecine Grade":
        msg = "Interventions post capture"
        title = "Interventions post capture?"
        fieldNames = ["Colour Alterations","Exposure Alterations","Sound Alterations"]
        grade_interventions = []  # we start with blanks for the values
        grade_interventions = multenterbox(msg,title, fieldNames)
    
    else:
	msg ="Telecine Machine"
	title = "Choose the telecine machine"
	choices = ["Flashtransfer", "Flashscan",]
	scanner = choicebox(msg, title, choices)
	
	if scanner == "Flashtransfer":
		def scanner(numbo):		    
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Telecine', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:description', '16mm Film Digitisation', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'MWA', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'Flashtransfer', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', 'ABC123', revtmd_xmlfile)
	if scanner == "Flashscan":
		def scanner(numbo):		    
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Telecine', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:description', '8mm Film Digitisation', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'MWA', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'Flashscan', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', 'ABC123', revtmd_xmlfile)
	msg ="Preperation?"
	title = "Workflows"
	choices = ["Splice and perforation check on rewind table",
			   "Splice repairs",
			   "Leader added", 
			   "Perforation repairs",
			   "Recanned",
			   "Film reversed during transfer"	]
	preparation = multchoicebox(msg, title, choices)
	print preparation
	
	msg ="Post Processing?"
	title = "Post Processing"
	choices = ["Horizontal Flipping",
			   "Vertical Flipping",
			   "Audio normalised to -20db", 
			   "Broadcast Safe Filter",
			   "Desaturate Filter",
			   ]
	post_processing = multchoicebox(msg, title, choices)
	print post_processing
'''
if preparation == "Splice and perforation check & repairs":
	def prep():
		add_to_revtmd('//revtmd:preparationActions[1]', 'Check for splices and perforation damage', revtmd_xmlfile)
		add_to_revtmd('//revtmd:preparationActions[2]', 'Carry out repairs', revtmd_xmlfile)
 '''


#More interviews    
msg ="User?"
title = "Pick a name yo!"
choices = ["<NAME>", "<NAME>", 
           "<NAME>", "<NAME>", 
	   "<NAME>", "<NAME>", "Unknown"]
user = choicebox(msg, title, choices)


msg = "Fill out these things please"
title = "blablablabl"
fieldNames = ["Source Accession Number",
	      "Notes","Filmographic Reference Number", 
              "Identifier-Object Entry/Accession Number:"]
  # we start with blanks for the values
fieldValues = multenterbox(msg,title, fieldNames)
print fieldValues

# make sure that none of the fields was left blank
while 1:
        if fieldValues == None: break
        errmsg = ""
        for i in range(len(fieldNames)):
            if fieldValues[i].strip() == "":
                errmsg = errmsg + ('"%s" is a required field.' % fieldNames[i])
        if errmsg == "": break # no problems found
        fieldValues = multenterbox(errmsg, title, fieldNames, fieldValues)
    
# Prints info to screen. Make this actually useful! 
#print "Reply was:", fieldValues
#print "Your selection was:\n Workflow =  %s\n Scanner = %s\n Preparation actions = %s\n User = %s\n" % (workflow,scanner, preparation, user)

# Generate filename for the reVTMD xmlfile
revtmd_xmlfile = sys.argv[1] + '.xml'


# Store md5 checksum.
print 'generating md5 checksum, this may take some time'
md5 = subprocess.check_output(['md5deep', '-e', sys.argv[1]])
# Begin creating functions for repetitive tasks:
# Generate xml elements for coding process history.
def revtmd_coding_process_history():
    fo.write('<revtmd:codingProcessHistory>\n')
    fo.write('<revtmd:role/>\n')
    fo.write('<revtmd:description/>\n')
    fo.write('<revtmd:manufacturer/>\n')
    fo.write('<revtmd:modelName/>\n')
    fo.write('<revtmd:version/>\n')
    fo.write('<revtmd:serialNumber/>\n')
    fo.write('<revtmd:signal/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:videoEncoding/>\n')
    fo.write('</revtmd:codingProcessHistory>\n')

# Create mostly blank reVTMD template which we'll gradually fill up with info.
with open(revtmd_xmlfile, "w+") as fo:

    fo.write('<?xml version="1.0" encoding="UTF-8"?>\n')
    fo.write('<revtmd xmlns:revtmd="http://nwtssite.nwts.nara/schema/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nwtssite.nwts.nara/schema/  http://www.archives.gov/preservation/products/reVTMD.xsd">\n')
    fo.write('<revtmd:reVTMD>\n')
    fo.write('<revtmd:object>\n')
    fo.write('<revtmd:filename/>\n')
    fo.write('<revtmd:organization>\n')
    fo.write('<revtmd:organization_main>\n')
    fo.write('<revtmd:name>Irish Film Institute</revtmd:name>\n')
    fo.write('<revtmd:role/>\n')
    fo.write('</revtmd:organization_main>\n')
    fo.write('<revtmd:organization_division>\n')
    fo.write('<revtmd:name>Irish Film Archive</revtmd:name>\n')
    fo.write('</revtmd:organization_division>\n')
    fo.write('</revtmd:organization>\n')
    fo.write('<revtmd:identifier type="Object Entry">%s</revtmd:identifier>\n' % fieldValues[3])
    fo.write('<revtmd:identifier type="Inmagic DB Textworks Filmographic Reference Number">%s</revtmd:identifier>\n' % fieldValues[2])
    fo.write('<revtmd:mimetype/>\n')
    fo.write('<revtmd:duration/>\n')
    fo.write('<revtmd:language/>\n')
    fo.write('<revtmd:size/>\n')
    fo.write('<revtmd:datarate/>\n')
    fo.write('<revtmd:use>Preservation Master</revtmd:use>\n')
    fo.write('<revtmd:color/>\n')
    fo.write('<revtmd:framerate/>\n')
    fo.write('<revtmd:format/>\n')
    fo.write('<!-- Checksum as generated immediately after the digitization process. -->\n')
    fo.write('<revtmd:checksum algorithm="md5" dateTime="%s">%s</revtmd:checksum>\n' % (time_date,md5.split()[0])) 
	
    fo.write('<revtmd:sound>%s</revtmd:sound>\n' % sound)
    fo.write('<revtmd:track id="1" type="video">\n')
    fo.write('<revtmd:size/>\n')
    fo.write('<revtmd:datarate/>\n')
    fo.write('<revtmd:color/>\n')
    fo.write('<revtmd:frame>\n')
    fo.write('<revtmd:pixelsHorizontal/>\n')
    fo.write('<revtmd:pixelsVertical/>\n')
    fo.write('<revtmd:PAR/>\n')
    fo.write('<revtmd:DAR/>\n')
    fo.write('</revtmd:frame>\n')
    fo.write('<revtmd:framerate/>\n')
    fo.write('<revtmd:codec>\n')
    fo.write('<revtmd:codecID/>\n')
    fo.write('<revtmd:channelCount/>\n')
    fo.write('<revtmd:endianness/>\n')
    fo.write('<revtmd:quality/>\n')
    fo.write('<revtmd:scanType/>\n')
    fo.write('<revtmd:scanOrder/>\n')
    fo.write('</revtmd:codec>\n')
    fo.write('<revtmd:bitsPerSample/>\n')
    fo.write('<revtmd:sampling/>\n')
    fo.write('</revtmd:track>\n')
    fo.write('<revtmd:captureHistory>\n')
    fo.write('<revtmd:digitizationDate>%s</revtmd:digitizationDate>\n' % date)
    fo.write('<revtmd:digitizationEngineer/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:source/>\n')
    for _ in range(no_of_emptyfields):    
	    revtmd_coding_process_history()
    fo.write('</revtmd:captureHistory>\n')
    fo.write('</revtmd:object>\n')
    fo.write('</revtmd:reVTMD>\n')
    fo.write('</revtmd>\n')



# What follows are a lot of functions that can be reused. Titles should be self explanatory.

def get_mediainfo(var_type, type, filename):
    var_type = subprocess.check_output(['mediainfo', '--Language=raw', '--Full',
                                         type , filename ]).replace('\n', '').replace('\r', '')
    return var_type
duration =  get_mediainfo('duration', '--inform=General;%Duration_String4%', sys.argv[1] )
par =  get_mediainfo('par', '--inform=Video;%PixelAspectRatio%', sys.argv[1] )<commit_msg>revtmd: broken audio harvest loop<commit_after>import sys
import subprocess
import os
import time
from easygui import multenterbox, choicebox, multchoicebox

# Store the filename for the XML sidecar.
revtmd_xmlfile = sys.argv[1] + '.xml'

# Store the filename without extension.
filename_without_path = os.path.basename(sys.argv[1])

# Store the current time in ISO8601 format.
time_date = time.strftime("%Y-%m-%dT%H:%M:%S")
date = time.strftime("%Y-%m-%d")
def get_audio_stream_count():
    audio_stream_count = subprocess.check_output(['ffprobe', '-v', 'error', '-select_streams', 'a', '-show_entries', 'stream=index', '-of', 'flat', sys.argv[1]]).splitlines()
    return len(audio_stream_count)
audio_tracks = get_audio_stream_count()
if audio_tracks > 0:
    sound = "Yes"
elif audio_tracks == 0:
    sound = "No"

# This function actually adds value to a specified xml element.    
def add_to_revtmd(element, value, xmlfile):
    subprocess.call(['xmlstarlet', 'ed', '--inplace', '-N', 'x=http://nwtssite.nwts.nara/schema/', '-u', element, '-v', value, xmlfile])

# Begin Interview using Easygui.
msg ="Which Workflow?"
title = "Workflows"
choices = ["Telecine One Light", "bestlight", "Telecine Grade", "Tape Ingest 1", "Tape Ingest 2", "Tape Edit Suite 1", "Tape Edit Suite 2"]
workflow = choicebox(msg, title, choices)

# Forking path in order to get more accurate info depending on workflow
if workflow not in ("Telecine One Light", "bestlight", "Telecine Grade"):
    no_of_emptyfields = 13 #temp, this will be a variable.
    msg ="Tape Deck?"
    title = "Pick a name yo!"
    choices = ["DVW-500P", "MiniDV-Something", "UVW-1400AP", "DVW-510P", "J-30", "J-H3", "UVW-1200P", "Unknown"]
    deck = choicebox(msg, title, choices)
    print deck
    if deck == "DVW-A500P":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'DVW-A500P', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', '10317', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[1]', 'Timecode = Auto', revtmd_xmlfile)  
    if deck == "DVW-510P":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'DVW-A510p', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', '11414', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[1]', 'Timecode = Auto', revtmd_xmlfile)   
    elif deck == "J-30":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'J-30', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', 'ABC123', revtmd_xmlfile)
    elif deck == "J-H3":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'J-H3', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', '11482', revtmd_xmlfile)    
    elif deck == "UVW-1400AP":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'UVW-1400AP', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'Component', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', '13697', revtmd_xmlfile) 
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[1]', 'Component out = Y-R,B', revtmd_xmlfile)   
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[2]', 'Timecode = LTC', revtmd_xmlfile)    
              
    elif deck == "UVW-1200P":
        def deck_func(numbo):
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Playback', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Sony', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'UVW-1200P', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'Component', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', '13697', revtmd_xmlfile)
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[1]', 'Component out = Y-R,B', revtmd_xmlfile)   
            add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:settings[2]', 'Timecode = LTC', revtmd_xmlfile)                  
if workflow == "Tape Ingest 1":
    def workstation(numbo):
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Host Computer', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Hewlett Packard', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'ABC123', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:version', 'ABC123', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', 'ABC123', revtmd_xmlfile)
    no_of_emptyfields = 6
elif workflow == "Tape Ingest 2":
    def workstation(numbo):
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Host Computer', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'Hewlett Packard2', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'ABC123', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:version', 'ABC123', revtmd_xmlfile)
        add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', 'ABC123', revtmd_xmlfile)
# Currently unused, but I'll get around to it :[
else:
    no_of_emptyfields = 13
    if workflow == "Telecine Grade":
        msg = "Interventions post capture"
        title = "Interventions post capture?"
        fieldNames = ["Colour Alterations","Exposure Alterations","Sound Alterations"]
        grade_interventions = []  # we start with blanks for the values
        grade_interventions = multenterbox(msg,title, fieldNames)
    
    else:
	msg ="Telecine Machine"
	title = "Choose the telecine machine"
	choices = ["Flashtransfer", "Flashscan",]
	scanner = choicebox(msg, title, choices)
	
	if scanner == "Flashtransfer":
		def scanner(numbo):		    
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Telecine', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:description', '16mm Film Digitisation', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'MWA', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'Flashtransfer', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', 'ABC123', revtmd_xmlfile)
	if scanner == "Flashscan":
		def scanner(numbo):		    
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:role', 'Telecine', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:description', '8mm Film Digitisation', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:manufacturer', 'MWA', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:modelName', 'Flashscan', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:signal', 'SDI', revtmd_xmlfile)
			add_to_revtmd('//revtmd:codingProcessHistory' + str([numbo]) + '/revtmd:serialNumber', 'ABC123', revtmd_xmlfile)
	msg ="Preperation?"
	title = "Workflows"
	choices = ["Splice and perforation check on rewind table",
			   "Splice repairs",
			   "Leader added", 
			   "Perforation repairs",
			   "Recanned",
			   "Film reversed during transfer"	]
	preparation = multchoicebox(msg, title, choices)
	print preparation
	
	msg ="Post Processing?"
	title = "Post Processing"
	choices = ["Horizontal Flipping",
			   "Vertical Flipping",
			   "Audio normalised to -20db", 
			   "Broadcast Safe Filter",
			   "Desaturate Filter",
			   ]
	post_processing = multchoicebox(msg, title, choices)
	print post_processing
'''
if preparation == "Splice and perforation check & repairs":
	def prep():
		add_to_revtmd('//revtmd:preparationActions[1]', 'Check for splices and perforation damage', revtmd_xmlfile)
		add_to_revtmd('//revtmd:preparationActions[2]', 'Carry out repairs', revtmd_xmlfile)
 '''


#More interviews    
msg ="User?"
title = "Pick a name yo!"
choices = ["<NAME>", "<NAME>", 
           "<NAME>", "<NAME>", 
	   "<NAME>", "<NAME>", "Unknown"]
user = choicebox(msg, title, choices)


msg = "Fill out these things please"
title = "blablablabl"
fieldNames = ["Source Accession Number",
	          "Notes","Filmographic Reference Number", 
              "Identifier-Object Entry/Accession Number:"]
  # we start with blanks for the values
fieldValues = multenterbox(msg,title, fieldNames)
print fieldValues

# make sure that none of the fields was left blank
while 1:
        if fieldValues == None: break
        errmsg = ""
        for i in range(len(fieldNames)):
            if fieldValues[i].strip() == "":
                errmsg = errmsg + ('"%s" is a required field.' % fieldNames[i])
        if errmsg == "": break # no problems found
        fieldValues = multenterbox(errmsg, title, fieldNames, fieldValues)
print fieldValues  
# Prints info to screen. Make this actually useful! 
#print "Reply was:", fieldValues
#print "Your selection was:\n Workflow =  %s\n Scanner = %s\n Preparation actions = %s\n User = %s\n" % (workflow,scanner, preparation, user)

# Generate filename for the reVTMD xmlfile
revtmd_xmlfile = sys.argv[1] + '.xml'


# Store md5 checksum.
print 'generating md5 checksum, this may take some time'
md5 = subprocess.check_output(['md5deep', '-e', sys.argv[1]])
# Begin creating functions for repetitive tasks:
# Generate xml elements for coding process history.
def revtmd_coding_process_history():
    fo.write('<revtmd:codingProcessHistory>\n')
    fo.write('<revtmd:role/>\n')
    fo.write('<revtmd:description/>\n')
    fo.write('<revtmd:manufacturer/>\n')
    fo.write('<revtmd:modelName/>\n')
    fo.write('<revtmd:version/>\n')
    fo.write('<revtmd:serialNumber/>\n')
    fo.write('<revtmd:signal/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:settings/>\n')
    fo.write('<revtmd:videoEncoding/>\n')
    fo.write('</revtmd:codingProcessHistory>\n')


def revtmd_blank_audio_fields():
    audio_track_number = 1
    global audio_track_number
    while audio_track_number <= audio_tracks:
        fo.write('<revtmd:track id="%s" type="audio">\n' % audio_track_number)
        fo.write('<revtmd:duration/>\n')
        fo.write('<revtmd:size/>\n')
        fo.write('<revtmd:codec>\n')
        fo.write('<revtmd:codecID/>\n')
        fo.write('<revtmd:channelCount/>\n')
        fo.write('<revtmd:endianness/>\n')
        fo.write('<revtmd:quality/>\n')
        fo.write('</revtmd:codec>\n')
        fo.write('<revtmd:bitsPerSample/>\n')
        fo.write('<revtmd:sampling/>\n')
        
        fo.write('<revtmd:bitsPerSample/>\n')
        fo.write('<revtmd:sampling/>\n')
        fo.write('</revtmd:track>\n')		
        audio_track_number += 1
		#PS C:\Users\kieranjol> xml sel -t -m "Mediainfo/File/track[@type='Audio' and @typeorder='12']" -v ChannelPositions D:\mi.xml
	
    

# Create mostly blank reVTMD template which we'll gradually fill up with info.
with open(revtmd_xmlfile, "w+") as fo:

    fo.write('<?xml version="1.0" encoding="UTF-8"?>\n')
    fo.write('<revtmd xmlns:revtmd="http://nwtssite.nwts.nara/schema/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nwtssite.nwts.nara/schema/  http://www.archives.gov/preservation/products/reVTMD.xsd">\n')
    fo.write('<revtmd:reVTMD>\n')
    fo.write('<revtmd:object>\n')
    fo.write('<revtmd:filename/>\n')
    fo.write('<revtmd:organization>\n')
    fo.write('<revtmd:organization_main>\n')
    fo.write('<revtmd:name>Irish Film Institute</revtmd:name>\n')
    fo.write('<revtmd:role/>\n')
    fo.write('</revtmd:organization_main>\n')
    fo.write('<revtmd:organization_division>\n')
    fo.write('<revtmd:name>Irish Film Archive</revtmd:name>\n')
    fo.write('</revtmd:organization_division>\n')
    fo.write('</revtmd:organization>\n')
    fo.write('<revtmd:identifier type="Object Entry">%s</revtmd:identifier>\n' % fieldValues[3])
    fo.write('<revtmd:identifier type="Inmagic DB Textworks Filmographic Reference Number">%s</revtmd:identifier>\n' % fieldValues[2])
    fo.write('<revtmd:mimetype/>\n')
    fo.write('<revtmd:duration/>\n')
    fo.write('<revtmd:language/>\n')
    fo.write('<revtmd:size/>\n')
    fo.write('<revtmd:datarate/>\n')
    fo.write('<revtmd:use>Preservation Master</revtmd:use>\n')
    fo.write('<revtmd:color/>\n')
    fo.write('<revtmd:framerate/>\n')
    fo.write('<revtmd:format/>\n')
    fo.write('<!-- Checksum as generated immediately after the digitization process. -->\n')
    fo.write('<revtmd:checksum algorithm="md5" dateTime="%s">%s</revtmd:checksum>\n' % (time_date,md5.split()[0])) 
	
    fo.write('<revtmd:sound>%s</revtmd:sound>\n' % sound)
    fo.write('<revtmd:track id="1" type="video">\n')
    fo.write('<revtmd:size/>\n')
    fo.write('<revtmd:datarate/>\n')
    fo.write('<revtmd:color/>\n')
    fo.write('<revtmd:frame>\n')
    fo.write('<revtmd:pixelsHorizontal/>\n')
    fo.write('<revtmd:pixelsVertical/>\n')
    fo.write('<revtmd:PAR/>\n')
    fo.write('<revtmd:DAR/>\n')
    fo.write('</revtmd:frame>\n')
    fo.write('<revtmd:framerate/>\n')
    fo.write('<revtmd:codec>\n')
    fo.write('<revtmd:codecID/>\n')
    fo.write('<revtmd:channelCount/>\n')
    fo.write('<revtmd:endianness/>\n')
    fo.write('<revtmd:quality/>\n')
    fo.write('<revtmd:scanType/>\n')
    fo.write('<revtmd:scanOrder/>\n')
    fo.write('</revtmd:codec>\n')
    fo.write('<revtmd:bitsPerSample/>\n')
    fo.write('<revtmd:sampling/>\n')

    fo.write('</revtmd:track>\n')
    revtmd_blank_audio_fields()
    fo.write('<revtmd:captureHistory>\n')
    fo.write('<revtmd:digitizationDate>%s</revtmd:digitizationDate>\n' % date)
    fo.write('<revtmd:digitizationEngineer/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:preparationActions/>\n')
    fo.write('<revtmd:source/>\n')
    for _ in range(no_of_emptyfields):    
	    revtmd_coding_process_history()
    fo.write('</revtmd:captureHistory>\n')
    fo.write('</revtmd:object>\n')
    fo.write('</revtmd:reVTMD>\n')
    fo.write('</revtmd>\n')



# What follows are a lot of functions that can be reused. Titles should be self explanatory.

def get_mediainfo(var_type, type, filename):
    var_type = subprocess.check_output(['mediainfo', '--Language=raw', '--Full',
                                         type , filename ]).replace('\n', '').replace('\r', '')
    return var_type
duration =  get_mediainfo('duration', '--inform=General;%Duration_String4%', sys.argv[1] )
par =  get_mediainfo('par', '--inform=Video;%PixelAspectRatio%', sys.argv[1] )
{'fraction_non_alphanumeric': 0.17510185344580248, 'fraction_numerical': 0.00935330234693292, 'mean_word_length': 4.235841970857744, 'pattern_counts': {'":': 28, '<': 206, '<?xml version=': 2, '>': 208, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 150}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1935328', 'n_tokens_mistral': 13179, 'n_tokens_neox': 12511, 'n_words': 2069}