ruby-mp3tag-1.0.orig/0000775000000000000000000000000007330773531011363 5ustar ruby-mp3tag-1.0.orig/mp3tag.30000664000000000000000000000544007330773531012645 0ustar .\" DO NOT MODIFY THIS FILE! it was generated by rd2 .TH mp3tag.rb 1 "July 2001" .SH Synopsis .PP Read the tag from a file or create and Mp3Tag instance for saving tag to mp3 file later: .nf \& tag = Mp3Tag.new(filename) .fi Examining tags: .nf \& tag.songname \& tag.artist \& tag.album \& tag.year \& tag.comment \& tag.tracknum \& tag.genre_id \& tag.genre .fi Setting tags: .nf \& tag.songname = "My Song" \& tag.artist = "Me" \& tag.album = "My Album" \& tag.year = "2001" \& tag.comment = "No Comment" \& tag.tracknum = 3 \& \& tag.genre_id = 23 \& tag.genre = "Drum Solo" .fi genre_id's should exist in Mp3Tag::Genres. Elements in Mp3Tag::Genres can be assigned using tag.genre= and the id will be looked up automatically. Saving tag to mp3: .nf \& tag.commit .fi Checking if a file has a tag: .nf \& Mp3Tag.hastag?(filename) .fi .SH Class Methods .PP .TP .fi .B Mp3Tag.new(path) Creates a new Mp3Tag object for the file give by path. .TP .fi .B Mp3Tag.hastag?(filename) Tests if filename has a ID3V1.0 or ID3V1.1 tag. Returns a boolean values giving the result of the test. .TP .fi .B Mp3Tag.removetag(filename) Removes an ID3v1 tag from the MP3 file filename .SH Instance Methods .PP .TP .fi .B songname .TP .fi .B artist .TP .fi .B album .TP .fi .B comment Return the song name, artist, album, or comment from the tag as a String object. Will return empty strings if file did not have a tag. .TP .fi .B tracknum Returns the track number from the tag. Will return 0 if the track number was not set in the tag when loaded, or if the file had no tag. .TP .fi .B year Returns the year from the tag. Will return 0 if the file had no tag. .TP .fi .B genre_id Return the id number of the genre from the tag. Will return 255 if the file had no tag. .TP .fi .B genre Returns the genre name. Will return "Unknown" if the file had no tag or the genre id was not in Mp3Tag::Genres .TP .fi .B path Returns the full path name of the MP3 file. .TP .fi .B filename Returns the filename without the directory part of the MP3 File. .TP .fi .B songname=(txt) .TP .fi .B artist=(txt) .TP .fi .B album=(txt) .TP .fi .B comment=(txt) Sets the song name, atist, album, or comment for the tag to txt. txt should be a String object. .TP .fi .B tracknum=(num) Sets the track number for the tag. Only values in the range (0..255) are allowed. .TP .fi .B year=(num) Sets the year for the tag. Should be a four digit number. .TP .fi .B genre_id=(num) Sets the the genre id for the tag. Only values in the range (0..255) are allowed. .TP .fi .B genre=(txt) Sets the genre id for the tag to the index of txt in Mp3Tag::Genres. The genre id will be set to 255 if txt is not found in the list. .TP .fi .B commit Saves the tag to the MP3 file. Will overwrite any existing tag. ruby-mp3tag-1.0.orig/install.rb0000775000000000000000000000076507330772501013365 0ustar #!/usr/bin/env ruby require "rbconfig" require "ftools" include Config RV = File.join(CONFIG['sitedir'], CONFIG['MAJOR'] + '.' + CONFIG['MINOR']) DSTPATH = RV FILES = %w(mp3tag.rb) MANFILES = %(mp3tag.3) File.mkpath DSTPATH, true begin FILES.each { |name| File.install name, File.join(DSTPATH), 0644, true } MANFILES.each { |name| File.install name, File.join(CONFIG['mandir'], 'man3'), 0644, true } rescue puts 'install failed!' puts $! else puts 'install succeed!' end ruby-mp3tag-1.0.orig/README0000664000000000000000000000260407330773520012243 0ustar ABOUT mp3tag.rb - a ruby module to read and write ID3V1.1 tags in MP3 Files. Copyright (C) 2001 by Lars Christensen. LICENSE INFORMATION This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ABOUT mp3tag.rb is a ruby class to read ID3v1.0 an ID3v1.1, and write ID3v1.1 tags in MP3 files. These tags save meta information about the music piece such song name, artist, album, genre, track number and a comment. INSTALLATION Run the 'install.rb' script with your ruby interpreter, e.g.: ruby install.rb This will install mp3tag.rb in your site_ruby directory. You will need to have write permissions to this directory. USAGE See mp3tag(3) (using man) or mp3tag.html (using your browser). ruby-mp3tag-1.0.orig/mp3tag.rb0000664000000000000000000001474407330773322013113 0ustar =begin = Synopsis Read the tag from a file or create and Mp3Tag instance for saving tag to mp3 file later: tag = Mp3Tag.new(filename) Examining tags: tag.songname tag.artist tag.album tag.year tag.comment tag.tracknum tag.genre_id tag.genre Setting tags: tag.songname = "My Song" tag.artist = "Me" tag.album = "My Album" tag.year = "2001" tag.comment = "No Comment" tag.tracknum = 3 tag.genre_id = 23 tag.genre = "Drum Solo" genre_id's should exist in Mp3Tag::Genres. Elements in Mp3Tag::Genres can be assigned using tag.genre= and the id will be looked up automatically. Saving tag to mp3: tag.commit Checking if a file has a tag: Mp3Tag.hastag?(filename) =end # ' class Mp3Tag VERSION = '1.0' Genres = [ 'Blues', 'Classic Rock', 'Country', 'Dance', 'Disco', 'Funk', 'Grunge', 'Hip-Hop', 'Jazz', 'Metal', 'New Age', 'Oldies', 'Other', 'Pop', 'R&B', 'Rap', 'Reggae', 'Rock', 'Techno', 'Industrial', 'Alternative', 'Ska', 'Death Metal', 'Pranks', 'Soundtrack', 'Euro-Techno', 'Ambient', 'Trip-Hop', 'Vocal', 'Jazz+Funk', 'Fusion', 'Trance', 'Classical', 'Instrumental', 'Acid', 'House', 'Game', 'Sound Clip', 'Gospel', 'Noise', 'Alternative Rock', 'Bass', 'Soul', 'Punk', 'Space', 'Meditative', 'Instrumental Pop', 'Instrumental Rock', 'Ethnic', 'Gothic', 'Darkwave', 'Techno-Industrial', 'Electronic', 'Pop-Folk', 'Eurodance', 'Dream', 'Southern Rock', 'Comedy', 'Cult', 'Gangsta', 'Top 40', 'Christian Rap', 'Pop/Funk', 'Jungle', 'Native US', 'Cabaret', 'New Wave', 'Psychadelic', 'Rave', 'Showtunes', 'Trailer', 'Lo-Fi', 'Tribal', 'Acid Punk', 'Acid Jazz', 'Polka', 'Retro', 'Musical', 'Rock & Roll', 'Hard Rock', 'Folk', 'Folk-Rock', 'National Folk', 'Swing', 'Fast Fusion', 'Bebob', 'Latin', 'Revival', 'Celtic', 'Bluegrass', 'Avantgarde', 'Gothic Rock', 'Progressive Rock', 'Psychedelic Rock', 'Symphonic Rock', 'Slow Rock', 'Big Band', 'Chorus', 'Easy Listening', 'Acoustic', 'Humour', 'Speech', 'Chanson', 'Opera', 'Chamber Music', 'Sonata', 'Symphony', 'Booty Bass', 'Primus', 'Porn Groove', 'Satire', 'Slow Jam', 'Club', 'Tango', 'Samba', 'Folklore', 'Ballad', 'Power Ballad', 'Rhytmic Soul', 'Freestyle', 'Duet', 'Punk Rock', 'Drum Solo', 'Acapella', 'Euro-House', 'Dance Hall', 'Goa', 'Drum & Bass', 'Club-House', 'Hardcore', 'Terror', 'Indie', 'BritPop', 'Negerpunk', 'Polsk Punk', 'Beat', 'Christian Gangsta Rap', 'Heavy Metal', 'Black Metal', 'Crossover', 'Contemporary Christian', 'Christian Rock', 'Merengue', 'Salsa', 'Trash Metal', 'Anime', 'Jpop', 'Synthpop' ] attr_accessor :genre_id, :songname, :artist, :album, :comment attr_reader :path, :year, :tracknum TagSize = 128 TAGFORMAT_WRITE = 'Z30Z30Z30Z4Z28CCC'# write zero padded TAGFORMAT_READ = 'A30A30A30A4A30C'# accept zero/space padded input =begin = Class Methods --- Mp3Tag.new(path) Creates a new Mp3Tag object for the file give by ((|path|)). =end def initialize(path) @path = path @genre_id = 255 @songname = '' @artist = '' @album = '' @comment = '' @tracknum = 0 @year = 0 readtag end =begin --- Mp3Tag.hastag?(filename) Tests if ((|filename|)) has a ID3V1.0 or ID3V1.1 tag. Returns a boolean values giving the result of the test. =end def Mp3Tag.hastag?(file) hastag = nil File.open(file, 'r') { |f| f.seek(-TagSize, IO::SEEK_END) tag = f.read(3) hastag = (tag == 'TAG') } return hastag end =begin --- Mp3Tag.removetag(filename) Removes an ID3v1 tag from the MP3 file ((|filename|)) =end def Mp3Tag.removetag(filename) if Mp3Tag.hastag?(filename) newsize = File.size(filename) - TagSize File.open(filename, 'r+') { |f| f.truncate(newsize) } end end =begin = Instance Methods --- songname --- artist --- album --- comment Return the song name, artist, album, or comment from the tag as a String object. Will return empty strings if file did not have a tag. --- tracknum Returns the track number from the tag. Will return 0 if the track number was not set in the tag when loaded, or if the file had no tag. --- year Returns the year from the tag. Will return 0 if the file had no tag. --- genre_id Return the id number of the genre from the tag. Will return 255 if the file had no tag. --- genre Returns the genre name. Will return "Unknown" if the file had no tag or the genre id was not in Mp3Tag::Genres --- path Returns the full path name of the MP3 file. --- filename Returns the filename without the directory part of the MP3 File. --- songname=(txt) --- artist=(txt) --- album=(txt) --- comment=(txt) Sets the song name, atist, album, or comment for the tag to ((|txt|)). ((|txt|)) should be a String object. --- tracknum=(num) Sets the track number for the tag. Only values in the range (0..255) are allowed. --- year=(num) Sets the year for the tag. Should be a four digit number. --- genre_id=(num) Sets the the genre id for the tag. Only values in the range (0..255) are allowed. --- genre=(txt) Sets the genre id for the tag to the index of ((|txt|)) in Mp3Tag::Genres. The genre id will be set to 255 if ((|txt|)) is not found in the list. =end def tracknum=(num) @tracknum = num.to_i end def year=(year) @year = year.to_i end def genre=(genre) @genre_id = Genres.index(genre) || 255 end def genre_id=(id) @genre_id = id.to_i end def genre Genres[@genre_id] || 'Unknown' end def filename File.basename(@path) end def readtag return if File.size(@path) < TagSize File.open(@path, 'r') { |f| f.seek(-TagSize, IO::SEEK_END) tag = f.read(3) if (tag == 'TAG') rest = f.read(TagSize-3) # Read id3v1.0 tag @songname, @artist, @album, @year_s, @comment, @genre_id = rest.unpack TAGFORMAT_READ @year = @year_s.to_i # Handle id3v1.1 tracknums if @comment[28] == 0 @tracknum = @comment[29] @comment.sub!(/\000+.$/, '')# remove nulls and tracknum from comment end end } end private :readtag =begin --- commit Saves the tag to the MP3 file. Will overwrite any existing tag. =end def commit File.open(@path, 'r+') { |f| f.seek(-TagSize, IO::SEEK_END) tag = f.read(3) if tag != 'TAG' # Append new tag f.seek(0, IO::SEEK_END) f.write('TAG') end f.write([@songname,@artist,@album, ("%04d" % @year), @comment, 0, @tracknum, @genre_id].pack TAGFORMAT_WRITE) } end end ruby-mp3tag-1.0.orig/mp3tag_test.rb0000775000000000000000000000741607330637306014154 0ustar #!/usr/bin/env ruby require './mp3tag' require 'runit/testcase' class Mp3TagTest < RUNIT::TestCase Mp3File = '/tmp/1.mp3' def setup system("cp '#{ARGV[0]}' #{Mp3File}") end def test_hastag Mp3Tag.new(Mp3File).commit assert(Mp3Tag.hastag?(Mp3File) == true) Mp3Tag.removetag(Mp3File) assert(Mp3Tag.hastag?(Mp3File) == false) end def test_addtag Mp3Tag.removetag(Mp3File) size_without_tag = File.stat(Mp3File).size Mp3Tag.new(Mp3File).commit size_with_tag = File.stat(Mp3File).size assert(size_with_tag - size_without_tag == 128) end def test_removetag Mp3Tag.new(Mp3File).commit size_with_tag = File.stat(Mp3File).size Mp3Tag.removetag(Mp3File) size_without_tag = File.stat(Mp3File).size assert(size_with_tag - size_without_tag == 128) end def test_integrity Mp3Tag.removetag(Mp3File) md5_before = `md5sum #{Mp3File}` Mp3Tag.new(Mp3File).commit Mp3Tag.removetag(Mp3File) md5_after = `md5sum #{Mp3File}` assert(md5_after == md5_before) Mp3Tag.new(Mp3File).commit md5_before = `md5sum #{Mp3File}` Mp3Tag.removetag(Mp3File) Mp3Tag.new(Mp3File).commit md5_after = `md5sum #{Mp3File}` assert(md5_after == md5_before) end def check_change tag = Mp3Tag.new(Mp3File) yield(tag) tag.commit tagnow = Mp3Tag.new(Mp3File) assert_equal tag.songname, tagnow.songname assert_equal tag.artist, tagnow.artist assert_equal tag.album, tagnow.album assert_equal tag.artist, tagnow.artist assert_equal tag.album, tagnow.album assert_equal tag.year, tagnow.year assert_equal tag.genre_id, tagnow.genre_id assert_equal tag.comment, tagnow.comment assert_equal tag.tracknum, tagnow.tracknum end def test_edit Mp3Tag.removetag(Mp3File) [ 'songname', 'artist', 'album', 'comment' ].each { |attr| check_change { |tag| tag.send("#{attr}=", "Test #{attr}") } } check_change { |tag| tag.year = 1923 } check_change { |tag| tag.year = "1923" } check_change { |tag| tag.genre_id = 128 } check_change { |tag| tag.genre_id = "128" } check_change { |tag| tag.tracknum = 23 } check_change { |tag| tag.tracknum = "23" } check_change { |tag| tag.genre_id = 38 } check_change { |tag| tag.genre_id = "38" } end def test_genres tag = Mp3Tag.new(Mp3File) tag.genre_id = 38 assert_equal(tag.genre, "Gospel") tag.genre = "Noise" assert_equal(tag.genre_id, 39) end def test_overfull longstring = "ANameWhichIsLongerThan30Characters" tag = Mp3Tag.new(Mp3File) tag.songname = longstring tag.artist = "Artist" tag.comment = longstring tag.tracknum = 88 tag.commit ntag = Mp3Tag.new(Mp3File) assert_equal(longstring[0,30], ntag.songname) assert_equal(tag.artist, ntag.artist) assert_equal(longstring[0,28], ntag.comment) assert_equal(tag.tracknum, ntag.tracknum) end def test_newtag Mp3Tag.removetag(Mp3File) tag = Mp3Tag.new(Mp3File) assert_equal(255, tag.genre_id) assert_equal(0, tag.year) assert_equal(0, tag.tracknum) assert_equal('', tag.songname) assert_equal('', tag.artist) assert_equal('', tag.album) assert_equal('', tag.comment) end def test_misc tag = Mp3Tag.new(Mp3File) tag.genre = "NoSuchGenre" assert_equal(255, tag.genre_id) assert_equal("Unknown", tag.genre) end end if $0 == __FILE__ if (ARGV[0].nil?) || (!FileTest.file? ARGV[0]) $stderr.puts "Must supply a name of an existing mp3 filename as argument. The file will be copied before modified - your original will never be changed." exit 1 end require 'runit/cui/testrunner' RUNIT::CUI::TestRunner.run(Mp3TagTest.suite) end ruby-mp3tag-1.0.orig/mp3tag.html0000664000000000000000000001223607330773527013455 0ustar mp3tag.rb

Synopsis

Read the tag from a file or create and Mp3Tag instance for saving tag to mp3 file later:

tag = Mp3Tag.new(filename)

Examining tags:

tag.songname
tag.artist
tag.album
tag.year
tag.comment
tag.tracknum
tag.genre_id
tag.genre

Setting tags:

tag.songname = "My Song"
tag.artist = "Me"
tag.album = "My Album"
tag.year = "2001"
tag.comment = "No Comment"
tag.tracknum = 3

tag.genre_id = 23
tag.genre = "Drum Solo"

genre_id's should exist in Mp3Tag::Genres. Elements in Mp3Tag::Genres can be assigned using tag.genre= and the id will be looked up automatically.

Saving tag to mp3:

tag.commit

Checking if a file has a tag:

Mp3Tag.hastag?(filename)

Class Methods

Mp3Tag.new(path)

Creates a new Mp3Tag object for the file give by path.

Mp3Tag.hastag?(filename)

Tests if filename has a ID3V1.0 or ID3V1.1 tag. Returns a boolean values giving the result of the test.

Mp3Tag.removetag(filename)

Removes an ID3v1 tag from the MP3 file filename

Instance Methods

songname
artist
album
comment

Return the song name, artist, album, or comment from the tag as a String object. Will return empty strings if file did not have a tag.

tracknum

Returns the track number from the tag. Will return 0 if the track number was not set in the tag when loaded, or if the file had no tag.

year

Returns the year from the tag. Will return 0 if the file had no tag.

genre_id

Return the id number of the genre from the tag. Will return 255 if the file had no tag.

genre

Returns the genre name. Will return "Unknown" if the file had no tag or the genre id was not in Mp3Tag::Genres

path

Returns the full path name of the MP3 file.

filename

Returns the filename without the directory part of the MP3 File.

songname=(txt)
artist=(txt)
album=(txt)
comment=(txt)

Sets the song name, atist, album, or comment for the tag to txt. txt should be a String object.

tracknum=(num)

Sets the track number for the tag. Only values in the range (0..255) are allowed.

year=(num)

Sets the year for the tag. Should be a four digit number.

genre_id=(num)

Sets the the genre id for the tag. Only values in the range (0..255) are allowed.

genre=(txt)

Sets the genre id for the tag to the index of txt in Mp3Tag::Genres. The genre id will be set to 255 if txt is not found in the list.

commit

Saves the tag to the MP3 file. Will overwrite any existing tag.