taglib-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ require 'helper'
2
+
3
+ require 'fileutils'
4
+
5
+ class TestID3v2Write < Test::Unit::TestCase
6
+
7
+ SAMPLE_FILE = "test/data/sample.mp3"
8
+ OUTPUT_FILE = "test/data/output.mp3"
9
+
10
+ context "TagLib::MPEG::File" do
11
+ setup do
12
+ FileUtils.cp SAMPLE_FILE, OUTPUT_FILE
13
+ @file = TagLib::MPEG::File.new(OUTPUT_FILE, false)
14
+ end
15
+
16
+ should "be able to strip the tag" do
17
+ assert_not_nil @file.id3v2_tag
18
+ success = @file.strip
19
+ assert success
20
+ assert_nil @file.id3v2_tag
21
+ end
22
+
23
+ context "with a fresh tag" do
24
+ setup do
25
+ @file.strip
26
+ @tag = @file.id3v2_tag(true)
27
+ end
28
+
29
+ should "be able to create a new tag" do
30
+ assert_not_nil @tag
31
+ assert_equal 0, @tag.frame_list.size
32
+ end
33
+
34
+ should "be able to save it" do
35
+ success = @file.save
36
+ assert success
37
+ end
38
+
39
+ should "be able to add a new frame to it and read it back" do
40
+ picture_data = File.open("test/data/globe_east_540.jpg", 'rb'){ |f| f.read }
41
+
42
+ apic = TagLib::ID3v2::AttachedPictureFrame.new
43
+ apic.mime_type = "image/jpeg"
44
+ apic.description = "desc"
45
+ apic.text_encoding = TagLib::String::UTF8
46
+ apic.picture = picture_data
47
+ apic.type = TagLib::ID3v2::AttachedPictureFrame::FrontCover
48
+
49
+ @tag.add_frame(apic)
50
+
51
+ success = @file.save
52
+ assert success
53
+ @file = nil
54
+
55
+ written_file = TagLib::MPEG::File.new(OUTPUT_FILE, false)
56
+ written_apic = written_file.id3v2_tag.frame_list("APIC").first
57
+ assert_equal "image/jpeg", written_apic.mime_type
58
+ assert_equal "desc", written_apic.description
59
+ assert_equal picture_data, written_apic.picture
60
+ end
61
+
62
+ should "be able to set field_list" do
63
+ tit2 = TagLib::ID3v2::TextIdentificationFrame.new("TIT2", TagLib::String::UTF8)
64
+ texts = ["one", "two"]
65
+ tit2.field_list = texts
66
+ assert_equal texts, tit2.field_list
67
+ @tag.add_frame(tit2)
68
+ success = @file.save
69
+ assert success
70
+ end
71
+
72
+ if HAVE_ENCODING
73
+ should "be able to set unicode fields" do
74
+ # Hello, Unicode Snowman (not in Latin1)
75
+ text = "Hello, \u{2603}"
76
+
77
+ # If we don't set the default text encoding to UTF-8, taglib
78
+ # will print a warning
79
+ frame_factory = TagLib::ID3v2::FrameFactory.instance
80
+ frame_factory.default_text_encoding = TagLib::String::UTF8
81
+
82
+ @tag.title = text
83
+ @file.save
84
+
85
+ assert_equal text, @tag.title
86
+ end
87
+ end
88
+ end
89
+
90
+ teardown do
91
+ @file = nil
92
+ FileUtils.rm OUTPUT_FILE
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ class TestTag < Test::Unit::TestCase
4
+ context "The sample.mp3 file" do
5
+ setup do
6
+ @fileref = TagLib::FileRef.new("test/data/sample.mp3", false)
7
+ @tag = @fileref.tag
8
+ end
9
+
10
+ should "have basic tag information" do
11
+ assert_equal 'Dummy Title', @tag.title
12
+ assert_equal 'Dummy Artist', @tag.artist
13
+ assert_equal 'Dummy Album', @tag.album
14
+ assert_equal 'Dummy Comment', @tag.comment
15
+ assert_equal 'Pop', @tag.genre
16
+ assert_equal 2000, @tag.year
17
+ assert_equal 1, @tag.track
18
+ assert_equal false, @tag.empty?
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taglib-ruby
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Robin Stocker
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-17 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 5
27
+ segments:
28
+ - 0
29
+ - 7
30
+ version: "0.7"
31
+ version_requirements: *id001
32
+ name: rake-compiler
33
+ prerelease: false
34
+ type: :development
35
+ - !ruby/object:Gem::Dependency
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ hash: 21
42
+ segments:
43
+ - 2
44
+ - 11
45
+ version: "2.11"
46
+ version_requirements: *id002
47
+ name: shoulda
48
+ prerelease: false
49
+ type: :development
50
+ - !ruby/object:Gem::Dependency
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ hash: 23
57
+ segments:
58
+ - 1
59
+ - 0
60
+ - 0
61
+ version: 1.0.0
62
+ version_requirements: *id003
63
+ name: bundler
64
+ prerelease: false
65
+ type: :development
66
+ - !ruby/object:Gem::Dependency
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ hash: 7
73
+ segments:
74
+ - 1
75
+ - 6
76
+ - 4
77
+ version: 1.6.4
78
+ version_requirements: *id004
79
+ name: jeweler
80
+ prerelease: false
81
+ type: :development
82
+ - !ruby/object:Gem::Dependency
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ version_requirements: *id005
93
+ name: rcov
94
+ prerelease: false
95
+ type: :development
96
+ - !ruby/object:Gem::Dependency
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ hash: 21
103
+ segments:
104
+ - 3
105
+ - 9
106
+ version: "3.9"
107
+ version_requirements: *id006
108
+ name: rdoc
109
+ prerelease: false
110
+ type: :development
111
+ description: "taglib-ruby\n\
112
+ ===========\n\n\
113
+ Ruby interface for the [TagLib C++ library][taglib].\n\n\
114
+ In contrast to other libraries, this one wraps the full C++ API using\n\
115
+ SWIG, not only the minimal C API. This means that all tags can be\n\
116
+ accessed.\n\n\
117
+ taglib-ruby is work in progress, here are some of the things still left\n\
118
+ to do (contributors very welcome):\n\n\
119
+ * Wrap TagLib::MPEG::Properties\n\
120
+ * Pre-compiled Gem for Windows\n\
121
+ * More coverage of the library besides ID3v2\n\n\
122
+ Usage\n\
123
+ -----\n\n\
124
+ Here's an example for reading an ID3v2 tag:\n\n require 'taglib'\n\n # Load an ID3v2 tag from a file\n file = TagLib::MPEG::File.new(\"wake_up.mp3\")\n tag = file.id3v2_tag\n\n # Read basic attributes\n tag.title #=> \"Wake Up\"\n tag.artist #=> \"Arcade Fire\"\n tag.track #=> 7\n\n # Access all frames\n tag.frame_list.size #=> 13\n\n # Track frame\n track = tag.frame_list('TRCK').first\n track.to_s #=> \"7/10\"\n\n # Attached picture frame\n cover = tag.frame_list('APIC').first\n cover.mime_type #=> \"image/jpeg\"\n cover.picture #=> \"\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF...\"\n\n\
125
+ And here's an example for writing one:\n\n file = TagLib::MPEG::File.new(\"joga.mp3\")\n tag = file.id3v2_tag\n\n # Write basic attributes\n tag.artist = \"Bj\xC3\xB6rk\"\n tag.title = \"J\xC3\xB3ga\"\n\n # Add attached picture frame\n apic = TagLib::ID3v2::AttachedPictureFrame.new\n apic.mime_type = \"image/jpeg\"\n apic.description = \"Cover\"\n apic.type = TagLib::ID3v2::AttachedPictureFrame::FrontCover\n apic.picture = File.open(\"cover.jpg\", 'rb'){ |f| f.read }\n\n tag.add_frame(apic)\n\n file.save\n\n\
126
+ ### Encoding\n\n\
127
+ By default, taglib stores text frames as ISO-8859-1 (Latin-1), if the\n\
128
+ text contains only characters that are available in that encoding. If\n\
129
+ not (e.g. with Cyrillic, Chinese, Japanese), it prints a warning and\n\
130
+ stores the text as UTF-8.\n\n\
131
+ When you already know that you want to store the text as UTF-8, you can\n\
132
+ change the default text encoding:\n\n frame_factory = TagLib::ID3v2::FrameFactory.instance\n frame_factory.default_text_encoding = TagLib::String::UTF8\n\n\
133
+ Another option is using the advanced API:\n\n title = tag.frame_list('TIT2').first\n title.text = \"J\xC3\xB3ga\"\n title.text_encoding = TagLib::String::UTF8\n\n\
134
+ Contributing\n\
135
+ ------------\n\n\
136
+ * Check out the latest master to make sure the feature hasn't been\n implemented or the bug hasn't been fixed yet\n\
137
+ * Check out the issue tracker to make sure someone already hasn't\n requested it and/or contributed it\n\
138
+ * Fork the project\n\
139
+ * Start a feature/bugfix branch\n\
140
+ * Commit and push until you are happy with your contribution\n\
141
+ * Make sure to add tests for it. This is important so I don't break it\n in a future version unintentionally.\n\
142
+ * Please try not to mess with the Rakefile, version, or history. If you\n want to have your own version, or is otherwise necessary, that is\n fine, but please isolate to its own commit so I can cherry-pick around\n it.\n\n\
143
+ License\n\
144
+ -------\n\n\
145
+ taglib-ruby is distributed under the MIT License,\n\
146
+ see LICENSE.txt for details.\n\n\
147
+ Copyright (c) 2010, 2011 Robin Stocker.\n\n\
148
+ [taglib]: http://developer.kde.org/~wheeler/taglib.html\n"
149
+ email: robin@nibor.org
150
+ executables: []
151
+
152
+ extensions:
153
+ - ext/taglib_base/extconf.rb
154
+ - ext/taglib_mpeg/extconf.rb
155
+ - ext/taglib_id3v2/extconf.rb
156
+ extra_rdoc_files:
157
+ - LICENSE.txt
158
+ - README.md
159
+ files:
160
+ - Gemfile
161
+ - Gemfile.lock
162
+ - LICENSE.txt
163
+ - README.md
164
+ - Rakefile
165
+ - ext/Rakefile
166
+ - ext/extconf_common.rb
167
+ - ext/taglib_base/extconf.rb
168
+ - ext/taglib_base/includes.i
169
+ - ext/taglib_base/taglib_base.i
170
+ - ext/taglib_base/taglib_base_wrap.cxx
171
+ - ext/taglib_id3v2/extconf.rb
172
+ - ext/taglib_id3v2/taglib_id3v2.i
173
+ - ext/taglib_id3v2/taglib_id3v2_wrap.cxx
174
+ - ext/taglib_mpeg/extconf.rb
175
+ - ext/taglib_mpeg/taglib_mpeg.i
176
+ - ext/taglib_mpeg/taglib_mpeg_wrap.cxx
177
+ - ext/valgrind-suppressions.txt
178
+ - lib/taglib.rb
179
+ - lib/taglib/base.rb
180
+ - lib/taglib/id3v2.rb
181
+ - lib/taglib/mpeg.rb
182
+ - lib/taglib/version.rb
183
+ - test/data/globe_east_540.jpg
184
+ - test/data/sample.mp3
185
+ - test/data/unicode.mp3
186
+ - test/helper.rb
187
+ - test/test_id3v2_frames.rb
188
+ - test/test_id3v2_memory.rb
189
+ - test/test_id3v2_tag.rb
190
+ - test/test_id3v2_unicode.rb
191
+ - test/test_id3v2_write.rb
192
+ - test/test_tag.rb
193
+ homepage: http://github.com/robinst/taglib-ruby
194
+ licenses:
195
+ - MIT
196
+ post_install_message:
197
+ rdoc_options: []
198
+
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ none: false
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ hash: 3
207
+ segments:
208
+ - 0
209
+ version: "0"
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ none: false
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ hash: 3
216
+ segments:
217
+ - 0
218
+ version: "0"
219
+ requirements: []
220
+
221
+ rubyforge_project:
222
+ rubygems_version: 1.8.10
223
+ signing_key:
224
+ specification_version: 3
225
+ summary: Ruby interface for the complete taglib C++ library
226
+ test_files: []
227
+