taglib-ruby 0.4.0-x86-mingw32

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.
Files changed (85) hide show
  1. data/.yardopts +9 -0
  2. data/CHANGES.md +53 -0
  3. data/Gemfile +4 -0
  4. data/Guardfile +8 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +87 -0
  7. data/Rakefile +29 -0
  8. data/docs/default/fulldoc/html/css/common.css +1 -0
  9. data/docs/taglib/base.rb +202 -0
  10. data/docs/taglib/id3v1.rb +5 -0
  11. data/docs/taglib/id3v2.rb +444 -0
  12. data/docs/taglib/mpeg.rb +120 -0
  13. data/docs/taglib/ogg.rb +77 -0
  14. data/docs/taglib/vorbis.rb +62 -0
  15. data/ext/extconf_common.rb +29 -0
  16. data/ext/taglib_base/extconf.rb +4 -0
  17. data/ext/taglib_base/includes.i +115 -0
  18. data/ext/taglib_base/taglib_base.i +139 -0
  19. data/ext/taglib_base/taglib_base_wrap.cxx +5153 -0
  20. data/ext/taglib_id3v1/extconf.rb +4 -0
  21. data/ext/taglib_id3v1/taglib_id3v1.i +11 -0
  22. data/ext/taglib_id3v1/taglib_id3v1_wrap.cxx +3110 -0
  23. data/ext/taglib_id3v2/extconf.rb +4 -0
  24. data/ext/taglib_id3v2/relativevolumeframe.i +35 -0
  25. data/ext/taglib_id3v2/taglib_id3v2.i +112 -0
  26. data/ext/taglib_id3v2/taglib_id3v2_wrap.cxx +9033 -0
  27. data/ext/taglib_mpeg/extconf.rb +4 -0
  28. data/ext/taglib_mpeg/taglib_mpeg.i +75 -0
  29. data/ext/taglib_mpeg/taglib_mpeg_wrap.cxx +4726 -0
  30. data/ext/taglib_ogg/extconf.rb +4 -0
  31. data/ext/taglib_ogg/taglib_ogg.i +36 -0
  32. data/ext/taglib_ogg/taglib_ogg_wrap.cxx +3631 -0
  33. data/ext/taglib_vorbis/extconf.rb +4 -0
  34. data/ext/taglib_vorbis/taglib_vorbis.i +48 -0
  35. data/ext/taglib_vorbis/taglib_vorbis_wrap.cxx +3083 -0
  36. data/ext/valgrind-suppressions.txt +170 -0
  37. data/ext/win.cmake +5 -0
  38. data/lib/libtag.dll +0 -0
  39. data/lib/taglib.rb +14 -0
  40. data/lib/taglib/base.rb +19 -0
  41. data/lib/taglib/id3v1.rb +1 -0
  42. data/lib/taglib/id3v2.rb +20 -0
  43. data/lib/taglib/mpeg.rb +7 -0
  44. data/lib/taglib/ogg.rb +1 -0
  45. data/lib/taglib/version.rb +10 -0
  46. data/lib/taglib/vorbis.rb +7 -0
  47. data/lib/taglib_base.so +0 -0
  48. data/lib/taglib_id3v1.so +0 -0
  49. data/lib/taglib_id3v2.so +0 -0
  50. data/lib/taglib_mpeg.so +0 -0
  51. data/lib/taglib_ogg.so +0 -0
  52. data/lib/taglib_vorbis.so +0 -0
  53. data/taglib-ruby.gemspec +122 -0
  54. data/tasks/docs_coverage.rake +26 -0
  55. data/tasks/ext.rake +81 -0
  56. data/tasks/gemspec_check.rake +19 -0
  57. data/tasks/swig.rake +43 -0
  58. data/test/data/Makefile +15 -0
  59. data/test/data/add-relative-volume.cpp +40 -0
  60. data/test/data/crash.mp3 +0 -0
  61. data/test/data/globe_east_540.jpg +0 -0
  62. data/test/data/id3v1-create.cpp +31 -0
  63. data/test/data/id3v1.mp3 +0 -0
  64. data/test/data/relative-volume.mp3 +0 -0
  65. data/test/data/sample.mp3 +0 -0
  66. data/test/data/unicode.mp3 +0 -0
  67. data/test/data/vorbis-create.cpp +42 -0
  68. data/test/data/vorbis.oga +0 -0
  69. data/test/fileref_open_test.rb +32 -0
  70. data/test/fileref_properties_test.rb +21 -0
  71. data/test/fileref_write_test.rb +62 -0
  72. data/test/helper.rb +10 -0
  73. data/test/id3v1_tag_test.rb +36 -0
  74. data/test/id3v2_frames_test.rb +115 -0
  75. data/test/id3v2_memory_test.rb +87 -0
  76. data/test/id3v2_relative_volume_test.rb +62 -0
  77. data/test/id3v2_tag_test.rb +59 -0
  78. data/test/id3v2_unicode_test.rb +47 -0
  79. data/test/id3v2_write_test.rb +100 -0
  80. data/test/mpeg_file_test.rb +76 -0
  81. data/test/tag_test.rb +21 -0
  82. data/test/unicode_filename_test.rb +29 -0
  83. data/test/vorbis_file_test.rb +54 -0
  84. data/test/vorbis_tag_test.rb +79 -0
  85. metadata +191 -0
@@ -0,0 +1,87 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestID3v2Memory < Test::Unit::TestCase
4
+
5
+ N = 1000
6
+
7
+ context "TagLib::ID3v2" do
8
+ setup do
9
+ @file = TagLib::MPEG::File.new("test/data/sample.mp3", false)
10
+ @tag = @file.id3v2_tag
11
+ @apic = @tag.frame_list("APIC").first
12
+ end
13
+
14
+ should "not corrupt memory with FrameList" do
15
+ N.times do
16
+ @tag.frame_list
17
+ end
18
+ end
19
+
20
+ should "not corrupt memory with ByteVector" do
21
+ data = nil
22
+ N.times do
23
+ data = @apic.picture
24
+ end
25
+ N.times do
26
+ @apic.picture = data
27
+ end
28
+ end
29
+
30
+ should "not corrupt memory with StringList" do
31
+ txxx = @tag.frame_list('TXXX').first
32
+ N.times do
33
+ txxx.field_list
34
+ end
35
+ N.times do
36
+ txxx.field_list = ["one", "two", "three"]
37
+ end
38
+ end
39
+
40
+ should "not segfault when tag is deleted along with file" do
41
+ @file = nil
42
+ begin
43
+ N.times do
44
+ GC.start
45
+ @tag.title
46
+ end
47
+ rescue => e
48
+ assert_equal "ObjectPreviouslyDeleted", e.class.to_s
49
+ else
50
+ raise "GC did not delete file, unsure if test was successful."
51
+ end
52
+ end
53
+
54
+ should "not segfault when audio properties are deleted along with file" do
55
+ file = TagLib::MPEG::File.new("test/data/crash.mp3", true)
56
+ properties = file.audio_properties
57
+ file.close
58
+ begin
59
+ N.times do
60
+ GC.start
61
+ properties.bitrate
62
+ end
63
+ rescue => e
64
+ assert_equal "ObjectPreviouslyDeleted", e.class.to_s
65
+ else
66
+ raise "GC did not delete file, unsure if test was successful."
67
+ end
68
+ end
69
+
70
+ should "not throw when adding frame via Tag.add_frame" do
71
+ tcom = TagLib::ID3v2::TextIdentificationFrame.new('TCOM', TagLib::String::Latin1)
72
+ tcom.text = "Some composer"
73
+ @tag.add_frame tcom
74
+ # the following leads to an ObjectPreviouslyDeleted error (see Issue #8)
75
+ assert_nothing_raised do
76
+ @tag.frame_list.find{ |fr| 'TCOM' == fr.frame_id }
77
+ end
78
+ end
79
+
80
+ teardown do
81
+ if @file
82
+ @file.close
83
+ @file = nil
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,62 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestID3v2RelativeVolumeFrame < Test::Unit::TestCase
4
+ context "The relative-volume.mp3 RVA2 frame" do
5
+ setup do
6
+ @file = TagLib::MPEG::File.new("test/data/relative-volume.mp3")
7
+ @tag = @file.id3v2_tag
8
+ @rv = @tag.frame_list('RVA2').first
9
+ end
10
+
11
+ should "exist" do
12
+ assert_not_nil @rv
13
+ end
14
+
15
+ should "have channels" do
16
+ expected = [TagLib::ID3v2::RelativeVolumeFrame::MasterVolume, TagLib::ID3v2::RelativeVolumeFrame::Subwoofer]
17
+ assert_equal expected, @rv.channels
18
+ end
19
+
20
+ should "have volume adjustments" do
21
+ assert_equal 512, @rv.volume_adjustment_index
22
+ assert_equal 1.0, @rv.volume_adjustment
23
+ assert_equal 1024, @rv.volume_adjustment_index(TagLib::ID3v2::RelativeVolumeFrame::Subwoofer)
24
+ assert_equal 2.0, @rv.volume_adjustment(TagLib::ID3v2::RelativeVolumeFrame::Subwoofer)
25
+ end
26
+
27
+ should "have peak volumes" do
28
+ master_pv = @rv.peak_volume
29
+ assert_equal 8, master_pv.bits_representing_peak
30
+ assert_equal 0b01000001.chr, master_pv.peak_volume
31
+
32
+ subwoofer_pv = @rv.peak_volume(TagLib::ID3v2::RelativeVolumeFrame::Subwoofer)
33
+ assert_equal 4, subwoofer_pv.bits_representing_peak
34
+ assert_equal 0b00111111.chr, subwoofer_pv.peak_volume
35
+ end
36
+
37
+ should "accept new volume adjustments" do
38
+ @rv.set_volume_adjustment_index(2048, TagLib::ID3v2::RelativeVolumeFrame::FrontCentre)
39
+ assert_equal 2048, @rv.volume_adjustment_index(TagLib::ID3v2::RelativeVolumeFrame::FrontCentre)
40
+ @rv.set_volume_adjustment(4.0, TagLib::ID3v2::RelativeVolumeFrame::FrontLeft)
41
+ assert_equal 4.0, @rv.volume_adjustment(TagLib::ID3v2::RelativeVolumeFrame::FrontLeft)
42
+ end
43
+
44
+ should "accept new peak volumes" do
45
+ pv = TagLib::ID3v2::PeakVolume.new
46
+ assert_equal 0, pv.bits_representing_peak
47
+ assert_equal "", pv.peak_volume
48
+ pv.bits_representing_peak = 6
49
+ pv.peak_volume = 0b110111.chr
50
+ @rv.set_peak_volume(pv, TagLib::ID3v2::RelativeVolumeFrame::BackLeft)
51
+
52
+ pv2 = @rv.peak_volume(TagLib::ID3v2::RelativeVolumeFrame::BackLeft)
53
+ assert_equal 6, pv2.bits_representing_peak
54
+ assert_equal 0b110111.chr, pv2.peak_volume
55
+ end
56
+
57
+ teardown do
58
+ @file.close
59
+ @file = nil
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,59 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestID3v2Tag < Test::Unit::TestCase
4
+ context "The sample.mp3 file" do
5
+ setup do
6
+ read_properties = false
7
+ @file = TagLib::MPEG::File.new("test/data/sample.mp3", read_properties)
8
+ end
9
+
10
+ should "have an ID3v2 tag" do
11
+ assert_not_nil @file.id3v2_tag
12
+ end
13
+
14
+ context "tag" do
15
+ setup do
16
+ @tag = @file.id3v2_tag
17
+ end
18
+
19
+ should "have basic properties" do
20
+ assert_equal 'Dummy Title', @tag.title
21
+ assert_equal 'Dummy Artist', @tag.artist
22
+ assert_equal 'Dummy Album', @tag.album
23
+ assert_equal 'Dummy Comment', @tag.comment
24
+ assert_equal 'Pop', @tag.genre
25
+ assert_equal 2000, @tag.year
26
+ assert_equal 1, @tag.track
27
+ assert_equal false, @tag.empty?
28
+ end
29
+ end
30
+
31
+ teardown do
32
+ @file.close
33
+ @file = nil
34
+ end
35
+ end
36
+
37
+ context "A new ID3v2::Tag" do
38
+ setup do
39
+ @tag = TagLib::ID3v2::Tag.new
40
+ end
41
+
42
+ should "be empty" do
43
+ assert @tag.empty?
44
+ end
45
+
46
+ should "have nil for string attributes" do
47
+ assert_nil @tag.title
48
+ assert_nil @tag.artist
49
+ assert_nil @tag.album
50
+ assert_nil @tag.comment
51
+ assert_nil @tag.genre
52
+ end
53
+
54
+ should "have 0 for numeric attributes" do
55
+ assert_equal 0, @tag.track
56
+ assert_equal 0, @tag.year
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestID3v2Unicode < Test::Unit::TestCase
4
+ context "The unicode.mp3 file" do
5
+ setup do
6
+ read_properties = false
7
+ @file = TagLib::MPEG::File.new("test/data/unicode.mp3", read_properties)
8
+ end
9
+
10
+ should "have an ID3v2 tag" do
11
+ assert_not_nil @file.id3v2_tag
12
+ end
13
+
14
+ if HAVE_ENCODING
15
+ context "tag" do
16
+ setup do
17
+ @tag = @file.id3v2_tag
18
+ end
19
+
20
+ should "return strings in the right encoding" do
21
+ assert_equal "UTF-8", @tag.title.encoding.to_s
22
+ end
23
+
24
+ should "convert strings to the right encoding" do
25
+ # Unicode Snowman in UTF-16
26
+ utf16_encoded = "\x26\x03"
27
+ utf16_encoded.force_encoding("UTF-16BE")
28
+
29
+ # It should be converted here
30
+ @tag.title = utf16_encoded
31
+
32
+ result = @tag.title
33
+
34
+ # In order for == to work, they have to be in the same
35
+ # encoding
36
+ utf8_encoded = utf16_encoded.encode("UTF-8")
37
+ assert_equal utf8_encoded, result
38
+ end
39
+ end
40
+ end
41
+
42
+ teardown do
43
+ @file.close
44
+ @file = nil
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,100 @@
1
+ require File.join(File.dirname(__FILE__), '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.close
54
+ @file = nil
55
+
56
+ written_file = TagLib::MPEG::File.new(OUTPUT_FILE, false)
57
+ written_apic = written_file.id3v2_tag.frame_list("APIC").first
58
+ assert_equal "image/jpeg", written_apic.mime_type
59
+ assert_equal "desc", written_apic.description
60
+ assert_equal picture_data, written_apic.picture
61
+ written_file.close
62
+ end
63
+
64
+ should "be able to set field_list" do
65
+ tit2 = TagLib::ID3v2::TextIdentificationFrame.new("TIT2", TagLib::String::UTF8)
66
+ texts = ["one", "two"]
67
+ tit2.field_list = texts
68
+ assert_equal texts, tit2.field_list
69
+ @tag.add_frame(tit2)
70
+ success = @file.save
71
+ assert success
72
+ end
73
+
74
+ if HAVE_ENCODING
75
+ should "be able to set unicode fields" do
76
+ # Hello, Unicode Snowman (not in Latin1)
77
+ text = "Hello, \u{2603}"
78
+
79
+ # If we don't set the default text encoding to UTF-8, taglib
80
+ # will print a warning
81
+ frame_factory = TagLib::ID3v2::FrameFactory.instance
82
+ frame_factory.default_text_encoding = TagLib::String::UTF8
83
+
84
+ @tag.title = text
85
+ @file.save
86
+
87
+ assert_equal text, @tag.title
88
+ end
89
+ end
90
+ end
91
+
92
+ teardown do
93
+ if @file
94
+ @file.close
95
+ @file = nil
96
+ end
97
+ FileUtils.rm OUTPUT_FILE
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,76 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestMPEGFile < Test::Unit::TestCase
4
+ context "The crash.mp3 file" do
5
+ setup do
6
+ read_properties = true
7
+ @file = TagLib::MPEG::File.new("test/data/crash.mp3", read_properties)
8
+ end
9
+
10
+ should "have a basic tag" do
11
+ tag = @file.tag
12
+ assert_not_nil tag
13
+ assert_equal TagLib::Tag, tag.class
14
+ end
15
+
16
+ should "have an ID3v2 tag" do
17
+ tag = @file.id3v2_tag(false)
18
+ assert_not_nil tag
19
+ assert_equal TagLib::ID3v2::Tag, tag.class
20
+ end
21
+
22
+ context "audio properties" do
23
+ setup do
24
+ @properties = @file.audio_properties
25
+ end
26
+
27
+ should "be MPEG audio properties" do
28
+ assert_equal TagLib::MPEG::Properties, @properties.class
29
+ end
30
+
31
+ should "contain information" do
32
+ assert_equal 2, @properties.length
33
+ assert_equal 157, @properties.bitrate
34
+ assert_equal 44100, @properties.sample_rate
35
+ assert_equal 2, @properties.channels
36
+ assert_equal TagLib::MPEG::Header::Version1, @properties.version
37
+ assert_equal 3, @properties.layer
38
+ assert_equal false, @properties.protection_enabled
39
+ assert_equal TagLib::MPEG::Header::JointStereo, @properties.channel_mode
40
+ assert_equal false, @properties.copyrighted?
41
+ assert_equal true, @properties.original?
42
+ end
43
+
44
+ context "Xing header" do
45
+ setup do
46
+ @xing_header = @properties.xing_header
47
+ end
48
+
49
+ should "exist" do
50
+ assert_not_nil @xing_header
51
+ end
52
+
53
+ should "contain information" do
54
+ assert @xing_header.valid?
55
+ assert_equal 88, @xing_header.total_frames
56
+ assert_equal 45140, @xing_header.total_size
57
+ end
58
+ end
59
+ end
60
+
61
+ teardown do
62
+ @file.close
63
+ @file = nil
64
+ end
65
+ end
66
+
67
+ context "TagLib::MPEG::File" do
68
+ should "have open method" do
69
+ title = nil
70
+ TagLib::MPEG::File.open("test/data/sample.mp3", false) do |file|
71
+ title = file.tag.title
72
+ end
73
+ assert_equal "Dummy Title", title
74
+ end
75
+ end
76
+ end
data/test/tag_test.rb ADDED
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__), '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