This repository has been archived by the owner on Feb 23, 2021. It is now read-only.
forked from slackhq/magic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommando-munger-spec
156 lines (123 loc) · 3.87 KB
/
commando-munger-spec
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
#!/usr/bin/env ruby
require_relative 'commando-helpers.rb'
require 'csv'
require 'pp'
require 'edl'
require 'timecode'
program :description, 'WIP'
program :version, '1.0.0'
command :run do |c|
c.description = 'WIP'
c.option '--edl EDL', String, 'EDL file'
c.option '--sheet CSV', String, 'Old Google Docs sheet'
c.option '--frameio CSV', String, 'Frame.io comments export'
c.option '--fps FPS', Integer, 'FPS to process EDL file with'
c.action do |args, options|
options.default \
fps: 30
crash("EDL is required") unless options.edl && File.exists?(options.edl)
crash("Sheet is required") unless options.sheet && File.exists?(options.sheet)
options.edl = File.expand_path(options.edl)
options.sheet = File.expand_path(options.sheet)
options.frameio = File.expand_path(options.frameio) if options.frameio && File.exists?(options.frameio)
command_header(c, options)
output = {}
dupes = {}
stub = {
start_tc: nil,
start_frame: nil,
end_tc: nil,
end_frame: nil,
description: nil,
notes: nil,
}
edl = EDL::Parser.new(fps=options.fps).parse(File.open(options.edl))
edl.each do |evt|
# if evt.num == "072"
# pp evt
# pp evt.comments
# pp evt.clip_name
# end
next if evt.track == "AA"
# use TO NAME for transitions
if evt.has_transition?
evt.comments.each do |comment|
next unless comment.start_with? "* TO CLIP NAME"
evt.clip_name = comment.gsub("* TO CLIP NAME:", '').strip
break
end
end
next unless evt.clip_name
clip_id = evt.clip_name.split('.')[0]
if output[clip_id]
dupes[clip_id] ||= 1
dupes[clip_id] += 1
clip_id = "#{clip_id}_dupe#{dupes[clip_id]}"
end
output[clip_id] = stub.clone
output[clip_id][:start_tc] = evt.rec_start_tc.to_s
output[clip_id][:start_frame] = evt.rec_start_tc.total
output[clip_id][:end_tc] = evt.rec_end_tc.to_s
output[clip_id][:end_frame] = evt.rec_end_tc.total
end
sheet = CSV.parse(File.read(options.sheet), headers: true)
sheet.each do |row|
shot = row.to_hash
id = shot['Shot ID'].split('.')[0]
# find existing via start_with
unless output[id]
output.each do |k,v|
if k.start_with?(id)
id = k
break
end
end
end
unless output[id]
output[id] = stub.clone
puts "still didnt find entry for #{id}"
end
output[id][:description] = shot['Description']
output[id][:notes] = shot['Notes']
end
if options.frameio
frameio = File.open(options.frameio, "rb")
comments = frameio.read.split("\n\n")
comments.each_with_index do |comment, i|
next if i == 0
next if comment.start_with? "\t"
meta,msg = comment.split("\n")
meta = meta.split(' - ', 2)[1]
tc,msg = msg.split(' - ', 2)
frame = Timecode.parse(tc, fps = options.fps).total.to_i
output.each do |id,shot|
next if shot.nil? || shot[:start_frame].nil? || shot[:end_frame].nil?
next if shot[:start_frame] > frame
next if shot[:end_frame] < frame
msg = "#{meta}\n#{msg}"
if shot[:notes]
shot[:notes] = "#{shot[:notes]}\n\n====\n\n#{msg}"
else
shot[:notes] = msg
end
end
end
end
CSV.open("data.csv", "wb") do |csv|
csv << ["Shot ID", "Start TC", "Start Frame", "End TC", "End Frame", "Description", "Notes"]
output.each do |id, shot|
csv << [
"#{id}.mov",
shot[:start_tc],
shot[:start_frame],
shot[:end_tc],
shot[:end_frame],
shot[:description],
shot[:notes]
]
end
end
# pp output
end
end
default_command :run