rupeepeethree 0.0.3 → 0.0.4

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: c246d6bf55b54ae1c32dc4859aa1f4c359a985e3
4
- data.tar.gz: bcc7b3d8a968f9c6e8ab7a7bf73b2617a7c56198
3
+ metadata.gz: a9b8edd7bd8c74aa52856c2cc0fce126106ace72
4
+ data.tar.gz: 2adb6bcf7b0d698961137239b9673007498e82c8
5
5
  SHA512:
6
- metadata.gz: 47f8c56abde949079168870ab8daf4c49cef89579516670825948baeb518ae1683a843eb10f165d7c23ffd0412c020c4171658566b468f065a6943922ef07dda
7
- data.tar.gz: 332bb70f0f688daeae19d6fa18bc821592db91245232becb0ea044bccb916a6a481b0007bcf87319f1549223839562c7b4b406a6879e1314736a1cfe9df44c53
6
+ metadata.gz: e8243fbaf1da772131416834f7e694632715462be07e8675bb8888e4a69aa638cb0a2a67d8ad1c994a9b223f52a8059dd749efe2b28f395ae06fbaed29db35da
7
+ data.tar.gz: c95605dd6b16325f8ab54fe0f7eeeb8f2ed36488e702172e05e08e7d022e7a28f482999ae0990a060653f7576d2e16cede04cbfe6f2210b6324a49f61173cfa2
data/README.md CHANGED
@@ -6,7 +6,13 @@ http://github.com/datafruits/rupeepeethree
6
6
 
7
7
  [![Build Status](https://secure.travis-ci.org/datafruits/rupeepeethree.png?branch=master)](http://travis-ci.org/datafruits/rupeepeethree)
8
8
 
9
- tag your mp3 files. a command line wrapper around taglib-ruby.
9
+ ░█▀▄░█▀█░▀▀█
10
+ ░█▀▄░█▀▀░░▀▄
11
+ ░▀░▀░▀░░░▀▀░
12
+ ┣¨キ┣¨キ
13
+ You thought your mp3s were cool. Turns out you were wrong. Your mp3s have no tags. You must tag them!
14
+
15
+ a simple library and command line utility wrapper around ruby-taglib
10
16
 
11
17
  ## FEATURES/PROBLEMS:
12
18
 
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  require "rubygems"
4
+ require 'rspec/core/rake_task'
4
5
 
5
- # vim: syntax=ruby
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
data/bin/rp3 CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'rupeepeethree'
4
4
 
5
- Rupeepeethree.run ARGV
5
+ Rupeepeethree::Cli.run ARGV
data/lib/rupeepeethree.rb CHANGED
@@ -3,41 +3,43 @@ require 'rupeepeethree/tagger'
3
3
  require 'rupeepeethree/version'
4
4
  require 'trollop'
5
5
 
6
- class Rupeepeethree
7
- def self.run(args)
8
- p = Trollop::Parser.new do
9
- version "RP3 version #{VERSION} by Tony Miller"
10
- banner <<-EOS
11
- ░█▀▄░█▀█░▀▀█
12
- ░█▀▄░█▀▀░░▀▄
13
- ░▀░▀░▀░░░▀▀░
14
- ┣¨キ┣¨キ
15
- You thought your mp3s were cool. Turns out you were wrong. Your mp3s have no tags. You must tag them!
16
- EOS
17
- opt :title, "title", type: String, short: 't'
18
- opt :artist, "artist", type: String, short: 'a'
19
- opt :year, "track year", type: String, short: 'Y'
20
- opt :track, "track number", type: String, short: 'n'
21
- opt :album, "album title", type: String, short: 'A'
22
- opt :picture, "artwork", type: String, short: 'p'
23
- opt :clear, "clear all tags!"
24
- end
6
+ module Rupeepeethree
7
+ class Cli
8
+ def self.run(args)
9
+ p = Trollop::Parser.new do
10
+ version "RP3 version #{VERSION} by Tony Miller"
11
+ banner <<-EOS
12
+ ░█▀▄░█▀█░▀▀█
13
+ ░█▀▄░█▀▀░░▀▄
14
+ ░▀░▀░▀░░░▀▀░
15
+ ┣¨キ┣¨キ
16
+ You thought your mp3s were cool. Turns out you were wrong. Your mp3s have no tags. You must tag them!
17
+ EOS
18
+ opt :title, "title", type: String, short: 't'
19
+ opt :artist, "artist", type: String, short: 'a'
20
+ opt :year, "track year", type: String, short: 'Y'
21
+ opt :track, "track number", type: String, short: 'n'
22
+ opt :album, "album title", type: String, short: 'A'
23
+ opt :picture, "artwork", type: String, short: 'p'
24
+ opt :clear, "clear all tags!"
25
+ end
25
26
 
26
- opts = Trollop::with_standard_exception_handling p do
27
- raise Trollop::HelpNeeded if ARGV.empty? # show help screen
28
- p.parse ARGV
29
- end
27
+ opts = Trollop::with_standard_exception_handling p do
28
+ raise Trollop::HelpNeeded if ARGV.empty? # show help screen
29
+ p.parse ARGV
30
+ end
30
31
 
31
- mp3s = ARGV
32
- if mp3s.empty?
33
- abort("no mp3 specified...")
34
- end
35
- mp3s.each do |mp3|
36
- if opts[:clear]
37
- Tagger.clear(mp3)
38
- else
39
- Tagger.tag(mp3,opts)
40
- puts Tagger.print_tags(mp3)
32
+ mp3s = ARGV
33
+ if mp3s.empty?
34
+ abort("no mp3 specified...")
35
+ end
36
+ mp3s.each do |mp3|
37
+ if opts[:clear]
38
+ Tagger.clear(mp3)
39
+ else
40
+ Tagger.tag(mp3,opts)
41
+ puts Tagger.print_tags(mp3)
42
+ end
41
43
  end
42
44
  end
43
45
  end
@@ -1,77 +1,93 @@
1
1
  require 'taglib'
2
2
  require 'mime/types'
3
3
 
4
- class Tagger
5
- def self.tag(mp3,tags)
6
- TagLib::MPEG::File.open(mp3) do |f|
7
- t = f.id3v2_tag || TagLib::ID3v2::Tag.new
8
- if tags[:title]
9
- t.title = tags[:title]
10
- end
11
- if tags[:artist]
12
- t.artist = tags[:artist]
13
- end
14
- if tags[:album]
15
- t.album = tags[:album]
16
- end
17
- if tags[:year]
18
- t.year = tags[:year].to_i
19
- end
20
- if tags[:track]
21
- t.track = tags[:track].to_i
22
- end
23
- if tags[:picture]
24
- image_file = File.expand_path(tags[:picture])
25
- # delete old frame if it exists
26
- cover = t.frame_list('APIC').first
27
- if cover
28
- t.remove_frame(cover)
4
+ module Rupeepeethree
5
+ class Tagger
6
+ def self.tag(mp3,tags)
7
+ TagLib::MPEG::File.open(mp3) do |f|
8
+ t = f.id3v2_tag || TagLib::ID3v2::Tag.new
9
+ if tags[:title]
10
+ t.title = tags[:title]
11
+ end
12
+ if tags[:artist]
13
+ t.artist = tags[:artist]
29
14
  end
30
- cover = TagLib::ID3v2::AttachedPictureFrame.new
31
- cover.mime_type = mime_type(image_file)
32
- cover.type = TagLib::ID3v2::AttachedPictureFrame::FrontCover
33
- cover.picture = File.open(image_file,"rb"){|f|f.read}
34
- t.add_frame(cover)
15
+ if tags[:album]
16
+ t.album = tags[:album]
17
+ end
18
+ if tags[:year]
19
+ t.year = tags[:year].to_i
20
+ end
21
+ if tags[:track]
22
+ t.track = tags[:track].to_i
23
+ end
24
+ if tags[:picture]
25
+ image_file = File.expand_path(tags[:picture])
26
+ # delete old frame if it exists
27
+ cover = t.frame_list('APIC').first
28
+ if cover
29
+ t.remove_frame(cover)
30
+ end
31
+ cover = TagLib::ID3v2::AttachedPictureFrame.new
32
+ cover.mime_type = mime_type(image_file)
33
+ cover.type = TagLib::ID3v2::AttachedPictureFrame::FrontCover
34
+ cover.picture = File.open(image_file,"rb"){|f|f.read}
35
+ t.add_frame(cover)
36
+ end
37
+ f.save
35
38
  end
36
- f.save
37
39
  end
38
- end
39
40
 
40
- # clear all tags
41
- def self.clear(mp3)
42
- TagLib::MPEG::File.open(mp3) do |f|
43
- f.strip
41
+ def self.tags(mp3)
42
+ hash = {}
43
+ TagLib::MPEG::File.open(mp3) do |f|
44
+ t = f.id3v2_tag
45
+
46
+ hash[:title] = t.title
47
+ hash[:artist] = t.artist
48
+ hash[:album] = t.album
49
+ hash[:track_number] = t.track
50
+ hash[:year] = t.year
51
+ end
52
+ hash
44
53
  end
45
- end
46
54
 
47
- def self.print_tags(mp3)
48
- result = ""
49
- TagLib::MPEG::File.open(mp3) do |f|
50
- t = f.id3v2_tag
55
+ # clear all tags
56
+ def self.clear(mp3)
57
+ TagLib::MPEG::File.open(mp3) do |f|
58
+ f.strip
59
+ end
60
+ end
51
61
 
52
- result << "title: #{t.title}\n"
53
- result << "artist: #{t.artist}\n"
54
- result << "album: #{t.album}\n"
55
- result << "track number: #{t.track}\n"
56
- result << "year: #{t.year}\n"
62
+ def self.print_tags(mp3)
63
+ result = ""
64
+ TagLib::MPEG::File.open(mp3) do |f|
65
+ t = f.id3v2_tag
57
66
 
58
- t.frame_list('APIC').each do |cover|
59
- result << "image: [#{cover.mime_type}] [#{cover.picture.length} bytes]\n"
60
- end
67
+ result << "title: #{t.title}\n"
68
+ result << "artist: #{t.artist}\n"
69
+ result << "album: #{t.album}\n"
70
+ result << "track number: #{t.track}\n"
71
+ result << "year: #{t.year}\n"
61
72
 
62
- prop = f.audio_properties
63
- if prop
64
- result << "Bitrate: #{prop.bitrate}\n"
65
- result << "Channels: #{prop.channels}\n"
66
- result << "Sample Rate: #{prop.sample_rate}\n"
67
- result << "Length: #{sprintf("%.2f", prop.length/60.0)}\n"
73
+ t.frame_list('APIC').each do |cover|
74
+ result << "image: [#{cover.mime_type}] [#{cover.picture.length} bytes]\n"
75
+ end
76
+
77
+ prop = f.audio_properties
78
+ if prop
79
+ result << "Bitrate: #{prop.bitrate}\n"
80
+ result << "Channels: #{prop.channels}\n"
81
+ result << "Sample Rate: #{prop.sample_rate}\n"
82
+ result << "Length: #{sprintf("%.2f", prop.length/60.0)}\n"
83
+ end
68
84
  end
85
+ return result
69
86
  end
70
- return result
71
- end
72
87
 
73
- private
74
- def self.mime_type(file)
75
- MIME::Types.type_for(file).first.simplified.to_s
88
+ private
89
+ def self.mime_type(file)
90
+ MIME::Types.type_for(file).first.simplified.to_s
91
+ end
76
92
  end
77
93
  end
@@ -1,3 +1,3 @@
1
- class Rupeepeethree
2
- VERSION = "0.0.3"
1
+ module Rupeepeethree
2
+ VERSION = "0.0.4"
3
3
  end
Binary file
@@ -1,30 +1,43 @@
1
1
  require './lib/rupeepeethree/tagger'
2
2
 
3
- describe Tagger do
3
+ describe Rupeepeethree::Tagger do
4
4
  let(:mp3) { 'spec/fixtures/test.mp3' }
5
5
  before :each do
6
- Tagger.clear(mp3)
6
+ Rupeepeethree::Tagger.clear(mp3)
7
7
  end
8
8
  it "edits the existing cover art frame instead of creating a new one" do
9
9
  tags = {picture: "spec/fixtures/cover_art.jpg"}
10
10
  image_string = /image: \[image\/jpeg\] \[59562 bytes\]\n/
11
- Tagger.tag(mp3, tags)
12
- result = Tagger.print_tags(mp3)
11
+ Rupeepeethree::Tagger.tag(mp3, tags)
12
+ result = Rupeepeethree::Tagger.print_tags(mp3)
13
13
  result.should match(image_string)
14
14
 
15
- Tagger.tag(mp3, tags)
16
- result = Tagger.print_tags(mp3)
15
+ Rupeepeethree::Tagger.tag(mp3, tags)
16
+ result = Rupeepeethree::Tagger.print_tags(mp3)
17
17
  result.should_not match(/#{image_string}{2}/)
18
18
  end
19
+ it "gets a hash of the tags" do
20
+ tags = {title: "foodfight",
21
+ artist: "ninjaturtle",
22
+ album: "purplerain",
23
+ year: "1987",
24
+ picture: "spec/fixtures/cover_art.jpg"}
25
+ Rupeepeethree::Tagger.tag(mp3, tags)
26
+ t = Rupeepeethree::Tagger.tags(mp3)
27
+ expect(t[:title]).to eq("foodfight")
28
+ expect(t[:artist]).to eq("ninjaturtle")
29
+ expect(t[:album]).to eq("purplerain")
30
+ expect(t[:year]).to eq(1987)
31
+ end
19
32
  it "clears the tags" do
20
33
  tags = {title: "foodfight",
21
34
  artist: "ninjaturtle",
22
35
  album: "purplerain",
23
36
  year: "1987",
24
37
  picture: "spec/fixtures/cover_art.jpg"}
25
- Tagger.tag(mp3, tags)
26
- Tagger.clear(mp3)
27
- result = Tagger.print_tags(mp3)
38
+ Rupeepeethree::Tagger.tag(mp3, tags)
39
+ Rupeepeethree::Tagger.clear(mp3)
40
+ result = Rupeepeethree::Tagger.print_tags(mp3)
28
41
  result.should match(/title: \n/)
29
42
  result.should match(/artist: \n/)
30
43
  result.should match(/album: \n/)
@@ -1,7 +1,7 @@
1
1
  require "rupeepeethree"
2
2
  require "cocaine"
3
3
 
4
- describe Rupeepeethree do
4
+ describe 'integration test' do
5
5
  before :all do
6
6
  @rp3 = "ruby -Ilib bin/rp3"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rupeepeethree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Miller
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project: rupeepeethree
132
- rubygems_version: 2.0.3
132
+ rubygems_version: 2.2.0
133
133
  signing_key:
134
134
  specification_version: 3
135
135
  summary: tag your mp3 files
@@ -138,4 +138,3 @@ test_files:
138
138
  - spec/fixtures/test.mp3
139
139
  - spec/rupeepeethree/tagger_spec.rb
140
140
  - spec/rupeepeethree_spec.rb
141
- has_rdoc: