forked from kieranjol/IFIscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibimages.py
executable file
·205 lines (185 loc) · 7.95 KB
/
libimages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import sys
import subprocess
from glob import glob
import os
from easygui import multenterbox, choicebox
from Tkinter import *
import tkFileDialog
root = Tk()
import pdb
# Create file-open dialog.
root.update()
# Directory with files that we want to transcode losslessly and generate metadata for P.S just as for directory instead, fix later.
video_dir = tkFileDialog.askdirectory(parent=root)
inmagic_xmlfile = 'blablabla.xml'
os.chdir(video_dir)
# Find all image files
video_files = glob('*.tif') + glob('*.jpg') + glob('*.jpeg')
no_of_emptyfields = len(video_files) # the number of inmagic records based on the number of files
msg = "Fill out these things please"
title = "blablablabl"
fieldNames = ["Year",
"Film Title","Copyright",
"Donation Date", "Director", "Reference number of first record", "Accession number of first record "]
fieldValues = [] # we start with blanks for the values
fieldValues = multenterbox(msg,title, fieldNames)
# 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)
msg ="User?"
title = "Pick a name yo!"
choices = ["Fiona Rigney", "Fleur Finley", "Kasandra O'Connell", "Kieran O'Leary"]
user = choicebox(msg, title, choices)
msg ="Type?"
title = "Pick a name yo!"
choices = ["Poster", "Still"]
type = choicebox(msg, title, choices)
print fieldValues[5]
ref = fieldValues[5]
acc_number = int(fieldValues[6])
number = 0 #Inmagic lists the first record as number 0. the second record is number 1 and so on.
#print noofemptyfields
with open(inmagic_xmlfile, "w+") as fo:
fo.write('<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>\n')
fo.write('<inm:Results xmlns:inm="http://www.inmagic.com/webpublisher/query" productTitle="Inmagic DB/TextWorks for SQL" productVersion="13.00">\n')
fo.write('<inm:Recordset setCount="%s">\n' % no_of_emptyfields)
fo.write('<inm:Record setEntry="%s">\n' % number)
fo.write('<inm:Reference-Number>%s</inm:Reference-Number>\n' % ref)
fo.write('<inm:Type/>\n')
fo.write('<inm:Item-Title/>\n')
fo.write('<inm:Film-Title/>\n')
fo.write('<inm:Year/>\n')
fo.write('<inm:Country-of-Origin/>\n')
fo.write('<inm:Language/>\n')
fo.write('<inm:Notes/>\n')
fo.write('<inm:Dimensions/>\n')
fo.write('<inm:Colour/>\n')
fo.write('<inm:Location-Number/>\n')
fo.write('<inm:Conservation/>\n')
fo.write('<inm:Copyright/>\n')
fo.write('<inm:Access-Restrictions/>\n')
fo.write('<inm:Acquisition-Source/>\n')
fo.write('<inm:Acquisition-Method/>\n')
fo.write('<inm:Date-Created/>\n')
fo.write('<inm:Edited-By/>\n')
fo.write('<inm:Date-Last-Modified/>\n')
fo.write('<inm:Number-Of-Copies/>\n')
fo.write('<inm:Description/>\n')
fo.write('<inm:Subject-Headings/>\n')
fo.write('<inm:Date-Of-Donation/>\n')
fo.write('<inm:Accession-Number>15/%s</inm:Accession-Number>\n' % str(acc_number).zfill(4) )
fo.write('<inm:Director/>\n')
fo.write('<inm:Image/>\n')
fo.write('<inm:Collection-Name/>\n')
fo.write('<inm:Collection-Level-Des/>\n')
fo.write('<inm:Level-of-Description>File</inm:Level-of-Description>\n')
fo.write('<inm:Digital-or-Hardcopy>Digital</inm:Digital-or-Hardcopy>\n')
fo.write('<inm:Master-or-Access/>\n')
fo.write('<inm:Size/>\n')
fo.write('<inm:Digital-Size/>\n')
fo.write('<inm:File-Format/>\n')
fo.write('<inm:Resolution/>\n')
fo.write('<inm:Depositor-Ref-Number/>\n')
fo.write('<inm:Movement-Field/>\n')
fo.write('</inm:Record>\n')
for _ in range(no_of_emptyfields - 1): # -1 because one blank record has already been created
number += 1
with open(inmagic_xmlfile, "a+") as fo:
fo.write('<inm:Record setEntry="%s">\n' % number)
fo.write('<inm:Reference-Number/>\n')
fo.write('<inm:Type/>\n')
fo.write('<inm:Item-Title/>\n')
fo.write('<inm:Film-Title/>\n')
fo.write('<inm:Year/>\n')
fo.write('<inm:Country-of-Origin/>\n')
fo.write('<inm:Language/>\n')
fo.write('<inm:Notes/>\n')
fo.write('<inm:Dimensions/>\n')
fo.write('<inm:Colour/>\n')
fo.write('<inm:Location-Number/>\n')
fo.write('<inm:Conservation/>\n')
fo.write('<inm:Copyright/>\n')
fo.write('<inm:Access-Restrictions/>\n')
fo.write('<inm:Acquisition-Source/>\n')
fo.write('<inm:Acquisition-Method/>\n')
fo.write('<inm:Date-Created/>\n')
fo.write('<inm:Edited-By/>\n')
fo.write('<inm:Date-Last-Modified/>\n')
fo.write('<inm:Number-Of-Copies/>\n')
fo.write('<inm:Description/>\n')
fo.write('<inm:Subject-Headings/>\n')
fo.write('<inm:Date-Of-Donation/>\n')
fo.write('<inm:Accession-Number/>\n')
fo.write('<inm:Director/>\n')
fo.write('<inm:Image/>\n')
fo.write('<inm:Collection-Name/>\n')
fo.write('<inm:Collection-Level-Des/>\n')
fo.write('<inm:Level-of-Description>File</inm:Level-of-Description>\n')
fo.write('<inm:Digital-or-Hardcopy>Digital</inm:Digital-or-Hardcopy>\n')
fo.write('<inm:Master-or-Access/>\n')
fo.write('<inm:Size/>\n')
fo.write('<inm:Digital-Size/>\n')
fo.write('<inm:File-Format/>\n')
fo.write('<inm:Resolution/>\n')
fo.write('<inm:Depositor-Ref-Number/>\n')
fo.write('<inm:Movement-Field/>\n')
fo.write('</inm:Record>\n')
with open(inmagic_xmlfile, "a+") as fo:
fo.write('</inm:Recordset>\n')
fo.write('</inm:Results>\n')
numbo = 0
numbo_1 = 1
ref = int(fieldValues[5])
print ref
for filename in video_files: #Begin a loop for all .mov and .mp4 files.
#pdb.set_trace()
msg ="User?"
title = "Depositor?"
choices = ["IFB", "BAI"]
#user = choicebox(msg, title, choices)
print inmagic_xmlfile
print video_dir
print video_files
ref +=1
acc_number +=1
print ref
print fieldValues
def add_to_inmagic(element, value, xmlfile):
subprocess.call(['xml', 'ed', '--inplace', '-N', 'x=http://www.inmagic.com/webpublisher/query', '-u', element, '-v', value, xmlfile])
add_to_inmagic('//inm:Collection-Name', 'BAI',inmagic_xmlfile)
add_to_inmagic('//inm:Acquisition-Source', 'Broadcasting Authority of Ireland [BAI]',inmagic_xmlfile)
add_to_inmagic('//inm:Acquisition-Method', 'BAI Delivery',inmagic_xmlfile)
add_to_inmagic('//inm:Edited-By', user,inmagic_xmlfile)
add_to_inmagic('//inm:Type', type,inmagic_xmlfile)
add_to_inmagic('//inm:Record' + str([numbo_1 + 1]) +'//inm:Reference-Number',str(ref),inmagic_xmlfile)
add_to_inmagic('//inm:Record' + str([numbo_1 + 1]) +'//inm:Accession-Number', '15/' + str(acc_number).zfill(4),inmagic_xmlfile)
numbo_1 += 1
def get_exiftool(var_type, type, filename):
var_type = subprocess.check_output(['exiftool', '-b',
type , filename ])
return var_type
megapixels = get_exiftool('megapixels', '-Megapixels', filename )
filesize = get_exiftool('filesize', '-FileSize', filename )
codec = get_exiftool('codec', '-FileType', filename )
print "processing", filename
print codec
print megapixels
print filesize
numbo +=1
add_to_inmagic('//inm:Record' + str([numbo]) + '//inm:File-Format', codec,inmagic_xmlfile)
add_to_inmagic('//inm:Record' + str([numbo]) + '//inm:Digital-Size', filesize,inmagic_xmlfile)
add_to_inmagic('//inm:Record' + str([numbo]) + '//inm:Year', fieldValues[0],inmagic_xmlfile)
add_to_inmagic('//inm:Record' + str([numbo]) + '//inm:Film-Title', fieldValues[1],inmagic_xmlfile)
add_to_inmagic('//inm:Record' + str([numbo]) + '//inm:Copyright', fieldValues[2],inmagic_xmlfile)
add_to_inmagic('//inm:Record' + str([numbo]) + '//inm:Date-Of-Donation', fieldValues[3],inmagic_xmlfile)
add_to_inmagic('//inm:Record' + str([numbo]) + '//inm:Director', fieldValues[4],inmagic_xmlfile)
subprocess.call(['xml', 'ed', '--inplace','-d',
'//*[not(./*) and (not(./text()) or normalize-space(./text())="")]',
inmagic_xmlfile])
print "You've created", no_of_emptyfields, "Inmagic records. Open the image database, select File ->Import ->select xml file and make sure that ""'check for matching records'"" is not selected"