fancy_audio 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe063ac933426e770614c512560fee328e347ea4
4
+ data.tar.gz: 748cc07608b8a8bc0c9e1d833145d0f8763f6eca
5
+ SHA512:
6
+ metadata.gz: 05f59466588f08d2a178a00da63a803f0dfc64658f229856761bbd4411b95a3ca49aa0d1baebb7339ee41ba9bdf695df636e42beb496806e3ed7a04255f0cb98
7
+ data.tar.gz: 929a4d08e2949d7597d20f37bf4963b6e36b9e58f576e64dd156dc2f4d87e903a14f5e5f123f64fe45697cdeb3daa8470bfca2d962a20bfbe0f8b5fdae0b4102
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'ruby-mp3info'
4
+ gem 'pry'
5
+
6
+ gemspec
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fancy_audio (0.0.1)
5
+ ruby-mp3info (~> 0.8.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.0)
11
+ diff-lcs (1.2.5)
12
+ method_source (0.8.2)
13
+ pry (0.10.1)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.8.1)
16
+ slop (~> 3.4)
17
+ rake (10.4.2)
18
+ rspec (3.1.0)
19
+ rspec-core (~> 3.1.0)
20
+ rspec-expectations (~> 3.1.0)
21
+ rspec-mocks (~> 3.1.0)
22
+ rspec-core (3.1.7)
23
+ rspec-support (~> 3.1.0)
24
+ rspec-expectations (3.1.2)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.1.0)
27
+ rspec-mocks (3.1.3)
28
+ rspec-support (~> 3.1.0)
29
+ rspec-support (3.1.2)
30
+ ruby-mp3info (0.8.7)
31
+ slop (3.6.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.5)
38
+ fancy_audio!
39
+ pry
40
+ rake
41
+ rspec
42
+ ruby-mp3info
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ajit Singh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :spec do
4
+ sh 'rspec'
5
+ end
6
+
7
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fancy_audio'
4
+ include FancyAudio::Operations
5
+ include FancyAudio::PrettyPrinter
6
+
7
+ first = ARGV[0]
8
+ second = ARGV[1]
9
+
10
+ def print_help
11
+ help = <<-info
12
+ fancy_audio audio_file image_file #=> attach image_file to audio_file
13
+ fancy_audio #=> attach all audio and images with same name(default current dir) e.g song1.mp3 and song1.jpg
14
+ fancy_audio path/to/files #=> attach all audio and images with same name(cutom path to dir) e.g song1.mp3 and song1.jpg
15
+ fancy_audio --h #=> to print help
16
+ info
17
+
18
+ print_info help
19
+ end
20
+
21
+ if first == '--h' && ARGV.size == 1
22
+ print_help
23
+
24
+ elsif !first.nil? && !second.nil? && ARGV.size == 2
25
+ add_image first, second
26
+
27
+ elsif ARGV.size.zero?
28
+ add_image_smartly
29
+
30
+ elsif ARGV.size == 1
31
+ add_image_smartly first
32
+
33
+ else
34
+ print_error "Wrong Usages! To know the right usages type 'fancy_audio --h'"
35
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fancy_audio/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'fancy_audio'
8
+ s.version = FancyAudio::VERSION
9
+ s.date = '2015-07-18'
10
+ s.summary = 'Gem to add an album cover to the audio'
11
+ s.description = s.summary
12
+ s.authors = ['Ajit Singh']
13
+ s.email = 'jeetsingh.ajit@gamil.com'
14
+
15
+ s.files = `git ls-files -z`.split("\x0")
16
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'ruby-mp3info', '~> 0.8.5'
21
+ s.add_development_dependency "bundler", "~> 1.5"
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,64 @@
1
+ require 'mp3info'
2
+ require_relative 'fancy_audio/pretty_printer'
3
+
4
+ module FancyAudio
5
+ module Operations
6
+ include FancyAudio::PrettyPrinter
7
+
8
+ IMAGE_NOT_FOUND = 'File Not Found'
9
+
10
+ def add_image(audio_file, image)
11
+ image_file = File.new(image, 'rb')
12
+ Mp3Info.open(audio_file) do |audio|
13
+ audio.tag2.remove_pictures
14
+ audio.tag2.add_picture(image_file.read)
15
+ end
16
+ end
17
+
18
+ def add_image_smartly(dir = `pwd`.chop)
19
+ unavialble_images = []
20
+ changed_audio_files = {}
21
+ audio_files = Dir[dir + "/*.mp3"]
22
+
23
+ audio_files.each do |audio_file|
24
+ file_name_without_ext = dir + "/#{File.basename(audio_file, '.mp3')}"
25
+ image_file = get_image_file(file_name_without_ext)
26
+
27
+ if(image_file == IMAGE_NOT_FOUND)
28
+ unavialble_images << audio_file
29
+ else
30
+ add_image(audio_file, image_file)
31
+ changed_audio_files[audio_file] = image_file
32
+ end
33
+ end
34
+
35
+ print_modified_files changed_audio_files
36
+ print "\n\n"
37
+ print_unmodified_files unavialble_images
38
+ print_info "No audio files found!!" if audio_files.empty?
39
+ end
40
+
41
+ private
42
+ def print_modified_files(files)
43
+ return if files.empty?
44
+ print_info("Modified Audio Files\n")
45
+ files.each {|audio, image| print_success(audio + " + #{image}\n")}
46
+ end
47
+
48
+ def print_unmodified_files(files)
49
+ return if files.empty?
50
+ print_info("Unmodified Audio Files - May be image is not present for these audios\n")
51
+ print_info("Convertor only supports .jpeg, .jpg and .png image files\n")
52
+ files.each {|image| print_error(image+"\n")}
53
+ end
54
+
55
+ def get_image_file(file)
56
+ return (file + ".jpeg") if File.exist?(file + ".jpeg")
57
+ return (file + ".jpg") if File.exist?(file + ".jpg")
58
+ return (file + ".png") if File.exist?(file + ".png")
59
+
60
+ IMAGE_NOT_FOUND
61
+ end
62
+ end
63
+ end
64
+
@@ -0,0 +1,23 @@
1
+ module FancyAudio
2
+ module PrettyPrinter
3
+ def colorize(text, color_code)
4
+ "#{color_code}#{text}\e[0m"
5
+ end
6
+
7
+ def red(text); colorize(text, "\e[31m"); end
8
+ def green(text); colorize(text, "\e[32m"); end
9
+ def yellow(text); colorize(text, "\e[1m\e[33m"); end
10
+
11
+ def print_info(msg)
12
+ STDOUT.write yellow(msg)
13
+ end
14
+
15
+ def print_error(msg)
16
+ STDOUT.write red(msg)
17
+ end
18
+
19
+ def print_success(msg)
20
+ STDOUT.write green(msg)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module FancyAudio
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe :FancyAudio do
4
+
5
+ before(:each) do
6
+ remove_pictures_from_songs
7
+ end
8
+
9
+ it 'should add image to the song' do
10
+ current_dir = File.expand_path File.dirname __FILE__
11
+ image_file = current_dir + '/resources/song1.jpg'
12
+ audio_file = current_dir + '/resources/song1.mp3'
13
+
14
+ add_image audio_file, image_file
15
+ assert_audio_has_image audio_file
16
+ end
17
+
18
+ it 'should add image to the song smartly' do
19
+ dir = File.expand_path File.dirname(__dir__) + '/spec/resources'
20
+ audio_file = dir + '/song1.mp3'
21
+
22
+ add_image_smartly dir
23
+ assert_audio_has_image audio_file
24
+ end
25
+
26
+ it 'should add image to the song in the current directory' do
27
+ dir = File.expand_path File.dirname(__dir__) + '/spec/resources'
28
+ audio_file = dir + '/song1.mp3'
29
+ Dir.chdir dir do
30
+ add_image_smartly
31
+ assert_audio_has_image audio_file
32
+ end
33
+ end
34
+ end
35
+
Binary file
Binary file
Binary file
@@ -0,0 +1,98 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ require 'mp3info'
18
+ require './lib/fancy_audio.rb'
19
+
20
+ include FancyAudio::Operations
21
+
22
+ def assert_audio_has_image(audio)
23
+ Mp3Info.open(audio) do |song|
24
+ song.tag2.pictures.empty?.should be_falsy
25
+ end
26
+ end
27
+
28
+ def remove_pictures_from_songs
29
+ current_dir = File.expand_path File.dirname __FILE__
30
+ songs = Dir[current_dir + "/resources/*.mp3"]
31
+
32
+ songs.each do |song|
33
+ Mp3Info.open(song) do |song_file|
34
+ song_file.tag2.remove_pictures
35
+ end
36
+ end
37
+ end
38
+
39
+ RSpec.configure do |config|
40
+ # rspec-expectations config goes here. You can use an alternate
41
+ # assertion/expectation library such as wrong or the stdlib/minitest
42
+ # assertions if you prefer.
43
+ config.expect_with :rspec do |c|
44
+ c.syntax = :should
45
+ end
46
+
47
+ config.mock_with :rspec do |c|
48
+ c.syntax = :should
49
+ end
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # These two settings work together to allow you to limit a spec run
54
+ # to individual examples or groups you care about by tagging them with
55
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
56
+ # get run.
57
+ config.filter_run :focus
58
+ config.run_all_when_everything_filtered = true
59
+
60
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
61
+ # For more details, see:
62
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
63
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
64
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
65
+ config.disable_monkey_patching!
66
+
67
+ # This setting enables warnings. It's recommended, but in some cases may
68
+ # be too noisy due to issues in dependencies.
69
+ config.warnings = true
70
+
71
+ # Many RSpec users commonly either run the entire suite or an individual
72
+ # file, and it's useful to allow more verbose output when running an
73
+ # individual spec file.
74
+ if config.files_to_run.one?
75
+ # Use the documentation formatter for detailed output,
76
+ # unless a formatter has already been configured
77
+ # (e.g. via a command-line flag).
78
+ config.default_formatter = 'doc'
79
+ end
80
+
81
+ # Print the 10 slowest examples and example groups at the
82
+ # end of the spec run, to help surface which specs are running
83
+ # particularly slow.
84
+ config.profile_examples = 10
85
+
86
+ # Run specs in random order to surface order dependencies. If you find an
87
+ # order dependency and want to debug it, you can fix the order by providing
88
+ # the seed, which is printed after each run.
89
+ # --seed 1234
90
+ config.order = :random
91
+
92
+ # Seed global randomization in this process using the `--seed` CLI option.
93
+ # Setting this allows you to use `--seed` to deterministically reproduce
94
+ # test failures related to randomization by passing the same `--seed` value
95
+ # as the one that triggered the failure.
96
+ Kernel.srand config.seed
97
+ =end
98
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fancy_audio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ajit Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-mp3info
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Gem to add an album cover to the audio
70
+ email: jeetsingh.ajit@gamil.com
71
+ executables:
72
+ - fancy_audio
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".rspec"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - Rakefile
81
+ - bin/fancy_audio
82
+ - fancy_audio.gemspec
83
+ - lib/fancy_audio.rb
84
+ - lib/fancy_audio/pretty_printer.rb
85
+ - lib/fancy_audio/version.rb
86
+ - spec/fancy_audio_spec.rb
87
+ - spec/resources/song1.jpg
88
+ - spec/resources/song1.mp3
89
+ - spec/resources/song2.mp3
90
+ - spec/spec_helper.rb
91
+ homepage:
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Gem to add an album cover to the audio
114
+ test_files:
115
+ - spec/fancy_audio_spec.rb
116
+ - spec/resources/song1.jpg
117
+ - spec/resources/song1.mp3
118
+ - spec/resources/song2.mp3
119
+ - spec/spec_helper.rb