-
Notifications
You must be signed in to change notification settings - Fork 0
/
uwmetaedit2
executable file
·135 lines (123 loc) · 5.49 KB
/
uwmetaedit2
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
#!/usr/bin/env ruby
require 'flammarion'
require 'yaml'
require 'mediainfo'
require 'optparse'
InputItemNumbers = []
Skip = []
HuskyLinks = ['https://web.archive.org/web/20090820093233/http://geocities.com/aleharobed/siberian_husky_run_mini.gif',
'https://web.archive.org/web/20090829072442/http://www.geocities.com/sakiaakennelz/walkingsiberianhusky.gif',
'https://web.archive.org/web/20091019155615/http://de.geocities.com/Mausezwerg1981/huskyspringend.gif']
ARGV.options do |opts|
opts.on("-i", "--item-number=val", String) { |val| InputItemNumbers << val }
opts.on("-s", "--skip=val", String) { |val| Skip << val }
opts.on("-o", "--overwrite") { Overwrite = true }
opts.parse!
end
# Check for $windows
if Gem.win_platform?
$windows = true
else
$windows = false
end
#Set up/Load config
scriptPath = __dir__
configPath = scriptPath + "/uw-metaedit-config.txt"
unless File.exist?(configPath)
configBlank = {
"originator" =>'',
"history1" => '',
"history2" => '',
"history3" => '',
"collection" => ''
}
File.open(configPath, "w") { |file| file.write(configBlank.to_yaml) }
end
configOptions = YAML.load(File.read(configPath))
def getOutputDir()
if $windows
targetFile = `powershell "Add-Type -AssemblyName System.$windows.forms|Out-Null;$f=New-Object System.$windows.Forms.FolderBrowserDialog;$f.SelectedPath = 'C:\';$f.Description = 'Select Output Directory';$f.ShowDialog((New-Object System.$windows.Forms.Form -Property @{TopMost = $true }))|Out-Null;$f.SelectedPath"`.strip + '\\'
else
targetFile = `zenity --file-selection`.strip
end
return targetFile
end
def embedBext(targetFile, origin, codeHist1, codeHist2, codeHist3,collNumber, itemNumber)
command = []
moddatetime = File.mtime(targetFile)
moddate = moddatetime.strftime("%Y-%m-%d")
modtime = moddatetime.strftime("%H:%M:%S")
history = codeHist1 + "\n" + codeHist2
history += "\n" + codeHist3 unless codeHist3.empty?
originator_reference = File.basename(targetFile)
originator_reference = 'See description for identifiers' if originator_reference.length > 32
unless itemNumber.nil?
description = "Collection number: #{collNumber}, " + "Item Number: #{itemNumber}, " + "Original File Name: #{File.basename(targetFile,".*")}"
else
description = "Collection number: #{collNumber}, " + "Original File Name #{File.basename(targetFile,".*")}"
end
description += "\nPROCESSED MEZZANINE FILE" unless codeHist3.empty?
command << 'bwfmetaedit'
command << '--reject-overwrite' if defined?(Overwrite).nil?
command << "--Originator=#{origin}" unless Skip.include?('Originator')
command << "--Description=#{description}" unless Skip.include?('Description')
command << "--OriginatorReference=#{originator_reference}" unless Skip.include?('OriginatorReference')
command << "--History=#{history}" unless Skip.include?('History')
command << "--IARL=#{origin}" unless Skip.include?('IARL')
command << "--OriginationDate=#{moddate}" unless Skip.include?('OriginationDate')
command << "--OriginationTime=#{modtime}" unless Skip.include?('OriginationTime')
command << '--MD5-Embed' unless Skip.include?('MD5')
command << "#{targetFile}"
if system(*command) && Gui
$window.alert("Embedding done")
elsif Gui
$window.alert("Error occurred - please double check file and settings")
end
end
# Set up config variables
originator = configOptions['originator']
history1 = configOptions['history1']
history2 = configOptions['history2']
history3 = configOptions['history3']
collection = configOptions['collection']
unless ARGV.length.positive?
Gui = true
$window = Flammarion::Engraving.new
$window.image(HuskyLinks.sample)
$window.title("Welcome to UW Metaedit 2.0")
$window.pane("Items").orientation = :horizontal
$window.pane("Items").puts("Item Info", replace:true)
collNumber = $window.pane("Items").input('Collection Number(s)', options = {value:collection})
itemNumber = $window.pane("Items").input('Item Number')
$window.pane("BEXT").puts("BEXT Info", replace:true)
origin = $window.pane("BEXT").input('Originator', options = {value:originator})
codeHist1 = $window.pane("BEXT").input('Encoding History Line 1' , options = {value:history1})
codeHist2 = $window.pane("BEXT").input('Encoding History Line 2', options = {value:history2})
codeHist3 = $window.pane("BEXT").input('Mezzanine creation information)', options = {value:history3})
$window.pane("Controls").button("Save Settings") {
configOptions['originator'] = origin.to_s
configOptions['history1'] = codeHist1.to_s
configOptions['history2'] = codeHist2.to_s
configOptions['history3'] = codeHist3.to_s
configOptions['collection'] = collNumber.to_s
File.open(configPath, "w") { |file| file.write(configOptions.to_yaml) }
}
$window.pane("Controls").orientation = :horizontal
targetFile = $window.pane("Controls").button('Select Target') { targetFile = getOutputDir() }
$window.pane("Controls").button('Embed Metadata') { embedBext(targetFile, origin, codeHist1, codeHist2, collNumber, itemNumber) }
$window.wait_until_closed
else
Gui = false
if ARGV.length != InputItemNumbers.length && InputItemNumbers.length != 0
puts "Number of inputs does not match number of item numbers - please recheck your command."
exit
end
ARGV.each do |targetFile|
itemNumber = InputItemNumbers[ARGV.index(targetFile)]
if File.exist?(targetFile)
embedBext(targetFile, originator, history1, history2, history3, collection, itemNumber)
else
puts "File not found: Skipping #{targetFile}"
end
end
end