popcap 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b5015395f59243962df0c16cdf70a6e9c9de3d6
4
- data.tar.gz: 7b0608fa5fc3f5fc7e69a8d8e03cb6fb37706cf7
3
+ metadata.gz: 931fd9befcffd1b5ab9805ceff6c8fe297312444
4
+ data.tar.gz: 599f3ed43bdf4b1be7a35f90ea76c7d16d0f08ef
5
5
  SHA512:
6
- metadata.gz: cccf719a0f07c5c48ccca22fa2a8b5c13486dac590d987af767beabe402712bd4073b94c7312c39ad54ee6cbfddc11a5dc122f1f0d30cfff147954aac0c51d52
7
- data.tar.gz: 0cdd2167a5b1e03ed808a944754ed2ca1d5908e07889c63523f073ea1c96def37dc1f25aefdfba2e0f52133845a9fb2d7dbbb31f0605ed9d0c9b685e1b2d3b47
6
+ metadata.gz: 347cd122247302dd21ac0760dfe096d93e768099cc713cde8851d4bc5582998e3c22555d71c82776883781ac01999c51066a51d44835070509b565f9fb4dae9f
7
+ data.tar.gz: 9be5928aa054bdf3838cb3b582dc30d26f688a0683d5387a58fdcf9c7044ae56ccc41ab4c027be8ff7d80310e24c1566714be512a5212e67b7170a84fb5c6792
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ coverage/*
2
2
  *.swp
3
3
  .rbx
4
4
  .rbenv-version
5
+ *.gem
@@ -0,0 +1,50 @@
1
+ require 'pop_cap/ffmpeg/commander'
2
+
3
+ module PopCap
4
+ # Public: This class is similar to TagReader, but is useful for debugging.
5
+ # If a file cannot be read, this will return the error message generated
6
+ # by FFprobe
7
+ #
8
+ class AnalyzeFile
9
+ attr_reader :filepath
10
+
11
+ # Public: Initialize an instance of AnalyzeFile.
12
+ # filepath = relative path to a file on the filesystem
13
+ #
14
+ def initialize(filepath)
15
+ @filepath = File.expand_path(filepath)
16
+ @datetime = Time.now.strftime("%Y-%m-%d at %H:%M:%S")
17
+ end
18
+
19
+ # Public: This method returns the stderr of FFprobe -show_format
20
+ # as an array. The first element is a datetime stamp, the second
21
+ # element is the error message.
22
+ #
23
+ def examine
24
+ [datetimestamp, error]
25
+ end
26
+
27
+ # Public: A convenience class method for examining a file.
28
+ #
29
+ def self.examine(filepath)
30
+ new(filepath).examine
31
+ end
32
+
33
+ private
34
+ def command
35
+ %W{ffprobe -show_format -print_format json} + %W{#{filepath}}
36
+ end
37
+
38
+ def contents
39
+ Commander.new(*command).execute.stderr
40
+ end
41
+
42
+ def datetimestamp
43
+ "FFprobe read error on #{@datetime}"
44
+ end
45
+
46
+ def error
47
+ contents.split("\n").last
48
+ end
49
+ end
50
+ end
@@ -8,7 +8,7 @@ module PopCap
8
8
  # Public: This method will execute the conversion.
9
9
  #
10
10
  def convert
11
- unless commander.new(*command).execute.success?
11
+ unless execute.success?
12
12
  raise(FFmpegError, error_message('converting'))
13
13
  end
14
14
  end
@@ -33,6 +33,12 @@ module PopCap
33
33
  "Error #{message} #{filepath}."
34
34
  end
35
35
 
36
+ # Public: execute a command
37
+ #
38
+ def execute
39
+ @executed ||= commander.new(*command).execute
40
+ end
41
+
36
42
  private
37
43
  def check_for_ffmpeg_install
38
44
  begin
@@ -24,7 +24,7 @@ module PopCap
24
24
  end
25
25
 
26
26
  def output
27
- executed = commander.new(*command).execute
27
+ executed = execute
28
28
  raise(FFmpegError, error_message('reading')) unless executed.success?
29
29
  executed.stdout
30
30
  end
@@ -10,7 +10,8 @@ module PopCap
10
10
  # is done to prevent corrupting the original file.
11
11
  #
12
12
  def write
13
- unless commander.new(*command).execute.success?
13
+ unless execute.success?
14
+ cleanup_failed_write
14
15
  raise(FFmpegError, error_message('writing'))
15
16
  end
16
17
  FileUtils.move(tmppath, filepath)
@@ -24,7 +25,7 @@ module PopCap
24
25
 
25
26
  private
26
27
  def tmppath
27
- '/tmp/' + File.basename(filepath)
28
+ @tmp ||= '/tmp/' + File.basename(filepath)
28
29
  end
29
30
 
30
31
  def command
@@ -40,5 +41,9 @@ module PopCap
40
41
  def clean_tags
41
42
  @cleaned ||= options.reject { |key,_| key == :commander }
42
43
  end
44
+
45
+ def cleanup_failed_write
46
+ FileUtils.rm_f(tmppath)
47
+ end
43
48
  end
44
49
  end
@@ -1,3 +1,3 @@
1
1
  module PopCap
2
- VERSION = '0.9.2'
2
+ VERSION = '0.9.3'
3
3
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'pop_cap/ffmpeg/analyze_file'
3
+ require 'fileutils'
4
+
5
+ module PopCap
6
+ describe AnalyzeFile do
7
+ let(:bad_file) { "#{File.expand_path('spec/fixtures/bad_file.img')}" }
8
+
9
+ before { FileUtils.touch bad_file }
10
+ after { FileUtils.rm_f bad_file }
11
+
12
+ context ".examine" do
13
+ let(:response) { AnalyzeFile.examine(bad_file) }
14
+
15
+ it 'has a datetime stamp' do
16
+ date_regex = %r(FFprobe read error on \d{4}-\d{2}-\d{2} at \d{2}:\d{2}:\d{2})
17
+ expect(response[0]).to match date_regex
18
+ end
19
+
20
+ it 'has the error message' do
21
+ expect(response).
22
+ to include "#{bad_file}: Invalid data found when processing input"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -15,10 +15,6 @@ module PopCap
15
15
  instance.stub_chain(:execute, :stdout) { instance }
16
16
  end
17
17
 
18
- it 'test' do
19
- puts JSON.parse(TagReader.read('spec/fixtures/sample.flac'))
20
- end
21
-
22
18
  describe '.read' do
23
19
  before { shared_example }
24
20
 
@@ -54,6 +54,15 @@ module PopCap
54
54
  writer.write
55
55
  end.to raise_error(FFmpegError, "Error writing #{file}.")
56
56
  end
57
+
58
+ it 'removes the temp file' do
59
+ expect do
60
+ commander.should_receive(:new).with(*command) { instance }
61
+ instance.stub_chain(:execute, :success?) { false }
62
+ FileUtils.should_receive(:rm_f).with('/tmp/file.flac')
63
+ writer.write
64
+ end.to raise_error(FFmpegError, "Error writing #{file}.")
65
+ end
57
66
  end
58
67
  end
59
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popcap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Culley Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-04 00:00:00.000000000 Z
11
+ date: 2013-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reek
@@ -54,6 +54,7 @@ files:
54
54
  - README.md
55
55
  - lib/pop_cap/audio_file.rb
56
56
  - lib/pop_cap/class_support.rb
57
+ - lib/pop_cap/ffmpeg/analyze_file.rb
57
58
  - lib/pop_cap/ffmpeg/commander.rb
58
59
  - lib/pop_cap/ffmpeg/converter.rb
59
60
  - lib/pop_cap/ffmpeg/ffmpeg.rb
@@ -74,6 +75,7 @@ files:
74
75
  - spec/fixtures/sample.flac
75
76
  - spec/lib/pop_cap/audio_file_spec.rb
76
77
  - spec/lib/pop_cap/class_support_spec.rb
78
+ - spec/lib/pop_cap/ffmpeg/analyze_file_spec.rb
77
79
  - spec/lib/pop_cap/ffmpeg/commander_spec.rb
78
80
  - spec/lib/pop_cap/ffmpeg/converter_spec.rb
79
81
  - spec/lib/pop_cap/ffmpeg/ffmpeg_spec.rb
@@ -110,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  version: 1.3.6
111
113
  requirements: []
112
114
  rubyforge_project:
113
- rubygems_version: 2.0.0
115
+ rubygems_version: 2.0.3
114
116
  signing_key:
115
117
  specification_version: 4
116
118
  summary: A library work with audio files on the filesystem .
@@ -118,6 +120,7 @@ test_files:
118
120
  - spec/fixtures/sample.flac
119
121
  - spec/lib/pop_cap/audio_file_spec.rb
120
122
  - spec/lib/pop_cap/class_support_spec.rb
123
+ - spec/lib/pop_cap/ffmpeg/analyze_file_spec.rb
121
124
  - spec/lib/pop_cap/ffmpeg/commander_spec.rb
122
125
  - spec/lib/pop_cap/ffmpeg/converter_spec.rb
123
126
  - spec/lib/pop_cap/ffmpeg/ffmpeg_spec.rb
@@ -135,4 +138,3 @@ test_files:
135
138
  - spec/spec_helper.rb
136
139
  - spec/support/popcap_spec_helper.rb
137
140
  - spec/support/reek_spec.rb
138
- has_rdoc: