Class: FinalCutPro::XMLParser::XMEML::Version5
- Inherits:
-
Common
- Object
- Common
- FinalCutPro::XMLParser::XMEML::Version5
show all
- Defined in:
- lib/final_cut_pro/xml_parser/xmeml/version_5.rb
Instance Attribute Summary
Attributes inherited from Common
#files, #logger, #sequences
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Common
#initialize, #is_clip?, #is_fcpxml?, #is_project?, #is_sequence?, #is_xmeml?, #root, #root_type, #to_hash, #top_level_container, #version, xml_as_document, #xml_as_document, #xml_document, #xml_node_to_hash
Class Method Details
.parse_clips(xml, options = { }) ⇒ Object
8
9
10
11
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 8
def self.parse_clips(xml, options = { })
parser = new
parser.parse_clips(xml_as_document(xml, options))
end
|
.parse_files(xml, options = { }) ⇒ Object
18
19
20
21
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 18
def self.parse_files(xml, options = { })
parser = new
parser.parse_files(xml, options)
end
|
.parse_sequences(xml, options = { }) ⇒ Object
13
14
15
16
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 13
def self.parse_sequences(xml, options = { })
parser = new
parser.parse_sequences(xml_as_document(xml, options))
end
|
Instance Method Details
#build_file_hash(node) ⇒ Object
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
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 162
def build_file_hash(node)
file_id = node.attributes.get_attribute('id').value.to_s
logger.debug { "Processing File with an ID of: #{file_id}" }
path_url_element = node.find('./pathurl').first
unless !path_url_element.nil?
logger.debug { 'Skipping File Node. No pathurl attribute found.' }
return false
end
file_name = node.find('./name').first.content.to_s file_path_url = path_url_element.content.to_s
file_hash = {
:id => file_id,
:name => file_name,
:path_url => file_path_url
}
file_hash[:path_on_file_system] = URI(file_path_url).path.gsub(/(%(?:[2-9]|[A-F])(?:\d|[A-F]))/) { |v| CGI.unescape(v) }
file_hash[:file_node_full] = xml_node_to_hash node
file_hash[:project_name] = get_project_name node
file_hash[:bin_path] = get_bin_path node
file_hash[:clipitem_node_full] = get_clipitem_hash node
file_hash[:clipitems] = get_file_clipitems(node, file_id)
master_clip_id = file_hash[:clipitem_node_full][:masterclipid]
file_hash[:masterclip_node_full] = (master_clip_id.nil? or master_clip_id.empty?) ? { } : get_clip_hash_by_id(node.doc, master_clip_id)
file_hash[:metadata] = get_all_metadata node
file_hash[:labels] = get_all_labels node
file_hash[:comments] = node
file_hash[:logginginfo] = get_logging_info node
file_hash
end
|
#build_file_hash_array(doc, options = { }) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 142
def build_file_hash_array(doc, options = { })
_files = []
nodes = get_files_as_nodes(doc)
total_files = nodes.count
counter = 0
nodes.each do |node|
counter += 1
logger.debug { "Processing file #{counter} of #{total_files}" }
file_hash = build_file_hash(node)
next unless file_hash
logger.debug { "file_hash => #{file_hash}" }
_files << file_hash
end
return _files
end
|
#build_file_hash_hash(params = {}) ⇒ Object
134
135
136
137
138
139
140
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 134
def build_file_hash_hash(params = {})
_files = { }
key = params[:key_on] || :id
files_array = build_file_hash_array(@xml_document)
files_array.each {|file| _files[file[key]] = file }
_files
end
|
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 90
def (node)
= []
node.find('ancestor::bin/comments|ancestor::clip/comments|ancestor::sequence/comments|ancestor::clipitem/comments|ancestor::generatoritem/comments').each do ||
parent = .parent
first_from = parent.find('./name|@id').first
from_name_or_id = first_from.respond_to?(:content) ? first_from.content : first_from.value
= {}
[:from] = { parent.name.to_s => from_name_or_id }
[:comments] = []
.find('./*').each do ||
[:comments] << {.name.to_s => .content.to_s} unless .content.nil? or .content.empty?
end
<<
end
return
end
|
#get_all_labels(node) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 68
def get_all_labels(node)
labels = []
node.find('ancestor::bin/labels|ancestor::clip/labels|ancestor::sequence/labels|ancestor::clipitem/labels|ancestor::generatoritem/labels').each do |labels_node|
parent = labels_node.parent
first_from = parent.find('./name|@id').first
from_name_or_id = first_from.respond_to?(:content) ? first_from.content : first_from.value
label_set = {}
label_set[:from] = { parent.name.to_s => from_name_or_id }
label_set[:labels] = []
labels_node.find('./*').each do |label_node_item|
label_node_item_content = label_node_item.content
label_set[:labels] << {label_node_item.name.to_s => label_node_item_content.to_s} unless label_node_item_content.nil? or label_node_item_content.empty?
end
labels << label_set
end
return labels
end
|
60
61
62
63
64
65
66
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 60
def get_all_metadata(node)
metadata = {}
node.find('descendant::metadata|metadata').each do |metadata_node|
metadata[metadata_node.find('./key').first.content.to_s] = metadata_node.find('./value').first.content.to_s unless metadata_node.find('./key').first.nil? or metadata_node.find('./key').first.empty? or metadata_node.find('./value').first.nil? or metadata_node.find('./value').first.empty?
end
return metadata
end
|
#get_bin_path(node) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 35
def get_bin_path(node)
bin_path = []
node.find('ancestor::bin').each do |ancestor_node|
bin_path << ancestor_node.find('./name').first.content.to_s unless ancestor_node.find('./name').first.content.to_s.empty?
end
return '' if bin_path.empty?
return "/#{bin_path.join('/')}/"
end
|
#get_clip_hash_by_id(doc, id) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 44
def get_clip_hash_by_id(doc, id)
id = id.dup.gsub(/["\s]/, ' ' => "\\s", '"' => '"')
clip = doc.find("//clip[@id=\"#{id}\"]").first
return { } unless clip
return xml_node_to_hash(clip) || { }
end
|
#get_clipitem_hash(node) ⇒ Object
52
53
54
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 52
def get_clipitem_hash(node)
return xml_node_to_hash(node.parent)
end
|
#get_file_clipitems(node, file_id = nil) ⇒ Object
56
57
58
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 56
def get_file_clipitems(node, file_id = nil)
end
|
#get_files_as_nodes(doc) ⇒ Object
130
131
132
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 130
def get_files_as_nodes(doc)
doc.find('//file[pathurl]')
end
|
#get_logging_info(node) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 110
def get_logging_info(node)
logginginfos = []
node.find('ancestor::clip/logginginfo|ancestor::sequence/logginginfo|ancestor::clipitem/logginginfo|ancestor::generatoritem/logginginfo').each do |logginginfo_node|
parent = logginginfo_node.parent
first_from = parent.find('./name|@id').first
from_name_or_id = first_from.respond_to?(:content) ? first_from.content : first_from.value
logginginfo_set = {}
logginginfo_set[:from] = { parent.name.to_s => from_name_or_id }
logginginfo_set[:logginginfo] = {}
logginginfo_node.find('./*').each do |logginginfo_node_item|
logginginfo_set[:logginginfo][logginginfo_node_item.name.to_s] = logginginfo_node_item.content.to_s unless logginginfo_node_item.content.nil? or logginginfo_node_item.content.empty?
end
logginginfos << logginginfo_set
end
return logginginfos
end
|
#get_project_name(node) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 23
def get_project_name(node)
project_node = node.find_first('ancestor::project')
unless project_node.nil?
project_name_node = project_node.find_first('./name')
unless project_name_node.nil? or project_name_node.content.nil?
project_name = project_name_node.content.to_s
return project_name
end
end
end
|
#parse(xml = @xml_document, options = { }) ⇒ Object
199
200
201
202
203
204
205
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 199
def parse(xml = @xml_document, options = { })
xml_doc = self.class.xml_as_document(xml)
@files = parse_files(xml_doc, options)
@sequences = parse_sequences(xml_doc, options)
@clips = parse_clips(xml_doc)
return self
end
|
#parse_clips(xml = @xml_document, options = { }) ⇒ Object
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 211
def parse_clips(xml = @xml_document, options = { })
self.class.xml_as_document(xml).find('//clip').map do |clip_node|
clip_items = clip_node.find('clipitem[(not(enabled) or enabled[text()="TRUE"]) and ../../../../media/video/track[enabled[text()="TRUE"]]]').map do |clip_item_node|
xml_node_to_hash(clip_item_node)
end
xml_node_to_hash(clip_node).merge({ :clip_items => clip_items })
end
end
|
#parse_files(xml = @xml_document, options = { }) ⇒ Object
207
208
209
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 207
def parse_files(xml = @xml_document, options = { })
build_file_hash_array(self.class.xml_as_document(xml), options = { }) || [ ]
end
|
#parse_sequences(xml = @xml_document, options = { }) ⇒ Object
222
223
224
225
226
227
228
229
|
# File 'lib/final_cut_pro/xml_parser/xmeml/version_5.rb', line 222
def parse_sequences(xml = @xml_document, options = { })
self.class.xml_as_document(xml).find('//sequence').map do |sequence_node|
clip_items = sequence_node.find('media/video/track/clipitem[not(enabled) or enabled[text()="TRUE"]]').map do |clip_item_node|
xml_node_to_hash(clip_item_node)
end
xml_node_to_hash(sequence_node).merge({ :clip_items => clip_items })
end
end
|