dragonfly_audio 0.0.1 → 0.0.2

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: 6a170d383f614e2e631182e1f7b46e83c99ae0d6
4
- data.tar.gz: c7ef98a7e4fb7de069928e98a0f87f22da054322
3
+ metadata.gz: ea5b12c33329b64884570596ad8e06ffd530f830
4
+ data.tar.gz: a13834b59b263db518b796b8b7765fac83201883
5
5
  SHA512:
6
- metadata.gz: e6ddcbf3f71a510e4ac002ce582a93f477eb5ab5e3cc28b2ab6bf86b457c5360b75d3863c984cc9997985749dd45d5e445db6be7d132fab5f434d8a940516a95
7
- data.tar.gz: c822ee6493eab379b2634d52769f3937764e78b7f66163fc705bc3956246e89d00e6d87a152cc1d01e167988040b353f2da92c96a5ce25898e4d757c8ebe1039
6
+ metadata.gz: 4febcf182f5c3874e6010d52c3a7ec686f30f33a51b1a1469e02a7133ece2ff6766e800755e37fb3f8136b259546353861dd695f056ba04753a802b1fdd9a688
7
+ data.tar.gz: 3c79cf398b489981b612a87282b1554e5aa24897096d5db35aadd02ef8c93451b50ba1a925cbb556c8e03223c0e211faee0fec301827d8c427789c56680fbf48
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  .DS_Store
2
+ pkg
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ cache: bundler
3
+ script: 'bundle exec rake'
4
+ rvm:
5
+ - 2.2.5
6
+ before_install:
7
+ - sudo apt-get update
8
+ - sudo apt-get install -y libtag1-dev
9
+
10
+ notifications:
11
+ email:
12
+ recipients:
13
+ - tomas.celizna@gmail.com
14
+ on_failure: change
15
+ on_success: never
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dragonfly_audio (0.0.1)
4
+ dragonfly_audio (0.0.2)
5
5
  dragonfly (~> 1.0)
6
6
  taglib-ruby
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.3.8)
11
+ addressable (2.4.0)
12
12
  coderay (1.1.0)
13
13
  dragonfly (1.0.12)
14
14
  addressable (~> 2.3)
@@ -34,12 +34,9 @@ GEM
34
34
  rb-inotify (>= 0.9)
35
35
  lumberjack (1.0.9)
36
36
  method_source (0.8.2)
37
- mini_portile (0.6.2)
38
37
  minitest (5.8.1)
39
- multi_json (1.11.2)
38
+ multi_json (1.12.1)
40
39
  nenv (0.2.0)
41
- nokogiri (1.6.6.2)
42
- mini_portile (~> 0.6.0)
43
40
  notiffany (0.0.8)
44
41
  nenv (~> 0.1)
45
42
  shellany (~> 0.0)
@@ -47,14 +44,14 @@ GEM
47
44
  coderay (~> 1.1.0)
48
45
  method_source (~> 0.8.1)
49
46
  slop (~> 3.4)
50
- rack (1.6.4)
47
+ rack (2.0.1)
51
48
  rake (10.4.2)
52
49
  rb-fsevent (0.9.6)
53
50
  rb-inotify (0.9.5)
54
51
  ffi (>= 0.5.0)
55
52
  shellany (0.0.1)
56
53
  slop (3.6.0)
57
- taglib-ruby (0.7.0)
54
+ taglib-ruby (0.7.1)
58
55
  thor (0.19.1)
59
56
 
60
57
  PLATFORMS
@@ -66,5 +63,7 @@ DEPENDENCIES
66
63
  guard
67
64
  guard-minitest
68
65
  minitest
69
- nokogiri
70
66
  rake
67
+
68
+ BUNDLED WITH
69
+ 1.12.5
data/Guardfile CHANGED
@@ -2,7 +2,7 @@
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
4
  guard :minitest do
5
- watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
5
+ watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
6
6
  watch(%r{^test/.+_test\.rb$})
7
- watch(%r{^test/test_helper\.rb$}) { 'test' }
7
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
8
8
  end
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Dragonfly Audio
2
2
 
3
+ [![Build Status](https://travis-ci.org/tomasc/dragonfly_audio.svg)](https://travis-ci.org/tomasc/dragonfly_audio) [![Gem Version](https://badge.fury.io/rb/dragonfly_audio.svg)](http://badge.fury.io/rb/dragonfly_audio) [![Coverage Status](https://img.shields.io/coveralls/tomasc/dragonfly_audio.svg)](https://coveralls.io/r/tomasc/mongoid_recurring)
4
+
3
5
  Wraps common audio-related tasks into [Dragonfly](http://markevans.github.io/dragonfly) analysers and processors.
4
6
 
5
7
  ## Installation
@@ -18,6 +20,8 @@ Or install it yourself as:
18
20
 
19
21
  ## Dependencies
20
22
 
23
+ This gem uses [taglib-ruby](https://github.com/robinst/taglib-ruby) to read and write meta data and properties of audio files.
24
+
21
25
  ## Usage
22
26
 
23
27
  Add the `:audio` plugin to your Dragonfly config block:
@@ -30,8 +34,48 @@ end
30
34
 
31
35
  ## Analysers
32
36
 
37
+ ### audio_properties
38
+
39
+ Reads properties and tags of an audio file:
40
+
41
+ ```ruby
42
+ audio.audio_properties
43
+
44
+ # => {
45
+ # title: 'The Ship Was Sailing',
46
+ # artist: 'Vito Ricci',
47
+ # album: 'Music From Memory',
48
+ # year: '1985',
49
+ # track: 7
50
+ # genre: 'Ambient',
51
+ # comment: 'This Music was originally composed for "The Memory Theatre of Gulio Camillo" by Matthew Maguire. A Creation production premiered at La Mama Spring 1985 thanks to Bonnie for not laughing to Justin for laughing to Jon Gordron for electronic bondage produced by Jonathan Mann for Pangea Productions recorded 8/85 at Chiens Interdits Studio in a big cover production by Ann Rower cover design by Paul Leone * all compositions by Vito Ricci * play it loud',
52
+ # length: 345,
53
+ # bitrate: 192,
54
+ # channels: 2,
55
+ # sample_rate: 44_100
56
+ # }
57
+ ```
58
+
33
59
  ## Processors
34
60
 
61
+ ### tag
62
+
63
+ Sets the file's meta information:
64
+
65
+ ```ruby
66
+ audio.tag(artist: 'Ariel Kalma', album: 'Le Temps Des Moissons', track: 'Bakafrika')
67
+ ```
68
+
69
+ Permissible properties:
70
+ * album
71
+ * artist
72
+ * comment
73
+ * genre
74
+ * tag
75
+ * title
76
+ * track
77
+ * year
78
+
35
79
  ## Contributing
36
80
 
37
81
  1. Fork it ( https://github.com/tomasc/dragonfly_audio/fork )
@@ -4,26 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'dragonfly_audio/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "dragonfly_audio"
7
+ spec.name = 'dragonfly_audio'
8
8
  spec.version = DragonflyAudio::VERSION
9
- spec.authors = ["Tomas Celizna", "Asger Behncke Jacobsen"]
10
- spec.email = ["tomas.celizna@gmail.com", "asger@8kilo.com"]
11
- spec.summary = %q{Wraps common audio-related tasks into Dragonfly analysers and processors.}
12
- spec.homepage = "https://github.com/tomasc/dragonfly_audio"
13
- spec.license = "MIT"
9
+ spec.authors = ['Tomas Celizna', 'Asger Behncke Jacobsen']
10
+ spec.email = ['tomas.celizna@gmail.com', 'asger@8kilo.com']
11
+ spec.summary = 'Wraps common audio-related tasks into Dragonfly analysers and processors.'
12
+ spec.homepage = 'https://github.com/tomasc/dragonfly_audio'
13
+ spec.license = 'MIT'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
19
19
 
20
- spec.add_dependency "dragonfly", "~> 1.0"
21
- spec.add_dependency "taglib-ruby"
20
+ spec.add_dependency 'dragonfly', '~> 1.0'
21
+ spec.add_dependency 'taglib-ruby'
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.6"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "nokogiri"
26
- spec.add_development_dependency "guard"
27
- spec.add_development_dependency "guard-minitest"
28
- spec.add_development_dependency "minitest"
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'guard'
26
+ spec.add_development_dependency 'guard-minitest'
27
+ spec.add_development_dependency 'minitest'
29
28
  end
@@ -5,42 +5,31 @@ require 'taglib'
5
5
  module DragonflyAudio
6
6
  module Analysers
7
7
  class AudioProperties
8
+ TAGS = %i(title artist album year track genre comment).freeze
9
+ AUDIO_PROPS = %i(length bitrate channels sample_rate).freeze
8
10
 
9
- def call content
11
+ def call(content)
10
12
  taglib_fileref(content)
11
13
  end
12
14
 
13
15
  private # =============================================================
14
16
 
15
- def taglib_fileref temp_object
17
+ def taglib_fileref(content)
16
18
  res = {}
17
- TagLib::FileRef.open(temp_object.path) do |fileref|
19
+ TagLib::FileRef.open(content.path) do |fileref|
18
20
  unless fileref.null?
19
21
 
20
- # TODO: simplify me!
21
- tag = fileref.tag
22
- res.merge! title: tag.title
23
- res.merge! artist: tag.artist
24
- res.merge! album: tag.album
25
- res.merge! year: tag.year
26
- res.merge! tag: tag.year
27
- res.merge! track: tag.track
28
- res.merge! genre: tag.genre
29
- res.merge! comment: tag.comment
22
+ TAGS.each do |tag_name|
23
+ res[tag_name] = fileref.tag.send(tag_name)
24
+ end
30
25
 
31
- prop = fileref.audio_properties
32
- res.merge! length: prop.length
33
- res.merge! bitrate: prop.bitrate
34
- res.merge! channels: prop.channels
35
- res.merge! sample_rate: prop.sample_rate
36
-
37
- # prop.merge! %w(title artist album year track genre comment).inject({}) { |res, att| { att => fileref.tag.send(att) } }
38
- # prop.merge! length: fileref.audio_properties.length
26
+ AUDIO_PROPS.each do |prop_name|
27
+ res[prop_name] = fileref.audio_properties.send(prop_name)
28
+ end
39
29
  end
40
30
  end
41
31
  res
42
32
  end
43
-
44
33
  end
45
34
  end
46
35
  end
@@ -1,56 +1,22 @@
1
1
  require 'dragonfly_audio/analysers/audio_properties'
2
+ require 'dragonfly_audio/processors/tag'
2
3
 
3
4
  module DragonflyAudio
4
5
  class Plugin
5
-
6
- def call app, opts={}
6
+ def call(app, _opts = {})
7
7
  app.add_analyser :audio_properties, DragonflyAudio::Analysers::AudioProperties.new
8
8
 
9
- app.add_analyser :title do |content|
10
- content.analyse(:audio_properties)[:title]
11
- end
12
-
13
- app.add_analyser :artist do |content|
14
- content.analyse(:audio_properties)[:artist]
15
- end
16
-
17
- app.add_analyser :album do |content|
18
- content.analyse(:audio_properties)[:album]
19
- end
20
-
21
- app.add_analyser :year do |content|
22
- content.analyse(:audio_properties)[:year]
23
- end
24
-
25
- app.add_analyser :track do |content|
26
- content.analyse(:audio_properties)[:track]
27
- end
28
-
29
- app.add_analyser :genre do |content|
30
- content.analyse(:audio_properties)[:genre]
9
+ [
10
+ DragonflyAudio::Analysers::AudioProperties::TAGS,
11
+ DragonflyAudio::Analysers::AudioProperties::AUDIO_PROPS
12
+ ].flatten.each do |analyser|
13
+ app.add_analyser analyser do |content|
14
+ content.analyse(:audio_properties)[analyser]
15
+ end
31
16
  end
32
17
 
33
- app.add_analyser :comment do |content|
34
- content.analyse(:audio_properties)[:comment]
35
- end
36
-
37
- app.add_analyser :length do |content|
38
- content.analyse(:audio_properties)[:length]
39
- end
40
-
41
- app.add_analyser :bitrate do |content|
42
- content.analyse(:audio_properties)[:bitrate]
43
- end
44
-
45
- app.add_analyser :channels do |content|
46
- content.analyse(:audio_properties)[:channels]
47
- end
48
-
49
- app.add_analyser :sample_rate do |content|
50
- content.analyse(:audio_properties)[:sample_rate]
51
- end
18
+ app.add_processor :tag, DragonflyAudio::Processors::Tag.new
52
19
  end
53
-
54
20
  end
55
21
  end
56
22
 
@@ -0,0 +1,29 @@
1
+ require 'taglib'
2
+
3
+ # IMPORTANT: See http://robinst.github.io/taglib-ruby/
4
+
5
+ module DragonflyAudio
6
+ module Processors
7
+ class Tag
8
+ PERMISSIBLE_PROPERTIES = DragonflyAudio::Analysers::AudioProperties::TAGS
9
+
10
+ def call(content, properties)
11
+ clean_properties = properties.delete_if { |key, _| !PERMISSIBLE_PROPERTIES.include?(key) }
12
+
13
+ tempfile = Dragonfly::TempObject.new(content.tempfile)
14
+
15
+ TagLib::FileRef.open(tempfile.path) do |file|
16
+ unless file.null?
17
+ tag = file.tag
18
+ clean_properties.each do |key, value|
19
+ tag.send("#{key}=", value)
20
+ end
21
+ file.save
22
+ end
23
+ end
24
+
25
+ content.update(tempfile)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module DragonflyAudio
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'.freeze
3
3
  end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ describe DragonflyAudio::Analysers::AudioProperties do
4
+ let(:app) { test_app.configure_with(:audio) }
5
+ let(:audio) { app.fetch_file(SAMPLES_DIR.join('BroadmoorSirenTest.mp3')) }
6
+
7
+ it 'analyses "album" property' do
8
+ audio.audio_properties[:album].must_equal 'Album XYZ'
9
+ end
10
+
11
+ it 'analyses "artist" property' do
12
+ audio.audio_properties[:artist].must_equal 'Artist'
13
+ end
14
+
15
+ it 'analyses "bitrate" property' do
16
+ audio.audio_properties[:bitrate].must_equal 192
17
+ end
18
+
19
+ it 'analyses "channels" property' do
20
+ audio.audio_properties[:channels].must_equal 2
21
+ end
22
+
23
+ it 'analyses "comment" property' do
24
+ audio.audio_properties[:comment].must_equal ' Comment '
25
+ end
26
+
27
+ it 'analyses "genre" property' do
28
+ audio.audio_properties[:genre].must_equal 'Dance'
29
+ end
30
+
31
+ it 'analyses "length" property' do
32
+ audio.audio_properties[:length].must_equal 156
33
+ end
34
+
35
+ it 'analyses "sample_rate" property' do
36
+ audio.audio_properties[:sample_rate].must_equal 44_100
37
+ end
38
+
39
+ it 'analyses "title" property' do
40
+ audio.audio_properties[:title].must_equal 'SongTitle'
41
+ end
42
+
43
+ it 'analyses "track" property' do
44
+ audio.audio_properties[:track].must_equal 0
45
+ end
46
+
47
+ it 'analyses "year" property' do
48
+ audio.audio_properties[:year].must_equal 0
49
+ end
50
+ end
@@ -2,17 +2,28 @@ require 'test_helper'
2
2
 
3
3
  module DragonflyAudio
4
4
  describe Plugin do
5
-
6
5
  let(:app) { test_app.configure_with(:audio) }
7
6
  let(:audio) { app.fetch_file(SAMPLES_DIR.join('BroadmoorSirenTest.mp3')) }
8
7
 
9
- # ---------------------------------------------------------------------
10
-
11
8
  describe 'analysers' do
12
9
  it 'adds #audio_properties' do
13
10
  audio.must_respond_to :audio_properties
14
11
  end
12
+
13
+ [
14
+ DragonflyAudio::Analysers::AudioProperties::TAGS,
15
+ DragonflyAudio::Analysers::AudioProperties::AUDIO_PROPS
16
+ ].flatten.each do |analyser|
17
+ it "adds ##{analyser}" do
18
+ audio.must_respond_to analyser
19
+ end
20
+ end
15
21
  end
16
22
 
23
+ describe 'processors' do
24
+ it 'adds #tag' do
25
+ audio.must_respond_to :tag
26
+ end
27
+ end
17
28
  end
18
29
  end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ describe DragonflyAudio::Processors::Tag do
4
+ let(:app) { test_app.configure_with(:audio) }
5
+ let(:processor) { DragonflyAudio::Processors::Tag.new }
6
+ let(:analyser) { DragonflyAudio::Analysers::AudioProperties.new }
7
+ let(:audio) { Dragonfly::Content.new(app, SAMPLES_DIR.join('BroadmoorSirenTest.mp3')) }
8
+
9
+ let(:artist) { 'Elvis Presley' }
10
+ let(:title) { 'Hound Dawg' }
11
+
12
+ before { processor.call(audio, artist: artist, title: title) }
13
+
14
+ describe 'properties' do
15
+ it 'sets the artist tag property' do
16
+ analyser.call(audio)[:artist].must_equal artist
17
+ end
18
+
19
+ it 'sets the title tag property' do
20
+ analyser.call(audio)[:title].must_equal title
21
+ end
22
+ end
23
+ end
data/test/test_helper.rb CHANGED
@@ -7,15 +7,11 @@ require 'minitest/spec'
7
7
  require 'dragonfly'
8
8
  require 'dragonfly_audio'
9
9
 
10
- # ---------------------------------------------------------------------
11
-
12
10
  SAMPLES_DIR = Pathname.new(File.expand_path('../../samples', __FILE__))
13
11
 
14
- # ---------------------------------------------------------------------
15
-
16
- def test_app name=nil
12
+ def test_app(name = nil)
17
13
  app = Dragonfly::App.instance(name)
18
14
  app.datastore = Dragonfly::MemoryDataStore.new
19
- app.secret = "test secret"
15
+ app.secret = 'test secret'
20
16
  app
21
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly_audio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-23 00:00:00.000000000 Z
12
+ date: 2016-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dragonfly
@@ -67,20 +67,6 @@ dependencies:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
- - !ruby/object:Gem::Dependency
71
- name: nokogiri
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
70
  - !ruby/object:Gem::Dependency
85
71
  name: guard
86
72
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +118,7 @@ extensions: []
132
118
  extra_rdoc_files: []
133
119
  files:
134
120
  - ".gitignore"
121
+ - ".travis.yml"
135
122
  - Gemfile
136
123
  - Gemfile.lock
137
124
  - Guardfile
@@ -142,9 +129,12 @@ files:
142
129
  - lib/dragonfly_audio.rb
143
130
  - lib/dragonfly_audio/analysers/audio_properties.rb
144
131
  - lib/dragonfly_audio/plugin.rb
132
+ - lib/dragonfly_audio/processors/tag.rb
145
133
  - lib/dragonfly_audio/version.rb
146
134
  - samples/BroadmoorSirenTest.mp3
135
+ - test/dragonfly_audio/analysers/audio_properties_test.rb
147
136
  - test/dragonfly_audio/plugin_test.rb
137
+ - test/dragonfly_audio/processors/tag_test.rb
148
138
  - test/test_helper.rb
149
139
  homepage: https://github.com/tomasc/dragonfly_audio
150
140
  licenses:
@@ -166,10 +156,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
156
  version: '0'
167
157
  requirements: []
168
158
  rubyforge_project:
169
- rubygems_version: 2.4.8
159
+ rubygems_version: 2.4.5.1
170
160
  signing_key:
171
161
  specification_version: 4
172
162
  summary: Wraps common audio-related tasks into Dragonfly analysers and processors.
173
163
  test_files:
164
+ - test/dragonfly_audio/analysers/audio_properties_test.rb
174
165
  - test/dragonfly_audio/plugin_test.rb
166
+ - test/dragonfly_audio/processors/tag_test.rb
175
167
  - test/test_helper.rb