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 +4 -4
- data/README.md +7 -1
- data/Rakefile +4 -1
- data/bin/rp3 +1 -1
- data/lib/rupeepeethree.rb +35 -33
- data/lib/rupeepeethree/tagger.rb +76 -60
- data/lib/rupeepeethree/version.rb +2 -2
- data/spec/fixtures/test.mp3 +0 -0
- data/spec/rupeepeethree/tagger_spec.rb +22 -9
- data/spec/rupeepeethree_spec.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9b8edd7bd8c74aa52856c2cc0fce126106ace72
|
4
|
+
data.tar.gz: 2adb6bcf7b0d698961137239b9673007498e82c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
data/bin/rp3
CHANGED
data/lib/rupeepeethree.rb
CHANGED
@@ -3,41 +3,43 @@ require 'rupeepeethree/tagger'
|
|
3
3
|
require 'rupeepeethree/version'
|
4
4
|
require 'trollop'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
data/lib/rupeepeethree/tagger.rb
CHANGED
@@ -1,77 +1,93 @@
|
|
1
1
|
require 'taglib'
|
2
2
|
require 'mime/types'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
result
|
54
|
-
|
55
|
-
|
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
|
-
|
59
|
-
result << "
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
module Rupeepeethree
|
2
|
+
VERSION = "0.0.4"
|
3
3
|
end
|
data/spec/fixtures/test.mp3
CHANGED
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/)
|
data/spec/rupeepeethree_spec.rb
CHANGED
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.
|
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
|
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:
|