popcap 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +23 -32
- data/README.md +27 -24
- data/lib/pop_cap/audio_file.rb +13 -11
- data/lib/pop_cap/class_support.rb +73 -0
- data/lib/pop_cap/{commander.rb → ffmpeg/commander.rb} +8 -2
- data/lib/pop_cap/ffmpeg/converter.rb +57 -0
- data/lib/pop_cap/ffmpeg/ffmpeg.rb +45 -0
- data/lib/pop_cap/ffmpeg/tag_reader.rb +45 -0
- data/lib/pop_cap/ffmpeg/tag_writer.rb +44 -0
- data/lib/pop_cap/formatter.rb +62 -0
- data/lib/pop_cap/formatters/bit_rate.rb +5 -7
- data/lib/pop_cap/formatters/date.rb +12 -10
- data/lib/pop_cap/formatters/duration.rb +10 -12
- data/lib/pop_cap/formatters/filesize.rb +6 -8
- data/lib/pop_cap/tag/formatted_tag.rb +31 -0
- data/lib/pop_cap/tag/tag_hash.rb +55 -0
- data/lib/pop_cap/{tag_struct.rb → tag/tag_struct.rb} +2 -0
- data/lib/pop_cap/taggable.rb +50 -30
- data/lib/pop_cap/version.rb +1 -1
- data/popcap.gemspec +1 -2
- data/spec/integration/convert_audio_file_spec.rb +2 -2
- data/spec/integration/read_metatags_spec.rb +1 -1
- data/spec/integration/update_metatags_spec.rb +1 -1
- data/spec/lib/pop_cap/audio_file_spec.rb +3 -9
- data/spec/lib/pop_cap/class_support_spec.rb +59 -0
- data/spec/lib/pop_cap/{commander_spec.rb → ffmpeg/commander_spec.rb} +1 -1
- data/spec/lib/pop_cap/ffmpeg/converter_spec.rb +92 -0
- data/spec/lib/pop_cap/ffmpeg/ffmpeg_spec.rb +37 -0
- data/spec/lib/pop_cap/ffmpeg/tag_reader_spec.rb +67 -0
- data/spec/lib/pop_cap/ffmpeg/tag_writer_spec.rb +60 -0
- data/spec/lib/pop_cap/fileable_spec.rb +5 -5
- data/spec/lib/pop_cap/formatter_spec.rb +71 -0
- data/spec/lib/pop_cap/formatters/bit_rate_spec.rb +8 -0
- data/spec/lib/pop_cap/formatters/date_spec.rb +8 -0
- data/spec/lib/pop_cap/formatters/duration_spec.rb +8 -0
- data/spec/lib/pop_cap/formatters/filesize_spec.rb +8 -0
- data/spec/lib/pop_cap/tag/formatted_tag_spec.rb +29 -0
- data/spec/lib/pop_cap/tag/tag_hash_spec.rb +35 -0
- data/spec/lib/pop_cap/{tag_struct_spec.rb → tag/tag_struct_spec.rb} +5 -1
- data/spec/lib/pop_cap/taggable_spec.rb +24 -10
- data/spec/spec_helper.rb +0 -3
- data/spec/support/popcap_spec_helper.rb +50 -33
- metadata +40 -56
- data/lib/pop_cap/converter.rb +0 -40
- data/lib/pop_cap/ffmpeg.rb +0 -130
- data/lib/pop_cap/formatters.rb +0 -33
- data/lib/pop_cap/helper.rb +0 -53
- data/lib/pop_cap/tag_key.rb +0 -32
- data/lib/pop_cap/tag_line.rb +0 -36
- data/spec/lib/pop_cap/converter_spec.rb +0 -67
- data/spec/lib/pop_cap/ffmpeg_spec.rb +0 -96
- data/spec/lib/pop_cap/formatters_spec.rb +0 -36
- data/spec/lib/pop_cap/helper_spec.rb +0 -42
- data/spec/lib/pop_cap/tag_key_spec.rb +0 -48
- data/spec/lib/pop_cap/tag_line_spec.rb +0 -26
- /data/spec/{support → fixtures}/sample.flac +0 -0
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: popcap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.8.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Culley Smith
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-03-03 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: reek
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,27 +34,10 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '2.11'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: simplecov
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0.7'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.7'
|
62
41
|
description: Read & write metadata tags, convert audio files to alternate formats,
|
63
42
|
manage files on the filesystem.
|
64
43
|
email:
|
@@ -74,90 +53,95 @@ files:
|
|
74
53
|
- LICENSE
|
75
54
|
- README.md
|
76
55
|
- lib/pop_cap/audio_file.rb
|
77
|
-
- lib/pop_cap/
|
78
|
-
- lib/pop_cap/
|
79
|
-
- lib/pop_cap/ffmpeg.rb
|
56
|
+
- lib/pop_cap/class_support.rb
|
57
|
+
- lib/pop_cap/ffmpeg/commander.rb
|
58
|
+
- lib/pop_cap/ffmpeg/converter.rb
|
59
|
+
- lib/pop_cap/ffmpeg/ffmpeg.rb
|
60
|
+
- lib/pop_cap/ffmpeg/tag_reader.rb
|
61
|
+
- lib/pop_cap/ffmpeg/tag_writer.rb
|
80
62
|
- lib/pop_cap/fileable.rb
|
81
|
-
- lib/pop_cap/
|
63
|
+
- lib/pop_cap/formatter.rb
|
82
64
|
- lib/pop_cap/formatters/bit_rate.rb
|
83
65
|
- lib/pop_cap/formatters/date.rb
|
84
66
|
- lib/pop_cap/formatters/duration.rb
|
85
67
|
- lib/pop_cap/formatters/filesize.rb
|
86
|
-
- lib/pop_cap/
|
87
|
-
- lib/pop_cap/
|
88
|
-
- lib/pop_cap/
|
89
|
-
- lib/pop_cap/tag_struct.rb
|
68
|
+
- lib/pop_cap/tag/formatted_tag.rb
|
69
|
+
- lib/pop_cap/tag/tag_hash.rb
|
70
|
+
- lib/pop_cap/tag/tag_struct.rb
|
90
71
|
- lib/pop_cap/taggable.rb
|
91
72
|
- lib/pop_cap/version.rb
|
92
73
|
- lib/popcap.rb
|
93
74
|
- popcap.gemspec
|
75
|
+
- spec/fixtures/sample.flac
|
94
76
|
- spec/integration/convert_audio_file_spec.rb
|
95
77
|
- spec/integration/read_metatags_spec.rb
|
96
78
|
- spec/integration/update_metatags_spec.rb
|
97
79
|
- spec/lib/pop_cap/audio_file_spec.rb
|
98
|
-
- spec/lib/pop_cap/
|
99
|
-
- spec/lib/pop_cap/
|
100
|
-
- spec/lib/pop_cap/
|
80
|
+
- spec/lib/pop_cap/class_support_spec.rb
|
81
|
+
- spec/lib/pop_cap/ffmpeg/commander_spec.rb
|
82
|
+
- spec/lib/pop_cap/ffmpeg/converter_spec.rb
|
83
|
+
- spec/lib/pop_cap/ffmpeg/ffmpeg_spec.rb
|
84
|
+
- spec/lib/pop_cap/ffmpeg/tag_reader_spec.rb
|
85
|
+
- spec/lib/pop_cap/ffmpeg/tag_writer_spec.rb
|
101
86
|
- spec/lib/pop_cap/fileable_spec.rb
|
87
|
+
- spec/lib/pop_cap/formatter_spec.rb
|
102
88
|
- spec/lib/pop_cap/formatters/bit_rate_spec.rb
|
103
89
|
- spec/lib/pop_cap/formatters/date_spec.rb
|
104
90
|
- spec/lib/pop_cap/formatters/duration_spec.rb
|
105
91
|
- spec/lib/pop_cap/formatters/filesize_spec.rb
|
106
|
-
- spec/lib/pop_cap/
|
107
|
-
- spec/lib/pop_cap/
|
108
|
-
- spec/lib/pop_cap/
|
109
|
-
- spec/lib/pop_cap/tag_line_spec.rb
|
110
|
-
- spec/lib/pop_cap/tag_struct_spec.rb
|
92
|
+
- spec/lib/pop_cap/tag/formatted_tag_spec.rb
|
93
|
+
- spec/lib/pop_cap/tag/tag_hash_spec.rb
|
94
|
+
- spec/lib/pop_cap/tag/tag_struct_spec.rb
|
111
95
|
- spec/lib/pop_cap/taggable_spec.rb
|
112
96
|
- spec/spec_helper.rb
|
113
97
|
- spec/support/popcap_spec_helper.rb
|
114
98
|
- spec/support/reek_spec.rb
|
115
|
-
- spec/support/sample.flac
|
116
99
|
homepage: http://madstance.com
|
117
100
|
licenses: []
|
101
|
+
metadata: {}
|
118
102
|
post_install_message:
|
119
103
|
rdoc_options: []
|
120
104
|
require_paths:
|
121
105
|
- lib
|
122
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
107
|
requirements:
|
125
|
-
- -
|
108
|
+
- - '>='
|
126
109
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
110
|
+
version: 2.0.0
|
128
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
112
|
requirements:
|
131
|
-
- -
|
113
|
+
- - '>='
|
132
114
|
- !ruby/object:Gem::Version
|
133
115
|
version: 1.3.6
|
134
116
|
requirements: []
|
135
117
|
rubyforge_project:
|
136
|
-
rubygems_version:
|
118
|
+
rubygems_version: 2.0.0
|
137
119
|
signing_key:
|
138
|
-
specification_version:
|
120
|
+
specification_version: 4
|
139
121
|
summary: A library work with audio files on the filesystem .
|
140
122
|
test_files:
|
123
|
+
- spec/fixtures/sample.flac
|
141
124
|
- spec/integration/convert_audio_file_spec.rb
|
142
125
|
- spec/integration/read_metatags_spec.rb
|
143
126
|
- spec/integration/update_metatags_spec.rb
|
144
127
|
- spec/lib/pop_cap/audio_file_spec.rb
|
145
|
-
- spec/lib/pop_cap/
|
146
|
-
- spec/lib/pop_cap/
|
147
|
-
- spec/lib/pop_cap/
|
128
|
+
- spec/lib/pop_cap/class_support_spec.rb
|
129
|
+
- spec/lib/pop_cap/ffmpeg/commander_spec.rb
|
130
|
+
- spec/lib/pop_cap/ffmpeg/converter_spec.rb
|
131
|
+
- spec/lib/pop_cap/ffmpeg/ffmpeg_spec.rb
|
132
|
+
- spec/lib/pop_cap/ffmpeg/tag_reader_spec.rb
|
133
|
+
- spec/lib/pop_cap/ffmpeg/tag_writer_spec.rb
|
148
134
|
- spec/lib/pop_cap/fileable_spec.rb
|
135
|
+
- spec/lib/pop_cap/formatter_spec.rb
|
149
136
|
- spec/lib/pop_cap/formatters/bit_rate_spec.rb
|
150
137
|
- spec/lib/pop_cap/formatters/date_spec.rb
|
151
138
|
- spec/lib/pop_cap/formatters/duration_spec.rb
|
152
139
|
- spec/lib/pop_cap/formatters/filesize_spec.rb
|
153
|
-
- spec/lib/pop_cap/
|
154
|
-
- spec/lib/pop_cap/
|
155
|
-
- spec/lib/pop_cap/
|
156
|
-
- spec/lib/pop_cap/tag_line_spec.rb
|
157
|
-
- spec/lib/pop_cap/tag_struct_spec.rb
|
140
|
+
- spec/lib/pop_cap/tag/formatted_tag_spec.rb
|
141
|
+
- spec/lib/pop_cap/tag/tag_hash_spec.rb
|
142
|
+
- spec/lib/pop_cap/tag/tag_struct_spec.rb
|
158
143
|
- spec/lib/pop_cap/taggable_spec.rb
|
159
144
|
- spec/spec_helper.rb
|
160
145
|
- spec/support/popcap_spec_helper.rb
|
161
146
|
- spec/support/reek_spec.rb
|
162
|
-
- spec/support/sample.flac
|
163
147
|
has_rdoc:
|
data/lib/pop_cap/converter.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module PopCap
|
2
|
-
# Internal: This module builds a command to convert an audio file
|
3
|
-
# to the specified output format. The module is included in FFmpeg.
|
4
|
-
#
|
5
|
-
module Converter
|
6
|
-
# Internal: This method takes an input format & optional bitrate
|
7
|
-
# in order to supply the ffmpeg command used to convert.
|
8
|
-
#
|
9
|
-
# format - Provide a valid format as a string or symbol.
|
10
|
-
# bitrate - Provide a valid bitrate as a string or integer.
|
11
|
-
#
|
12
|
-
def convert(format, bitrate=192)
|
13
|
-
@bitrate = bitrate
|
14
|
-
@format = format.downcase.to_s
|
15
|
-
input_path + strict_mode + bitrate_options + output_path
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
def bitrate_options
|
20
|
-
%W{-ab #{@bitrate}k}
|
21
|
-
end
|
22
|
-
|
23
|
-
def input_path
|
24
|
-
%W{ffmpeg -i #{self.filepath}}
|
25
|
-
end
|
26
|
-
|
27
|
-
def output_path
|
28
|
-
%W{#{self.filepath.sub(%r([^.]+\z),@format)}}
|
29
|
-
end
|
30
|
-
|
31
|
-
def strict_mode
|
32
|
-
return %W{} unless use_strict_mode?
|
33
|
-
%W{-strict -2}
|
34
|
-
end
|
35
|
-
|
36
|
-
def use_strict_mode?
|
37
|
-
@format == 'm4a'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/pop_cap/ffmpeg.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
require 'pop_cap/commander'
|
2
|
-
require 'pop_cap/converter'
|
3
|
-
require 'pop_cap/fileable'
|
4
|
-
|
5
|
-
module PopCap
|
6
|
-
MissingDependency = Class.new(Errno::ENOENT)
|
7
|
-
# Internal: This is a wrapper for the FFmpeg C library.
|
8
|
-
#
|
9
|
-
# Examples
|
10
|
-
#
|
11
|
-
# filepath = 'spec/support/sample.flac'
|
12
|
-
# ffmpeg = FFmpeg.new(filepath)
|
13
|
-
#
|
14
|
-
class FFmpeg
|
15
|
-
include Converter
|
16
|
-
include Fileable
|
17
|
-
|
18
|
-
attr_accessor :filepath
|
19
|
-
|
20
|
-
# Internal: initialize
|
21
|
-
#
|
22
|
-
# filepath - Requires a valid filepath to a file on the local filesystem.
|
23
|
-
#
|
24
|
-
def initialize(filepath)
|
25
|
-
check_for_ffmpeg_install
|
26
|
-
@filepath = filepath
|
27
|
-
end
|
28
|
-
|
29
|
-
# Internal: convert
|
30
|
-
# This command calls up to Converter@convert.
|
31
|
-
#
|
32
|
-
# format - A valid audio file format as string or symbol.
|
33
|
-
# bitrate = A valid bit rate as string or symbol.
|
34
|
-
#
|
35
|
-
def convert(format, bitrate=192)
|
36
|
-
conversion = super(format,bitrate)
|
37
|
-
Commander.new(*conversion).execute
|
38
|
-
end
|
39
|
-
|
40
|
-
# Internal: read_tags
|
41
|
-
# Returns the raw output of FFProbe's show_format option.
|
42
|
-
#
|
43
|
-
# Examples
|
44
|
-
#
|
45
|
-
# [FORMAT]
|
46
|
-
# filename=spec/support/sample.flac
|
47
|
-
# nb_streams=1
|
48
|
-
# format_name=flac
|
49
|
-
# format_long_name=raw FLAC
|
50
|
-
# start_time=N/A
|
51
|
-
# duration=1.000000
|
52
|
-
# size=18291
|
53
|
-
# bit_rate=146328
|
54
|
-
# TAG:GENRE=Sample Genre
|
55
|
-
# TAG:track=01
|
56
|
-
# TAG:ALBUM=Sample Album
|
57
|
-
# TAG:DATE=2012
|
58
|
-
# TAG:TITLE=Sample Title
|
59
|
-
# TAG:ARTIST=Sample Artist
|
60
|
-
# [/FORMAT]
|
61
|
-
#
|
62
|
-
def read_tags
|
63
|
-
@stdout ||= encode(read_output)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Internal: update_tags(updates)
|
67
|
-
# This wraps FFmpeg's -metadata command.
|
68
|
-
#
|
69
|
-
# Examples
|
70
|
-
# filepath = 'spec/support/sample.flac'
|
71
|
-
# ffmpeg = FFmpeg.new(filepath)
|
72
|
-
# ffmpeg.update_tags({artist: 'New Artist'})
|
73
|
-
#
|
74
|
-
def update_tags(updates)
|
75
|
-
@updates = updates
|
76
|
-
unless Commander.new(*write_command).execute.success?
|
77
|
-
raise(FFmpegError, write_error_message)
|
78
|
-
end
|
79
|
-
self.restore('/tmp')
|
80
|
-
@stdout = nil
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
def check_for_ffmpeg_install
|
85
|
-
begin
|
86
|
-
Open3.capture3('ffmpeg')
|
87
|
-
rescue Errno::ENOENT
|
88
|
-
raise MissingDependency, 'FFmpeg is not installed.'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def encode(string)
|
93
|
-
return string if string.valid_encoding?
|
94
|
-
original_encoding = string.encoding.name
|
95
|
-
string.encode!('UTF-16', original_encoding, undef:
|
96
|
-
:replace, invalid: :replace)
|
97
|
-
string.encode!('UTF-8')
|
98
|
-
end
|
99
|
-
|
100
|
-
def read_command
|
101
|
-
%W{ffprobe -show_format} + %W{#{filepath}}
|
102
|
-
end
|
103
|
-
|
104
|
-
def read_output
|
105
|
-
commander = Commander.new(*read_command).execute
|
106
|
-
raise(FFmpegError, read_error_message) unless commander.success?
|
107
|
-
commander.stdout
|
108
|
-
end
|
109
|
-
|
110
|
-
def read_error_message
|
111
|
-
"Error reading #{self.filepath}"
|
112
|
-
end
|
113
|
-
|
114
|
-
def write_command
|
115
|
-
%W{ffmpeg -i #{filepath}} + write_options + %W{#{self.tmppath}}
|
116
|
-
end
|
117
|
-
|
118
|
-
def write_options
|
119
|
-
@updates.inject(%W{}) do |options,update|
|
120
|
-
options << '-metadata' << update.join('=')
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def write_error_message
|
125
|
-
"Error updating #{self.filepath}"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
FFmpegError = Class.new(StandardError)
|
data/lib/pop_cap/formatters.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module PopCap
|
2
|
-
# Internal: This module requires all formatters in "formatters/."
|
3
|
-
#
|
4
|
-
module Formatters
|
5
|
-
# Internal: This constant is a hash of all files in "formatters/."
|
6
|
-
# To add new custom formatters to Taggable#tags, add the formatter
|
7
|
-
# to "formatters/."
|
8
|
-
#
|
9
|
-
# Formatters should follow this format:
|
10
|
-
#
|
11
|
-
# Examples
|
12
|
-
# attribute - :custom_formatter
|
13
|
-
# path - lib/pop_cap/formatters/custom_formatter.rb
|
14
|
-
# class - CustomFormatter
|
15
|
-
# format instance method - #format
|
16
|
-
#
|
17
|
-
# # lib/pop_cap/formatters/custom_formatter.rb
|
18
|
-
# class CustomFormatter
|
19
|
-
# def format
|
20
|
-
# # code that formats
|
21
|
-
# end
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
::INCLUDED_FORMATTERS= {}
|
25
|
-
|
26
|
-
Dir["#{File.dirname(__FILE__)}/formatters/*.rb"].each do |path|
|
27
|
-
@file_name = File.basename(path , '.rb')
|
28
|
-
@required = 'pop_cap/formatters/' + @file_name
|
29
|
-
require @required
|
30
|
-
::INCLUDED_FORMATTERS[@file_name.to_sym] = @required
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/pop_cap/helper.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module PopCap
|
2
|
-
# Public: This class adds helper methods to construct a class.
|
3
|
-
#
|
4
|
-
# name - This is the name of the class.
|
5
|
-
#
|
6
|
-
# Examples
|
7
|
-
# Helper.new('array')
|
8
|
-
# Helper.new('active_support')
|
9
|
-
# Helper.new('active_record/base')
|
10
|
-
#
|
11
|
-
class Helper
|
12
|
-
def initialize(name)
|
13
|
-
@name = name.to_s
|
14
|
-
end
|
15
|
-
|
16
|
-
# Public: This method camel cases a string or symbol.
|
17
|
-
#
|
18
|
-
# Examples
|
19
|
-
# helper = Helper.new('active_support')
|
20
|
-
# helper.camelize
|
21
|
-
# # => 'ActiveSupport'
|
22
|
-
#
|
23
|
-
def camelize
|
24
|
-
@name.split('_').map { |word| word.capitalize }.join
|
25
|
-
end
|
26
|
-
|
27
|
-
# Public: This namespaces a string by converting a filepath
|
28
|
-
# to a namespaced constant.
|
29
|
-
#
|
30
|
-
# Examples
|
31
|
-
# helper = Helper.new('active_record/base')
|
32
|
-
# helper.namespace
|
33
|
-
# # => 'ActiveRecord::Base'
|
34
|
-
#
|
35
|
-
def namespace
|
36
|
-
camelize.split('/').map do |word|
|
37
|
-
_,head,tail = word.partition(%r(^[a-zA-Z]))
|
38
|
-
head.upcase + tail
|
39
|
-
end.join('::')
|
40
|
-
end
|
41
|
-
|
42
|
-
# Public: This converts a string into a constant.
|
43
|
-
#
|
44
|
-
# Examples
|
45
|
-
# helper = Helper.new('active_record/base')
|
46
|
-
# helper.constantize
|
47
|
-
# # => ActiveSupport::Base
|
48
|
-
#
|
49
|
-
def constantize
|
50
|
-
Object.module_eval(namespace)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/lib/pop_cap/tag_key.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module PopCap
|
2
|
-
# Internal: This class sanitizes the raw output of FFmpeg to
|
3
|
-
# be used as a hash key.
|
4
|
-
#
|
5
|
-
# key - This is a single key as created by TagLine.
|
6
|
-
#
|
7
|
-
class TagKey
|
8
|
-
def initialize(key)
|
9
|
-
@key = key
|
10
|
-
end
|
11
|
-
|
12
|
-
# Internal: This method removes unwanted strings, downcases,
|
13
|
-
# & symbolizes a key. Additionally, it renames keys named
|
14
|
-
# 'size' to 'filesize' in order to avoid potential conflicts
|
15
|
-
# with Ruby's build-in method of the same name.
|
16
|
-
#
|
17
|
-
# Examples
|
18
|
-
# tk = TagKey.new('size')
|
19
|
-
# tk.format
|
20
|
-
# # => :filesize
|
21
|
-
#
|
22
|
-
def format
|
23
|
-
return '' if ( @key.nil? || @key.empty? )
|
24
|
-
|
25
|
-
@key.
|
26
|
-
sub(/^TAG:/,'').
|
27
|
-
sub(/^size\b/,'filesize').
|
28
|
-
downcase.
|
29
|
-
to_sym
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/pop_cap/tag_line.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'pop_cap/tag_key'
|
2
|
-
require 'pop_cap/formatters'
|
3
|
-
|
4
|
-
module PopCap
|
5
|
-
# Internal: This class sanitizes the raw output of FFmpeg to
|
6
|
-
# and builds a hash.
|
7
|
-
#
|
8
|
-
# line - This is a single line of raw output from FFmpeg.
|
9
|
-
#
|
10
|
-
class TagLine
|
11
|
-
include
|
12
|
-
def initialize(line)
|
13
|
-
@line = line
|
14
|
-
end
|
15
|
-
|
16
|
-
# Internal: This method builds a hash by splitting on the
|
17
|
-
# first equal sign in a single line of content from FFmpeg.
|
18
|
-
# It uses TagKey to create the key for the hash.
|
19
|
-
#
|
20
|
-
# Examples
|
21
|
-
# tl = TagLine.new('TAG:ARTIST=David Bowie')
|
22
|
-
# to.to_hash
|
23
|
-
# # => {artist: 'David Bowie'}
|
24
|
-
#
|
25
|
-
def to_hash
|
26
|
-
return {} unless ( @line && is_a_tag? )
|
27
|
-
key,val = @line.split('=',2)
|
28
|
-
{TagKey.new(key).format => val}
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
def is_a_tag?
|
33
|
-
@line.match('=')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pop_cap/converter'
|
3
|
-
|
4
|
-
module PopCap
|
5
|
-
describe Converter do
|
6
|
-
class FakeClass
|
7
|
-
include Converter
|
8
|
-
def filepath
|
9
|
-
'path/to/file.flac'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:bitrate) { %W{-ab 192k}}
|
14
|
-
let(:filepath) { 'path/to/file.flac' }
|
15
|
-
let(:fk) { FakeClass.new }
|
16
|
-
let(:input) { %W{ffmpeg -i #{filepath}} }
|
17
|
-
|
18
|
-
context '#command' do
|
19
|
-
let(:output_path) { %W{path/to/file.ogg} }
|
20
|
-
|
21
|
-
it 'builds a command' do
|
22
|
-
expect(fk.convert('ogg')).to eq(input + bitrate + output_path)
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'format' do
|
26
|
-
it 'handles symbol' do
|
27
|
-
expect(fk.convert(:ogg)).to eq(input + bitrate + output_path)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'is case insenstive' do
|
31
|
-
expect(fk.convert('OGG')).to eq(input + bitrate + output_path)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'bitrate' do
|
36
|
-
let(:output_path) { %W{path/to/file.mp3} }
|
37
|
-
|
38
|
-
it 'defaults to 192 kb/s' do
|
39
|
-
expect(fk.convert(:mp3)).to eq(input + %W{-ab 192k} + output_path)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'takes an optional bitrate' do
|
43
|
-
expect(fk.convert(:mp3, 64)).to eq(input + %W{-ab 64k} + output_path)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'handles bitrate as string' do
|
47
|
-
expect(fk.convert(:mp3, '128')).
|
48
|
-
to eq(input + %W{-ab 128k} + output_path)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'm4a' do
|
53
|
-
let(:output_path) { %W{path/to/file.m4a} }
|
54
|
-
|
55
|
-
it 'uses strict mode' do
|
56
|
-
expect(fk.convert(:m4a)).
|
57
|
-
to eq(input + %W{-strict -2} + bitrate + output_path)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'ignores strict mode if not m4a' do
|
61
|
-
expect(fk.convert(:ogg)).
|
62
|
-
to eq(input + bitrate + %W{path/to/file.ogg})
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'support/popcap_spec_helper'
|
3
|
-
require 'pop_cap/ffmpeg'
|
4
|
-
|
5
|
-
module PopCap
|
6
|
-
describe FFmpeg do
|
7
|
-
before { PopCapSpecHelper.setup }
|
8
|
-
after { PopCapSpecHelper.teardown }
|
9
|
-
|
10
|
-
let(:commander) { double('Commander') }
|
11
|
-
let(:filepath) { File.realpath('spec/support/sample.flac') }
|
12
|
-
let(:ffmpeg) { FFmpeg.new(filepath) }
|
13
|
-
|
14
|
-
it 'returns its filepath' do
|
15
|
-
expect(ffmpeg.filepath).to eq filepath
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'raises error if FFmpeg not installed' do
|
19
|
-
error_message = 'No such file or directory - FFmpeg is not installed.'
|
20
|
-
expect do
|
21
|
-
Open3.stub(:capture3).with('ffmpeg').and_raise(Errno::ENOENT)
|
22
|
-
FFmpeg.new('filepath')
|
23
|
-
end.to raise_error(MissingDependency, error_message)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'includes Fileable' do
|
27
|
-
expect(FFmpeg.included_modules).to include Fileable
|
28
|
-
end
|
29
|
-
|
30
|
-
context '#read_tags' do
|
31
|
-
let(:output) { double('output') }
|
32
|
-
|
33
|
-
it 'sends a read command to Commander' do
|
34
|
-
expect(ffmpeg.read_tags).to eq PopCapSpecHelper.raw_tags
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'encodes invalid byte strings as UTF-8' do
|
38
|
-
Commander.stub_chain(:new, :execute) { output }
|
39
|
-
output.should_receive(:success?) { true }
|
40
|
-
output.should_receive(:stdout) { output }
|
41
|
-
output.stub(:valid_encoding?) { false }
|
42
|
-
output.stub_chain(:encoding, :name) { 'UTF-8' }
|
43
|
-
output.should_receive(:encode!).
|
44
|
-
with('UTF-16', 'UTF-8', undef: :replace, invalid: :replace)
|
45
|
-
output.should_receive(:encode!).with('UTF-8')
|
46
|
-
ffmpeg.read_tags
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'raises error if could not read tags' do
|
50
|
-
expect do
|
51
|
-
failed = double('commander', :success? => false)
|
52
|
-
Commander.stub_chain(:new, :execute) { failed }
|
53
|
-
ffmpeg.read_tags
|
54
|
-
end.
|
55
|
-
to raise_error(FFmpegError, 'Error reading ' + filepath)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context '#update_tags' do
|
60
|
-
let(:new_tags) { {artist: 'UPDATEDARTIST'} }
|
61
|
-
|
62
|
-
it 'updates tags on a temp file & copies temp file to original' do
|
63
|
-
expect(ffmpeg.read_tags).to match /Sample Artist/
|
64
|
-
ffmpeg.update_tags(new_tags)
|
65
|
-
expect(ffmpeg.read_tags).to match /UPDATEDARTIST/
|
66
|
-
expect(ffmpeg.read_tags).not_to match /Sample Artist/
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'reloads read_tags' do
|
70
|
-
ffmpeg.read_tags
|
71
|
-
Commander.stub_chain(:new, :execute).
|
72
|
-
and_return(double('output', success?: true))
|
73
|
-
ffmpeg.stub(:restore)
|
74
|
-
ffmpeg.update_tags({})
|
75
|
-
expect(ffmpeg.instance_variable_get('@stdout')).to be_nil
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'raises error if could not update tags' do
|
79
|
-
expect do
|
80
|
-
failed = double('commander', :success? => false)
|
81
|
-
Commander.stub_chain(:new, :execute) { failed }
|
82
|
-
ffmpeg.update_tags({})
|
83
|
-
end.
|
84
|
-
to raise_error(FFmpegError, 'Error updating ' + filepath)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context '#convert' do
|
89
|
-
it 'converts from input format to specified output format & bitrate' do
|
90
|
-
ffmpeg.convert(:mp3, 64)
|
91
|
-
mp3 = FFmpeg.new(File.realpath('spec/support/sample.mp3'))
|
92
|
-
expect(mp3.read_tags).to match /format_name=mp3/
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|