Skip to content

Commit

Permalink
Fix double comments and capture comments without a star
Browse files Browse the repository at this point in the history
  • Loading branch information
julik committed Jan 16, 2009
1 parent d40b75d commit 751b6ae
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 11 deletions.
5 changes: 5 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
=== 0.0.6 / 2000-01-14

* Fix comments in events appearing twice
* Capture extra comments that have no star at the beginning as fallback

=== 0.0.5 / 2000-01-14

* EDL::Event#starts_with_transition? is an alias
Expand Down
12 changes: 11 additions & 1 deletion SPECS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* parse from a File/IOish
* properly parse a dissolve
* return a spliced EDL if the sources allow
* not apply any Matchers if a match is found (empty)

== A TimewarpMatcher should
* not create any extra events when used within a Parser
Expand All @@ -62,6 +63,12 @@
* match a comment
* apply the comment to the last clip on the stack

== FallbackMatcher should
* match anything
* not match whitespace
* append the matched content to comments
* raise an ApplyError if no clip is on the stack

== ClipNameMatcher should
* match a clip name
* not match a simple comment
Expand All @@ -79,7 +86,10 @@
== A FinalCutPro speedup with fade at the end should
* be parsed cleanly

== In the trailer EDL the event 4 should
* not have too many comments

== A FinalCutPro speedup and reverse with fade at the end should
* parse cleanly

59 specifications, 1 empty (161 requirements), 0 failures
65 specifications, 2 empty (168 requirements), 0 failures
32 changes: 23 additions & 9 deletions lib/edl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# A simplistic EDL parser
module EDL
VERSION = "0.0.5"
VERSION = "0.0.6"
DEFAULT_FPS = 25

# Represents an EDL, is returned from the parser. Traditional operation is functional style, i.e.
Expand Down Expand Up @@ -159,6 +159,21 @@ def apply(stack, line)
stack[-1].comments << line.scan(@regexp).flatten.pop.strip
end
end

# Fallback matcher for things like FINAL CUT PRO REEL
class FallbackMatcher < Matcher
def initialize
super(/^(\w)(.+)/)
end

def apply(stack, line)
begin
stack[-1].comments << line.scan(@regexp).flatten.join.strip
rescue NoMethodError
raise ApplyError.new("Line can only be a comment but no event was on the stack", line)
end
end
end

# Clip name matcher
class NameMatcher < Matcher
Expand Down Expand Up @@ -322,14 +337,13 @@ def parse(io)
stack, matchers = List.new, get_matchers
until io.eof?
current_line = io.gets.strip
matchers.each do | matcher |
next unless matcher.matches?(current_line)

begin
matcher.apply(stack, current_line)
rescue Matcher::ApplyError => e
STDERR.puts "Cannot parse #{current_line} - #{e}"
end
m = matchers.find{|m| m.matches?(current_line) }
next unless m

begin
m.apply(stack, current_line)
rescue Matcher::ApplyError => e
STDERR.puts "Cannot parse #{current_line} - #{e}"
end
end
stack
Expand Down
2 changes: 1 addition & 1 deletion lib/edl/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def comments #:nodoc:
end

def outgoing_transition_duration #:nodoc:
@outgoing_transition_duration || 0
@outgoing_transition_duration ||= 0
end

# Is the clip reversed in the edit?
Expand Down
51 changes: 51 additions & 0 deletions test/test_edl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ def tc(fps = Timecode::DEFAULT_FPS)
@spliced[0].src_start_tc.should.equal '06:42:50:18'.tc
@spliced[0].src_end_tc.should.equal '06:42:52:16'.tc
end

specify "not apply any Matchers if a match is found" do
p = EDL::Parser.new
m1 = flexmock
m1.should_receive(:matches?).with("plop").once.and_return(true)
m1.should_receive(:apply).once

flexmock(p).should_receive(:get_matchers).once.and_return([m1, m1])

p.parse("plop")
end
end

context "A TimewarpMatcher should" do
Expand Down Expand Up @@ -485,6 +496,38 @@ def tc(fps = Timecode::DEFAULT_FPS)
end
end

context "FallbackMatcher should" do
specify "match anything" do
line = "SOME"
EDL::FallbackMatcher.new.matches?(line).should.equal true

line = "OR ANOTHER "
EDL::FallbackMatcher.new.matches?(line).should.equal true
end

specify "not match whitespace" do
line = "\s\s\s\r\n\r"
EDL::FallbackMatcher.new.matches?(line).should.equal false
end

specify "append the matched content to comments" do
e = flexmock
cmts = []
e.should_receive(:comments).and_return(cmts)

EDL::FallbackMatcher.new.apply([e], "FOOBAR")
cmts.should.equal ["FOOBAR"]

EDL::FallbackMatcher.new.apply([e], "FINAL CUT PRO REEL: 006-I REPLACED BY: 006I")
cmts.should.equal ["FOOBAR", "FINAL CUT PRO REEL: 006-I REPLACED BY: 006I"]
end

specify "raise an ApplyError if no clip is on the stack" do
lambda { EDL::FallbackMatcher.new.apply([], "FINAL CUT PRO REEL: 006-I REPLACED BY: 006I") }.should.raise(EDL::Matcher::ApplyError)
end

end

context "ClipNameMatcher should" do
specify "match a clip name" do
line = "* FROM CLIP NAME: TAPE_6-10.MOV"
Expand Down Expand Up @@ -580,6 +623,14 @@ def tc(fps = Timecode::DEFAULT_FPS)
end
end

context "In the trailer EDL the event 4 should" do
specify "not have too many comments" do
evts = EDL::Parser.new.parse(File.open(TRAILER_EDL))
evt = evts[6]
evt.comments.length.should.equal(5)
end
end

context "A FinalCutPro speedup and reverse with fade at the end should" do
specify "parse cleanly" do
first_evt = EDL::Parser.new.parse(File.open(SPEEDUP_REVERSE_AND_FADEOUT)).shift
Expand Down

0 comments on commit 751b6ae

Please sign in to comment.