fancy_audio 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 483962b6e6e93bce31791f839813bccb7da059c9
4
- data.tar.gz: 0c34aa62b2bd144c0e7434293b1f66c506dda21a
3
+ metadata.gz: 09f615a99f7bd8d0966a686bbaadd5e9071d14c7
4
+ data.tar.gz: 2af9c05d7737fa95d0ca4f81387efdd2e07688a1
5
5
  SHA512:
6
- metadata.gz: 402de01b63b428fb59e874b9c67a95a4bef02b7385576d19d27e0ad9fc930145e2490184a47c90938d79c6de1078263e2dc9250b0b43e1f5fc84518cba3799fa
7
- data.tar.gz: 7821490ba20d3e2def06962e43d7e22a0c5d22c49f5679d627e046e66e3fda58cfda39827004c8fcd69e07e3767d4192faf827fe671929dd56e11cc51e49a4c3
6
+ metadata.gz: e03faa88c3fd54bd564ad9fd4f69b34feaeca10c5865349f4a9b09620af9eaafeb0a2ef41457146935a4fb09f695f18946bfe0c499e2b06b2e6bf3d271e3b79e
7
+ data.tar.gz: 7afe3ba2a717a514534b82011204a2954df5a99ac87a5f0c570e5b29e75cca4e9ca13a64388b147ff276d8ee643188f8fc08ac83456a5b8ad55cdf4f6e9e1bb9
@@ -0,0 +1,13 @@
1
+ # fancy_audio
2
+ A gem to add album cover to audio file
3
+
4
+ ##Documentation
5
+ http://www.singhajit.com/fancyaudio-gem-to-add-album-cover-to-audio-file/
6
+
7
+ ## Contributing
8
+
9
+ 1. Fork it ( http://github.com/ajitsing/fancy_audio )
10
+ 2. Create your feature branch
11
+ 3. Commit your changes
12
+ 4. Push to the branch
13
+ 5. Create new Pull Request
@@ -4,32 +4,48 @@ require 'fancy_audio'
4
4
  include FancyAudio::Operations
5
5
  include FancyAudio::PrettyPrinter
6
6
 
7
- first = ARGV[0]
8
- second = ARGV[1]
9
-
10
7
  def print_help
11
8
  help = <<-info
12
9
  fancy_audio audio_file image_file #=> attach image_file to audio_file
13
10
  fancy_audio #=> attach all audio and images with same name(default current dir) e.g song1.mp3 and song1.jpg
14
11
  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
12
  fancy_audio --h #=> to print help
13
+
14
+ To see a demo visit - http://www.singhajit.com/fancyaudio-gem-to-add-album-cover-to-audio-file/
16
15
  info
17
16
 
18
17
  print_info help
19
18
  end
20
19
 
21
- if first == '--h' && ARGV.size == 1
22
- print_help
20
+ def execute
21
+ first = ARGV[0]
22
+ second = ARGV[1]
23
23
 
24
- elsif !first.nil? && !second.nil? && ARGV.size == 2
25
- add_image first, second
24
+ if first == '--h' && ARGV.size == 1
25
+ print_help
26
26
 
27
- elsif ARGV.size.zero?
28
- add_image_smartly
27
+ elsif !first.nil? && !second.nil? && ARGV.size == 2
28
+ add_image first, second
29
29
 
30
- elsif ARGV.size == 1
31
- add_image_smartly first
30
+ elsif ARGV.size.zero?
31
+ add_image_smartly
32
32
 
33
- else
34
- print_error "Wrong Usages! To know the right usages type 'fancy_audio --h'"
33
+ elsif ARGV.size == 1
34
+ add_image_smartly first
35
+
36
+ else
37
+ print_error "Wrong Usages! To know the right usages type 'fancy_audio --h'"
38
+ end
35
39
  end
40
+
41
+ begin
42
+ execute
43
+ rescue
44
+ error_msg = <<-error
45
+ Something went wrong! Or usages is incorrect
46
+ To understand the corrent usages visit - http://www.singhajit.com/fancyaudio-gem-to-add-album-cover-to-audio-file/
47
+ error
48
+
49
+ print_error error_msg
50
+ end
51
+
@@ -11,6 +11,8 @@ Gem::Specification.new do |s|
11
11
  s.description = s.summary
12
12
  s.authors = ['Ajit Singh']
13
13
  s.email = 'jeetsingh.ajit@gamil.com'
14
+ s.license = 'MIT'
15
+ s.homepage = 'http://www.singhajit.com/fancyaudio-gem-to-add-album-cover-to-audio-file/'
14
16
 
15
17
  s.files = `git ls-files -z`.split("\x0")
16
18
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -8,6 +8,8 @@ module FancyAudio
8
8
  IMAGE_NOT_FOUND = 'File Not Found'
9
9
 
10
10
  def add_image(audio_file, image)
11
+ return unless files_present(audio_file, image)
12
+
11
13
  image_file = File.new(image, 'rb')
12
14
  Mp3Info.open(audio_file) do |audio|
13
15
  audio.tag2.remove_pictures
@@ -39,6 +41,19 @@ module FancyAudio
39
41
  end
40
42
 
41
43
  private
44
+ def files_present(audio_file, image_file)
45
+ audio_file_exists = File.exist?(audio_file)
46
+ image_file_exists = File.exist?(image_file)
47
+
48
+ if !audio_file_exists
49
+ print_error "#{audio_file} does not exists!\n"
50
+ elsif !image_file_exists
51
+ print_error "#{image_file} does not exists!\n"
52
+ end
53
+
54
+ audio_file_exists && image_file_exists
55
+ end
56
+
42
57
  def print_modified_files(files)
43
58
  return if files.empty?
44
59
  print_info("Modified Audio Files\n")
@@ -1,3 +1,3 @@
1
1
  module FancyAudio
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -15,6 +15,20 @@ describe :FancyAudio do
15
15
  assert_audio_has_image audio_file
16
16
  end
17
17
 
18
+ it 'should handle gracefully when file is not present' do
19
+ current_dir = File.expand_path File.dirname __FILE__
20
+ unavailable_audio_file = current_dir + '/resources/unavailable_song.mp3'
21
+ unavailable_image_file = current_dir + '/resources/unavailable_image.jpg'
22
+
23
+ image_file = current_dir + '/resources/song1.jpg'
24
+ audio_file = current_dir + '/resources/song1.mp3'
25
+
26
+ add_image unavailable_audio_file, image_file
27
+ add_image audio_file, unavailable_image_file
28
+
29
+ assert_audio_does_not_have_image audio_file
30
+ end
31
+
18
32
  it 'should add image to the song smartly' do
19
33
  dir = File.expand_path File.dirname(__dir__) + '/spec/resources'
20
34
  audio_file = dir + '/song1.mp3'
@@ -25,6 +25,12 @@ def assert_audio_has_image(audio)
25
25
  end
26
26
  end
27
27
 
28
+ def assert_audio_does_not_have_image(audio)
29
+ Mp3Info.open(audio) do |song|
30
+ song.tag2.pictures.empty?.should be_truthy
31
+ end
32
+ end
33
+
28
34
  def remove_pictures_from_songs
29
35
  current_dir = File.expand_path File.dirname __FILE__
30
36
  songs = Dir[current_dir + "/resources/*.mp3"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fancy_audio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ajit Singh
@@ -77,6 +77,7 @@ files:
77
77
  - Gemfile
78
78
  - Gemfile.lock
79
79
  - LICENSE.txt
80
+ - README.md
80
81
  - Rakefile
81
82
  - bin/fancy_audio
82
83
  - fancy_audio.gemspec
@@ -88,8 +89,9 @@ files:
88
89
  - spec/resources/song1.mp3
89
90
  - spec/resources/song2.mp3
90
91
  - spec/spec_helper.rb
91
- homepage:
92
- licenses: []
92
+ homepage: http://www.singhajit.com/fancyaudio-gem-to-add-album-cover-to-audio-file/
93
+ licenses:
94
+ - MIT
93
95
  metadata: {}
94
96
  post_install_message:
95
97
  rdoc_options: []