ruby-ogginfo-0.6.12/0000755000004100000410000000000012222371263014237 5ustar www-datawww-dataruby-ogginfo-0.6.12/test/0000755000004100000410000000000012222371263015216 5ustar www-datawww-dataruby-ogginfo-0.6.12/test/test_ruby-spxinfo.rb0000644000004100000410000001155612222371263021257 0ustar www-datawww-data#!/usr/bin/ruby -w $:.unshift("lib/") require "test/unit" require "ogginfo" require "fileutils" require "tempfile" VALID_SPX = < "mytitle", "test" => "myartist" } OggInfo.open(GEN_FILE) do |spx| spx.tag.clear tag.each { |k,v| spx.tag[k] = v } end OggInfo.open(GEN_FILE) do |spx| assert_equal tag, spx.tag end end def generate_spx unless test(?f, "test.spx") system("dd if=/dev/urandom bs=1024 count=3000 | speexenc --rate 44100 --stereo --author spxinfotest --title SpxInfoTest --comment test=\"hello\303\251\" - test.spx") or flunk("cannot generate \"test.spx\", tests cannot be fully performed") end end end ruby-ogginfo-0.6.12/test/test_ruby-ogginfo.rb0000644000004100000410000002136312222371263021216 0ustar www-datawww-data#!/usr/bin/ruby -w # encoding: utf-8 $:.unshift("lib/") require "test/unit" require "ogginfo" require "fileutils" require "tempfile" VALID_OGG = < "this is a éé utf8 string", "artist" => "and è another one à"} tag_test("tag_writing", tag) end def test_tag_writing data = "a"*256 tag_test("tag_writing", "title" => data, "artist" => data ) end def test_big_tags data = "a"*60000 tag_test("big_tags", "title" => data, "artist" => data ) end def test_should_not_fail_when_input_is_truncated valid_ogg = generate_ogg ogg_length = nil OggInfo.open(valid_ogg.path) do |ogg| ogg_length = ogg.length end tf = generate_truncated_ogg OggInfo.open(tf.path) do |truncated_ogg| assert ogg_length != truncated_ogg.length end reader = Ogg::Reader.new(open(tf.path, "r")) last_page = nil reader.each_pages do |page| last_page = page end assert_not_equal Ogg.compute_checksum(last_page.pack), last_page.checksum end def test_checksum tf = generate_truncated_ogg reader = Ogg::Reader.new(open(tf.path)) assert_raises(Ogg::StreamError) do reader.each_pages(:checksum => true) do |page| page end end end protected def generate_ogg generated_ogg_file_path = File.join(File.dirname(__FILE__), "test.ogg") unless test(?f, generated_ogg_file_path) system("dd if=/dev/urandom bs=1024 count=3000 | oggenc -q0 --raw -o #{generated_ogg_file_path} -") or flunk("cannot generate \"#{generated_ogg_file_path}\", tests cannot be fully performed") end tf = Tempfile.new("ruby-ogginfo") tf.close FileUtils.cp(generated_ogg_file_path, tf.path) tf end def generate_truncated_ogg valid_ogg = generate_ogg tf = Tempfile.new("ruby-ogginfo") data = File.read(valid_ogg.path, File.size(valid_ogg.path) - 10000) tf.write(data) tf.close tf end def tag_test(test_name, tag) tf = generate_ogg OggInfo.open(tf.path) do |ogg| tag.each { |k,v| ogg.tag[k] = v } end OggInfo.open(tf.path) do |ogg| assert_equal tag, ogg.tag end system("cp #{tf.path} /tmp/test_#{RUBY_VERSION}_#{test_name}.ogg") test_length assert_nothing_raised do io = open(tf.path) reader = Ogg::Reader.new(io) reader.each_pages do |page| page end end end end ruby-ogginfo-0.6.12/Rakefile0000644000004100000410000000073412222371263015710 0ustar www-datawww-data# -*- ruby -*- require 'hoe' Hoe.plugin :yard Hoe.plugin :git Hoe.plugin :rcov Hoe.plugin :gemspec Hoe.spec('ruby-ogginfo') do developer('Guillaume Pierronnet','guillaume.pierronnet@gmail.com') developer('Grant Gardner','grant@lastweekend.com.au') #summary = 'ruby-ogginfo is a pure-ruby library that gives low level informations on ogg files' remote_rdoc_dir = '' rdoc_locations << "rubyforge.org:/var/www/gforge-projects/ruby-ogginfo/" end # vim: syntax=Ruby ruby-ogginfo-0.6.12/History.txt0000644000004100000410000000300512222371263016437 0ustar www-datawww-data=== 0.6.12 / 2013-09-05 * avoid potential race condition on temp file creation * remove warnings on unused variables === 0.6.11 / 2012-07-16 * more robust compute_length() method (works on broken OGGs) === 0.6.10 / 2012-05-18 * doesn't show binary dump in raise messages anymore === 0.6.9 / 2012-05-18 * more robust Ogg pages parsing. (doesn't fail on truncated Ogg files) === 0.6.8 / 2012-02-28 * removed :encoding parameter on OggInfo#new * utf8 strings are correctly written now in ruby > 1.9 === 0.6.7 / 2012-02-27 * fixes for ruby 1.9 (again) === 0.6.6 / 2011-12-23 * fixes for ruby 1.9 (thanks to gwolf) === 0.6.5 / 2011-04-07 * internal reorganization, leading to more robust and faster library === 0.6 / 2011-03-01 * pure ruby tag writing (thanks to Grant Gardner) === 0.5 / 2011-01-13 * speex support (thanks to Grant Gardner) === 0.4.2 / 2010-03-13 * bugfix on frame parsing === 0.4.1 / 2010-03-13 * bugfix on file parsing === 0.4 / 2009-12-04 * new ogg frame reading implementation * better tag reading (thanks to Sven) * now assume utf-8 by default to decode tags === 0.3.2 / 2009-06-22 * added setup.rb for tarball distribution * added license on top of lib/ogginfo.rb === 0.3.1 / 2008-03-16 * bug fixed #18852 "OggInfo#close(): close @ic only if not nil" * bug fixed on encoding handling === 0.3 / 2008-03-15 * write support through "vorbiscomment" binary * correct encoding handling === 0.2 / 2005-07-11 * tag["key"] is accessible with tag.key === 0.1 / 2004-06-20 * first public version ruby-ogginfo-0.6.12/.gemtest0000644000004100000410000000000012222371263015676 0ustar www-datawww-dataruby-ogginfo-0.6.12/checksums.yaml.gz0000444000004100000410000000041512222371263017525 0ustar www-datawww-data)(Re;R@D=^`-`f033|L<TA𺛾n|\u==_7oUD^Z('bUQܪۉڴ()ڌc SRf?\QV8%RR0rϕ׶JFSDɻS*S*PjD,V͆2OvVmCm.\b4+uxM%9 IMgc؍'@fux6n7zJruby-ogginfo-0.6.12/metadata.yml0000644000004100000410000000521712222371263016547 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: ruby-ogginfo version: !ruby/object:Gem::Version version: 0.6.12 platform: ruby authors: - Guillaume Pierronnet - Grant Gardner autorequire: bindir: bin cert_chain: [] date: 2013-09-05 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rdoc requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '3.10' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '3.10' - !ruby/object:Gem::Dependency name: rcov requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '0.9' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '0.9' - !ruby/object:Gem::Dependency name: hoe requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '3.5' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '3.5' description: |- ruby-ogginfo gives you access to low level information on ogg files (bitrate, length, samplerate, encoder, etc... ), as well as tag. It is written in pure ruby. email: - guillaume.pierronnet@gmail.com - grant@lastweekend.com.au executables: [] extensions: [] extra_rdoc_files: - History.txt - Manifest.txt - README.txt files: - History.txt - Manifest.txt - README.txt - Rakefile - lib/ogg/codecs/comments.rb - lib/ogg/codecs/speex.rb - lib/ogg/codecs/vorbis.rb - lib/ogg/page.rb - lib/ogg/reader.rb - lib/ogg/writer.rb - lib/ogg.rb - lib/ogginfo.rb - setup.rb - test/test_ruby-ogginfo.rb - test/test_ruby-spxinfo.rb - .gemtest homepage: http://ruby-ogginfo.rubyforge.org/ licenses: [] metadata: {} post_install_message: rdoc_options: - --main - README.txt require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: ruby-ogginfo rubygems_version: 2.0.6 signing_key: specification_version: 4 summary: ruby-ogginfo gives you access to low level information on ogg files (bitrate, length, samplerate, encoder, etc.. test_files: - test/test_ruby-ogginfo.rb - test/test_ruby-spxinfo.rb ruby-ogginfo-0.6.12/setup.rb0000644000004100000410000010713612222371263015734 0ustar www-datawww-data# # setup.rb # # Copyright (c) 2000-2006 Minero Aoki # # This program is free software. # You can distribute/modify this program under the terms of # the GNU LGPL, Lesser General Public License version 2.1. # unless Enumerable.method_defined?(:map) # Ruby 1.4.6 module Enumerable alias map collect end end unless File.respond_to?(:read) # Ruby 1.6 def File.read(fname) open(fname) {|f| return f.read } end end unless Errno.const_defined?(:ENOTEMPTY) # Windows? module Errno class ENOTEMPTY # We do not raise this exception, implementation is not needed. end end end def File.binread(fname) open(fname, 'rb') {|f| return f.read } end # for corrupted Windows' stat(2) def File.dir?(path) File.directory?((path[-1,1] == '/') ? path : path + '/') end class ConfigTable include Enumerable def initialize(rbconfig) @rbconfig = rbconfig @items = [] @table = {} # options @install_prefix = nil @config_opt = nil @verbose = true @no_harm = false end attr_accessor :install_prefix attr_accessor :config_opt attr_writer :verbose def verbose? @verbose end attr_writer :no_harm def no_harm? @no_harm end def [](key) lookup(key).resolve(self) end def []=(key, val) lookup(key).set val end def names @items.map {|i| i.name } end def each(&block) @items.each(&block) end def key?(name) @table.key?(name) end def lookup(name) @table[name] or setup_rb_error "no such config item: #{name}" end def add(item) @items.push item @table[item.name] = item end def remove(name) item = lookup(name) @items.delete_if {|i| i.name == name } @table.delete_if {|name, i| i.name == name } item end def load_script(path, inst = nil) if File.file?(path) MetaConfigEnvironment.new(self, inst).instance_eval File.read(path), path end end def savefile '.config' end def load_savefile begin File.foreach(savefile()) do |line| k, v = *line.split(/=/, 2) self[k] = v.strip end rescue Errno::ENOENT setup_rb_error $!.message + "\n#{File.basename($0)} config first" end end def save @items.each {|i| i.value } File.open(savefile(), 'w') {|f| @items.each do |i| f.printf "%s=%s\n", i.name, i.value if i.value? and i.value end } end def load_standard_entries standard_entries(@rbconfig).each do |ent| add ent end end def standard_entries(rbconfig) c = rbconfig rubypath = File.join(c['bindir'], c['ruby_install_name'] + c['EXEEXT']) major = c['MAJOR'].to_i minor = c['MINOR'].to_i teeny = c['TEENY'].to_i version = "#{major}.#{minor}" # ruby ver. >= 1.4.4? newpath_p = ((major >= 2) or ((major == 1) and ((minor >= 5) or ((minor == 4) and (teeny >= 4))))) if c['rubylibdir'] # V > 1.6.3 libruby = "#{c['prefix']}/lib/ruby" librubyver = c['rubylibdir'] librubyverarch = c['archdir'] siteruby = c['sitedir'] siterubyver = c['sitelibdir'] siterubyverarch = c['sitearchdir'] elsif newpath_p # 1.4.4 <= V <= 1.6.3 libruby = "#{c['prefix']}/lib/ruby" librubyver = "#{c['prefix']}/lib/ruby/#{version}" librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}" siteruby = c['sitedir'] siterubyver = "$siteruby/#{version}" siterubyverarch = "$siterubyver/#{c['arch']}" else # V < 1.4.4 libruby = "#{c['prefix']}/lib/ruby" librubyver = "#{c['prefix']}/lib/ruby/#{version}" librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}" siteruby = "#{c['prefix']}/lib/ruby/#{version}/site_ruby" siterubyver = siteruby siterubyverarch = "$siterubyver/#{c['arch']}" end parameterize = lambda {|path| path.sub(/\A#{Regexp.quote(c['prefix'])}/, '$prefix') } if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg } makeprog = arg.sub(/'/, '').split(/=/, 2)[1] else makeprog = 'make' end [ ExecItem.new('installdirs', 'std/site/home', 'std: install under libruby; site: install under site_ruby; home: install under $HOME')\ {|val, table| case val when 'std' table['rbdir'] = '$librubyver' table['sodir'] = '$librubyverarch' when 'site' table['rbdir'] = '$siterubyver' table['sodir'] = '$siterubyverarch' when 'home' setup_rb_error '$HOME was not set' unless ENV['HOME'] table['prefix'] = ENV['HOME'] table['rbdir'] = '$libdir/ruby' table['sodir'] = '$libdir/ruby' end }, PathItem.new('prefix', 'path', c['prefix'], 'path prefix of target environment'), PathItem.new('bindir', 'path', parameterize.call(c['bindir']), 'the directory for commands'), PathItem.new('libdir', 'path', parameterize.call(c['libdir']), 'the directory for libraries'), PathItem.new('datadir', 'path', parameterize.call(c['datadir']), 'the directory for shared data'), PathItem.new('mandir', 'path', parameterize.call(c['mandir']), 'the directory for man pages'), PathItem.new('sysconfdir', 'path', parameterize.call(c['sysconfdir']), 'the directory for system configuration files'), PathItem.new('localstatedir', 'path', parameterize.call(c['localstatedir']), 'the directory for local state data'), PathItem.new('libruby', 'path', libruby, 'the directory for ruby libraries'), PathItem.new('librubyver', 'path', librubyver, 'the directory for standard ruby libraries'), PathItem.new('librubyverarch', 'path', librubyverarch, 'the directory for standard ruby extensions'), PathItem.new('siteruby', 'path', siteruby, 'the directory for version-independent aux ruby libraries'), PathItem.new('siterubyver', 'path', siterubyver, 'the directory for aux ruby libraries'), PathItem.new('siterubyverarch', 'path', siterubyverarch, 'the directory for aux ruby binaries'), PathItem.new('rbdir', 'path', '$siterubyver', 'the directory for ruby scripts'), PathItem.new('sodir', 'path', '$siterubyverarch', 'the directory for ruby extentions'), PathItem.new('rubypath', 'path', rubypath, 'the path to set to #! line'), ProgramItem.new('rubyprog', 'name', rubypath, 'the ruby program using for installation'), ProgramItem.new('makeprog', 'name', makeprog, 'the make program to compile ruby extentions'), SelectItem.new('shebang', 'all/ruby/never', 'ruby', 'shebang line (#!) editing mode'), BoolItem.new('without-ext', 'yes/no', 'no', 'does not compile/install ruby extentions') ] end private :standard_entries def load_multipackage_entries multipackage_entries().each do |ent| add ent end end def multipackage_entries [ PackageSelectionItem.new('with', 'name,name...', '', 'ALL', 'package names that you want to install'), PackageSelectionItem.new('without', 'name,name...', '', 'NONE', 'package names that you do not want to install') ] end private :multipackage_entries ALIASES = { 'std-ruby' => 'librubyver', 'stdruby' => 'librubyver', 'rubylibdir' => 'librubyver', 'archdir' => 'librubyverarch', 'site-ruby-common' => 'siteruby', # For backward compatibility 'site-ruby' => 'siterubyver', # For backward compatibility 'bin-dir' => 'bindir', 'bin-dir' => 'bindir', 'rb-dir' => 'rbdir', 'so-dir' => 'sodir', 'data-dir' => 'datadir', 'ruby-path' => 'rubypath', 'ruby-prog' => 'rubyprog', 'ruby' => 'rubyprog', 'make-prog' => 'makeprog', 'make' => 'makeprog' } def fixup ALIASES.each do |ali, name| @table[ali] = @table[name] end end def options_re /\A--(#{@table.keys.join('|')})(?:=(.*))?\z/ end def parse_opt(opt) m = options_re().match(opt) or setup_rb_error "config: unknown option #{opt}" m.to_a[1,2] end def dllext @rbconfig['DLEXT'] end def value_config?(name) lookup(name).value? end class Item def initialize(name, template, default, desc) @name = name.freeze @template = template @value = default @default = default @description = desc end attr_reader :name attr_reader :description attr_accessor :default alias help_default default def help_opt "--#{@name}=#{@template}" end def value? true end def value @value end def resolve(table) @value.gsub(%r<\$([^/]+)>) { table[$1] } end def set(val) @value = check(val) end private def check(val) setup_rb_error "config: --#{name} requires argument" unless val val end end class BoolItem < Item def config_type 'bool' end def help_opt "--#{@name}" end private def check(val) return 'yes' unless val case val when /\Ay(es)?\z/i, /\At(rue)?\z/i then 'yes' when /\An(o)?\z/i, /\Af(alse)\z/i then 'no' else setup_rb_error "config: --#{@name} accepts only yes/no for argument" end end end class PathItem < Item def config_type 'path' end private def check(path) setup_rb_error "config: --#{@name} requires argument" unless path path[0,1] == '$' ? path : File.expand_path(path) end end class ProgramItem < Item def config_type 'program' end end class SelectItem < Item def initialize(name, selection, default, desc) super @ok = selection.split('/') end def config_type 'select' end private def check(val) unless @ok.include?(val.strip) setup_rb_error "config: use --#{@name}=#{@template} (#{val})" end val.strip end end class ExecItem < Item def initialize(name, selection, desc, &block) super name, selection, nil, desc @ok = selection.split('/') @action = block end def config_type 'exec' end def value? false end def resolve(table) setup_rb_error "$#{name()} wrongly used as option value" end undef set def evaluate(val, table) v = val.strip.downcase unless @ok.include?(v) setup_rb_error "invalid option --#{@name}=#{val} (use #{@template})" end @action.call v, table end end class PackageSelectionItem < Item def initialize(name, template, default, help_default, desc) super name, template, default, desc @help_default = help_default end attr_reader :help_default def config_type 'package' end private def check(val) unless File.dir?("packages/#{val}") setup_rb_error "config: no such package: #{val}" end val end end class MetaConfigEnvironment def initialize(config, installer) @config = config @installer = installer end def config_names @config.names end def config?(name) @config.key?(name) end def bool_config?(name) @config.lookup(name).config_type == 'bool' end def path_config?(name) @config.lookup(name).config_type == 'path' end def value_config?(name) @config.lookup(name).config_type != 'exec' end def add_config(item) @config.add item end def add_bool_config(name, default, desc) @config.add BoolItem.new(name, 'yes/no', default ? 'yes' : 'no', desc) end def add_path_config(name, default, desc) @config.add PathItem.new(name, 'path', default, desc) end def set_config_default(name, default) @config.lookup(name).default = default end def remove_config(name) @config.remove(name) end # For only multipackage def packages raise '[setup.rb fatal] multi-package metaconfig API packages() called for single-package; contact application package vendor' unless @installer @installer.packages end # For only multipackage def declare_packages(list) raise '[setup.rb fatal] multi-package metaconfig API declare_packages() called for single-package; contact application package vendor' unless @installer @installer.packages = list end end end # class ConfigTable # This module requires: #verbose?, #no_harm? module FileOperations def mkdir_p(dirname, prefix = nil) dirname = prefix + File.expand_path(dirname) if prefix $stderr.puts "mkdir -p #{dirname}" if verbose? return if no_harm? # Does not check '/', it's too abnormal. dirs = File.expand_path(dirname).split(%r<(?=/)>) if /\A[a-z]:\z/i =~ dirs[0] disk = dirs.shift dirs[0] = disk + dirs[0] end dirs.each_index do |idx| path = dirs[0..idx].join('') Dir.mkdir path unless File.dir?(path) end end def rm_f(path) $stderr.puts "rm -f #{path}" if verbose? return if no_harm? force_remove_file path end def rm_rf(path) $stderr.puts "rm -rf #{path}" if verbose? return if no_harm? remove_tree path end def remove_tree(path) if File.symlink?(path) remove_file path elsif File.dir?(path) remove_tree0 path else force_remove_file path end end def remove_tree0(path) Dir.foreach(path) do |ent| next if ent == '.' next if ent == '..' entpath = "#{path}/#{ent}" if File.symlink?(entpath) remove_file entpath elsif File.dir?(entpath) remove_tree0 entpath else force_remove_file entpath end end begin Dir.rmdir path rescue Errno::ENOTEMPTY # directory may not be empty end end def move_file(src, dest) force_remove_file dest begin File.rename src, dest rescue File.open(dest, 'wb') {|f| f.write File.binread(src) } File.chmod File.stat(src).mode, dest File.unlink src end end def force_remove_file(path) begin remove_file path rescue end end def remove_file(path) File.chmod 0777, path File.unlink path end def install(from, dest, mode, prefix = nil) $stderr.puts "install #{from} #{dest}" if verbose? return if no_harm? realdest = prefix ? prefix + File.expand_path(dest) : dest realdest = File.join(realdest, File.basename(from)) if File.dir?(realdest) str = File.binread(from) if diff?(str, realdest) verbose_off { rm_f realdest if File.exist?(realdest) } File.open(realdest, 'wb') {|f| f.write str } File.chmod mode, realdest File.open("#{objdir_root()}/InstalledFiles", 'a') {|f| if prefix f.puts realdest.sub(prefix, '') else f.puts realdest end } end end def diff?(new_content, path) return true unless File.exist?(path) new_content != File.binread(path) end def command(*args) $stderr.puts args.join(' ') if verbose? system(*args) or raise RuntimeError, "system(#{args.map{|a| a.inspect }.join(' ')}) failed" end def ruby(*args) command config('rubyprog'), *args end def make(task = nil) command(*[config('makeprog'), task].compact) end def extdir?(dir) File.exist?("#{dir}/MANIFEST") or File.exist?("#{dir}/extconf.rb") end def files_of(dir) Dir.open(dir) {|d| return d.select {|ent| File.file?("#{dir}/#{ent}") } } end DIR_REJECT = %w( . .. CVS SCCS RCS CVS.adm .svn ) def directories_of(dir) Dir.open(dir) {|d| return d.select {|ent| File.dir?("#{dir}/#{ent}") } - DIR_REJECT } end end # This module requires: #srcdir_root, #objdir_root, #relpath module HookScriptAPI def get_config(key) @config[key] end alias config get_config # obsolete: use metaconfig to change configuration def set_config(key, val) @config[key] = val end # # srcdir/objdir (works only in the package directory) # def curr_srcdir "#{srcdir_root()}/#{relpath()}" end def curr_objdir "#{objdir_root()}/#{relpath()}" end def srcfile(path) "#{curr_srcdir()}/#{path}" end def srcexist?(path) File.exist?(srcfile(path)) end def srcdirectory?(path) File.dir?(srcfile(path)) end def srcfile?(path) File.file?(srcfile(path)) end def srcentries(path = '.') Dir.open("#{curr_srcdir()}/#{path}") {|d| return d.to_a - %w(. ..) } end def srcfiles(path = '.') srcentries(path).select {|fname| File.file?(File.join(curr_srcdir(), path, fname)) } end def srcdirectories(path = '.') srcentries(path).select {|fname| File.dir?(File.join(curr_srcdir(), path, fname)) } end end class ToplevelInstaller Version = '3.4.1' Copyright = 'Copyright (c) 2000-2006 Minero Aoki' TASKS = [ [ 'all', 'do config, setup, then install' ], [ 'config', 'saves your configurations' ], [ 'show', 'shows current configuration' ], [ 'setup', 'compiles ruby extentions and others' ], [ 'install', 'installs files' ], [ 'test', 'run all tests in test/' ], [ 'clean', "does `make clean' for each extention" ], [ 'distclean',"does `make distclean' for each extention" ] ] def ToplevelInstaller.invoke config = ConfigTable.new(load_rbconfig()) config.load_standard_entries config.load_multipackage_entries if multipackage? config.fixup klass = (multipackage?() ? ToplevelInstallerMulti : ToplevelInstaller) klass.new(File.dirname($0), config).invoke end def ToplevelInstaller.multipackage? File.dir?(File.dirname($0) + '/packages') end def ToplevelInstaller.load_rbconfig if arg = ARGV.detect {|arg| /\A--rbconfig=/ =~ arg } ARGV.delete(arg) load File.expand_path(arg.split(/=/, 2)[1]) $".push 'rbconfig.rb' else require 'rbconfig' end ::Config::CONFIG end def initialize(ardir_root, config) @ardir = File.expand_path(ardir_root) @config = config # cache @valid_task_re = nil end def config(key) @config[key] end def inspect "#<#{self.class} #{__id__()}>" end def invoke run_metaconfigs case task = parsearg_global() when nil, 'all' parsearg_config init_installers exec_config exec_setup exec_install else case task when 'config', 'test' ; when 'clean', 'distclean' @config.load_savefile if File.exist?(@config.savefile) else @config.load_savefile end __send__ "parsearg_#{task}" init_installers __send__ "exec_#{task}" end end def run_metaconfigs @config.load_script "#{@ardir}/metaconfig" end def init_installers @installer = Installer.new(@config, @ardir, File.expand_path('.')) end # # Hook Script API bases # def srcdir_root @ardir end def objdir_root '.' end def relpath '.' end # # Option Parsing # def parsearg_global while arg = ARGV.shift case arg when /\A\w+\z/ setup_rb_error "invalid task: #{arg}" unless valid_task?(arg) return arg when '-q', '--quiet' @config.verbose = false when '--verbose' @config.verbose = true when '--help' print_usage $stdout exit 0 when '--version' puts "#{File.basename($0)} version #{Version}" exit 0 when '--copyright' puts Copyright exit 0 else setup_rb_error "unknown global option '#{arg}'" end end nil end def valid_task?(t) valid_task_re() =~ t end def valid_task_re @valid_task_re ||= /\A(?:#{TASKS.map {|task,desc| task }.join('|')})\z/ end def parsearg_no_options unless ARGV.empty? task = caller(0).first.slice(%r<`parsearg_(\w+)'>, 1) setup_rb_error "#{task}: unknown options: #{ARGV.join(' ')}" end end alias parsearg_show parsearg_no_options alias parsearg_setup parsearg_no_options alias parsearg_test parsearg_no_options alias parsearg_clean parsearg_no_options alias parsearg_distclean parsearg_no_options def parsearg_config evalopt = [] set = [] @config.config_opt = [] while i = ARGV.shift if /\A--?\z/ =~ i @config.config_opt = ARGV.dup break end name, value = *@config.parse_opt(i) if @config.value_config?(name) @config[name] = value else evalopt.push [name, value] end set.push name end evalopt.each do |name, value| @config.lookup(name).evaluate value, @config end # Check if configuration is valid set.each do |n| @config[n] if @config.value_config?(n) end end def parsearg_install @config.no_harm = false @config.install_prefix = '' while a = ARGV.shift case a when '--no-harm' @config.no_harm = true when /\A--prefix=/ path = a.split(/=/, 2)[1] path = File.expand_path(path) unless path[0,1] == '/' @config.install_prefix = path else setup_rb_error "install: unknown option #{a}" end end end def print_usage(out) out.puts 'Typical Installation Procedure:' out.puts " $ ruby #{File.basename $0} config" out.puts " $ ruby #{File.basename $0} setup" out.puts " # ruby #{File.basename $0} install (may require root privilege)" out.puts out.puts 'Detailed Usage:' out.puts " ruby #{File.basename $0} " out.puts " ruby #{File.basename $0} [] []" fmt = " %-24s %s\n" out.puts out.puts 'Global options:' out.printf fmt, '-q,--quiet', 'suppress message outputs' out.printf fmt, ' --verbose', 'output messages verbosely' out.printf fmt, ' --help', 'print this message' out.printf fmt, ' --version', 'print version and quit' out.printf fmt, ' --copyright', 'print copyright and quit' out.puts out.puts 'Tasks:' TASKS.each do |name, desc| out.printf fmt, name, desc end fmt = " %-24s %s [%s]\n" out.puts out.puts 'Options for CONFIG or ALL:' @config.each do |item| out.printf fmt, item.help_opt, item.description, item.help_default end out.printf fmt, '--rbconfig=path', 'rbconfig.rb to load',"running ruby's" out.puts out.puts 'Options for INSTALL:' out.printf fmt, '--no-harm', 'only display what to do if given', 'off' out.printf fmt, '--prefix=path', 'install path prefix', '' out.puts end # # Task Handlers # def exec_config @installer.exec_config @config.save # must be final end def exec_setup @installer.exec_setup end def exec_install @installer.exec_install end def exec_test @installer.exec_test end def exec_show @config.each do |i| printf "%-20s %s\n", i.name, i.value if i.value? end end def exec_clean @installer.exec_clean end def exec_distclean @installer.exec_distclean end end # class ToplevelInstaller class ToplevelInstallerMulti < ToplevelInstaller include FileOperations def initialize(ardir_root, config) super @packages = directories_of("#{@ardir}/packages") raise 'no package exists' if @packages.empty? @root_installer = Installer.new(@config, @ardir, File.expand_path('.')) end def run_metaconfigs @config.load_script "#{@ardir}/metaconfig", self @packages.each do |name| @config.load_script "#{@ardir}/packages/#{name}/metaconfig" end end attr_reader :packages def packages=(list) raise 'package list is empty' if list.empty? list.each do |name| raise "directory packages/#{name} does not exist"\ unless File.dir?("#{@ardir}/packages/#{name}") end @packages = list end def init_installers @installers = {} @packages.each do |pack| @installers[pack] = Installer.new(@config, "#{@ardir}/packages/#{pack}", "packages/#{pack}") end with = extract_selection(config('with')) without = extract_selection(config('without')) @selected = @installers.keys.select {|name| (with.empty? or with.include?(name)) \ and not without.include?(name) } end def extract_selection(list) a = list.split(/,/) a.each do |name| setup_rb_error "no such package: #{name}" unless @installers.key?(name) end a end def print_usage(f) super f.puts 'Inluded packages:' f.puts ' ' + @packages.sort.join(' ') f.puts end # # Task Handlers # def exec_config run_hook 'pre-config' each_selected_installers {|inst| inst.exec_config } run_hook 'post-config' @config.save # must be final end def exec_setup run_hook 'pre-setup' each_selected_installers {|inst| inst.exec_setup } run_hook 'post-setup' end def exec_install run_hook 'pre-install' each_selected_installers {|inst| inst.exec_install } run_hook 'post-install' end def exec_test run_hook 'pre-test' each_selected_installers {|inst| inst.exec_test } run_hook 'post-test' end def exec_clean rm_f @config.savefile run_hook 'pre-clean' each_selected_installers {|inst| inst.exec_clean } run_hook 'post-clean' end def exec_distclean rm_f @config.savefile run_hook 'pre-distclean' each_selected_installers {|inst| inst.exec_distclean } run_hook 'post-distclean' end # # lib # def each_selected_installers Dir.mkdir 'packages' unless File.dir?('packages') @selected.each do |pack| $stderr.puts "Processing the package `#{pack}' ..." if verbose? Dir.mkdir "packages/#{pack}" unless File.dir?("packages/#{pack}") Dir.chdir "packages/#{pack}" yield @installers[pack] Dir.chdir '../..' end end def run_hook(id) @root_installer.run_hook id end # module FileOperations requires this def verbose? @config.verbose? end # module FileOperations requires this def no_harm? @config.no_harm? end end # class ToplevelInstallerMulti class Installer FILETYPES = %w( bin lib ext data conf man ) include FileOperations include HookScriptAPI def initialize(config, srcroot, objroot) @config = config @srcdir = File.expand_path(srcroot) @objdir = File.expand_path(objroot) @currdir = '.' end def inspect "#<#{self.class} #{File.basename(@srcdir)}>" end def noop(rel) end # # Hook Script API base methods # def srcdir_root @srcdir end def objdir_root @objdir end def relpath @currdir end # # Config Access # # module FileOperations requires this def verbose? @config.verbose? end # module FileOperations requires this def no_harm? @config.no_harm? end def verbose_off begin save, @config.verbose = @config.verbose?, false yield ensure @config.verbose = save end end # # TASK config # def exec_config exec_task_traverse 'config' end alias config_dir_bin noop alias config_dir_lib noop def config_dir_ext(rel) extconf if extdir?(curr_srcdir()) end alias config_dir_data noop alias config_dir_conf noop alias config_dir_man noop def extconf ruby "#{curr_srcdir()}/extconf.rb", *@config.config_opt end # # TASK setup # def exec_setup exec_task_traverse 'setup' end def setup_dir_bin(rel) files_of(curr_srcdir()).each do |fname| update_shebang_line "#{curr_srcdir()}/#{fname}" end end alias setup_dir_lib noop def setup_dir_ext(rel) make if extdir?(curr_srcdir()) end alias setup_dir_data noop alias setup_dir_conf noop alias setup_dir_man noop def update_shebang_line(path) return if no_harm? return if config('shebang') == 'never' old = Shebang.load(path) if old $stderr.puts "warning: #{path}: Shebang line includes too many args. It is not portable and your program may not work." if old.args.size > 1 new = new_shebang(old) return if new.to_s == old.to_s else return unless config('shebang') == 'all' new = Shebang.new(config('rubypath')) end $stderr.puts "updating shebang: #{File.basename(path)}" if verbose? open_atomic_writer(path) {|output| File.open(path, 'rb') {|f| f.gets if old # discard output.puts new.to_s output.print f.read } } end def new_shebang(old) if /\Aruby/ =~ File.basename(old.cmd) Shebang.new(config('rubypath'), old.args) elsif File.basename(old.cmd) == 'env' and old.args.first == 'ruby' Shebang.new(config('rubypath'), old.args[1..-1]) else return old unless config('shebang') == 'all' Shebang.new(config('rubypath')) end end def open_atomic_writer(path, &block) tmpfile = File.basename(path) + '.tmp' begin File.open(tmpfile, 'wb', &block) File.rename tmpfile, File.basename(path) ensure File.unlink tmpfile if File.exist?(tmpfile) end end class Shebang def Shebang.load(path) line = nil File.open(path) {|f| line = f.gets } return nil unless /\A#!/ =~ line parse(line) end def Shebang.parse(line) cmd, *args = *line.strip.sub(/\A\#!/, '').split(' ') new(cmd, args) end def initialize(cmd, args = []) @cmd = cmd @args = args end attr_reader :cmd attr_reader :args def to_s "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}") end end # # TASK install # def exec_install rm_f 'InstalledFiles' exec_task_traverse 'install' end def install_dir_bin(rel) install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755, strip_ext? end def strip_ext? /mswin|mingw/ !~ RUBY_PLATFORM end def install_dir_lib(rel) install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644 end def install_dir_ext(rel) return unless extdir?(curr_srcdir()) install_files rubyextentions('.'), "#{config('sodir')}/#{File.dirname(rel)}", 0555 end def install_dir_data(rel) install_files targetfiles(), "#{config('datadir')}/#{rel}", 0644 end def install_dir_conf(rel) # FIXME: should not remove current config files # (rename previous file to .old/.org) install_files targetfiles(), "#{config('sysconfdir')}/#{rel}", 0644 end def install_dir_man(rel) install_files targetfiles(), "#{config('mandir')}/#{rel}", 0644 end def install_files(list, dest, mode, stripext = false) mkdir_p dest, @config.install_prefix list.each do |fname| if stripext install fname, "#{dest}/#{File.basename(fname, '.*')}", mode, @config.install_prefix else install fname, dest, mode, @config.install_prefix end end end def libfiles glob_reject(%w(*.y *.output), targetfiles()) end def rubyextentions(dir) ents = glob_select("*.#{@config.dllext}", targetfiles()) if ents.empty? setup_rb_error "no ruby extention exists: 'ruby #{$0} setup' first" end ents end def targetfiles mapdir(existfiles() - hookfiles()) end def mapdir(ents) ents.map {|ent| if File.exist?(ent) then ent # objdir else "#{curr_srcdir()}/#{ent}" # srcdir end } end # picked up many entries from cvs-1.11.1/src/ignore.c JUNK_FILES = %w( core RCSLOG tags TAGS .make.state .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb *~ *.old *.bak *.BAK *.orig *.rej _$* *$ *.org *.in .* ) def existfiles glob_reject(JUNK_FILES, (files_of(curr_srcdir()) | files_of('.'))) end def hookfiles %w( pre-%s post-%s pre-%s.rb post-%s.rb ).map {|fmt| %w( config setup install clean distclean ).map {|t| sprintf(fmt, t) } }.flatten end def glob_select(pat, ents) re = globs2re([pat]) ents.select {|ent| re =~ ent } end def glob_reject(pats, ents) re = globs2re(pats) ents.reject {|ent| re =~ ent } end GLOB2REGEX = { '.' => '\.', '$' => '\$', '#' => '\#', '*' => '.*' } def globs2re(pats) /\A(?:#{ pats.map {|pat| pat.gsub(/[\.\$\#\*]/) {|ch| GLOB2REGEX[ch] } }.join('|') })\z/ end # # TASK test # TESTDIR = 'test' def exec_test unless File.directory?('test') $stderr.puts 'no test in this package' if verbose? return end $stderr.puts 'Running tests...' if verbose? begin require 'test/unit' rescue LoadError setup_rb_error 'test/unit cannot loaded. You need Ruby 1.8 or later to invoke this task.' end runner = Test::Unit::AutoRunner.new(true) runner.to_run << TESTDIR runner.run end # # TASK clean # def exec_clean exec_task_traverse 'clean' rm_f @config.savefile rm_f 'InstalledFiles' end alias clean_dir_bin noop alias clean_dir_lib noop alias clean_dir_data noop alias clean_dir_conf noop alias clean_dir_man noop def clean_dir_ext(rel) return unless extdir?(curr_srcdir()) make 'clean' if File.file?('Makefile') end # # TASK distclean # def exec_distclean exec_task_traverse 'distclean' rm_f @config.savefile rm_f 'InstalledFiles' end alias distclean_dir_bin noop alias distclean_dir_lib noop def distclean_dir_ext(rel) return unless extdir?(curr_srcdir()) make 'distclean' if File.file?('Makefile') end alias distclean_dir_data noop alias distclean_dir_conf noop alias distclean_dir_man noop # # Traversing # def exec_task_traverse(task) run_hook "pre-#{task}" FILETYPES.each do |type| if type == 'ext' and config('without-ext') == 'yes' $stderr.puts 'skipping ext/* by user option' if verbose? next end traverse task, type, "#{task}_dir_#{type}" end run_hook "post-#{task}" end def traverse(task, rel, mid) dive_into(rel) { run_hook "pre-#{task}" __send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '') directories_of(curr_srcdir()).each do |d| traverse task, "#{rel}/#{d}", mid end run_hook "post-#{task}" } end def dive_into(rel) return unless File.dir?("#{@srcdir}/#{rel}") dir = File.basename(rel) Dir.mkdir dir unless File.dir?(dir) prevdir = Dir.pwd Dir.chdir dir $stderr.puts '---> ' + rel if verbose? @currdir = rel yield Dir.chdir prevdir $stderr.puts '<--- ' + rel if verbose? @currdir = File.dirname(rel) end def run_hook(id) path = [ "#{curr_srcdir()}/#{id}", "#{curr_srcdir()}/#{id}.rb" ].detect {|cand| File.file?(cand) } return unless path $stderr.puts "invoking hook script #{path}" if verbose? begin instance_eval File.read(path), path, 1 rescue raise if $DEBUG setup_rb_error "hook #{path} failed:\n" + $!.message end end end # class Installer class SetupError < StandardError; end def setup_rb_error(msg) raise SetupError, msg end if $0 == __FILE__ begin ToplevelInstaller.invoke rescue SetupError raise if $DEBUG $stderr.puts $!.message $stderr.puts "Try 'ruby #{$0} --help' for detailed usage." exit 1 end end ruby-ogginfo-0.6.12/Manifest.txt0000644000004100000410000000040412222371263016544 0ustar www-datawww-dataHistory.txt Manifest.txt README.txt Rakefile lib/ogg/codecs/comments.rb lib/ogg/codecs/speex.rb lib/ogg/codecs/vorbis.rb lib/ogg/page.rb lib/ogg/reader.rb lib/ogg/writer.rb lib/ogg.rb lib/ogginfo.rb setup.rb test/test_ruby-ogginfo.rb test/test_ruby-spxinfo.rb ruby-ogginfo-0.6.12/README.txt0000644000004100000410000000105612222371263015737 0ustar www-datawww-data= ruby-ogginfo http://ruby-ogginfo.rubyforge.org/ https://github.com/moumar/ruby-ogginfo == DESCRIPTION: ruby-ogginfo gives you access to low level information on ogg files (bitrate, length, samplerate, encoder, etc... ), as well as tag. It is written in pure ruby. == FEATURES/PROBLEMS * writing tags is now pure ruby == SYNOPSIS: require "ogginfo" OggInfo.open("toto.ogg") do |ogg| puts ogg.bitrate puts ogg.artist puts ogg end == INSTALL: sudo gem install ruby-ogginfo == TODO: * writing tags in pure-ruby == LICENSE: Ruby ruby-ogginfo-0.6.12/lib/0000755000004100000410000000000012222371263015005 5ustar www-datawww-dataruby-ogginfo-0.6.12/lib/ogg.rb0000644000004100000410000001147312222371263016114 0ustar www-datawww-data#Ogg framing # see http://www.xiph.org/ogg/vorbis/docs.html for documentation on vorbis format # http://www.xiph.org/vorbis/doc/framing.html %w{page reader writer codecs/comments codecs/vorbis codecs/speex}.each do |file| require File.join(File.dirname(__FILE__), "ogg", file) end module Ogg # Raised on any kind of Ogg parsing/writing error class StreamError < StandardError; end CHECKSUM_TABLE = [ 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9, 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005, 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61, 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd, 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9, 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75, 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011, 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd, 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039, 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5, 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81, 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d, 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49, 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95, 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1, 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d, 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae, 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072, 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16, 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca, 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde, 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02, 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066, 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba, 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e, 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692, 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6, 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a, 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e, 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2, 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686, 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a, 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637, 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb, 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f, 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53, 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47, 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b, 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff, 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623, 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7, 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b, 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f, 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3, 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7, 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b, 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f, 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3, 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640, 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c, 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8, 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24, 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30, 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec, 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088, 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654, 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0, 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c, 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18, 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4, 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0, 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c, 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668, 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4 ] class << self def detect_codec(input) if input.kind_of?(Page) first_page = input else first_page = Page.read(input) input.rewind end codecs = Ogg::Codecs.constants.map { |module_name| Ogg::Codecs.class_eval(module_name.to_s) }.select { |c| c.is_a?(Class) } codec = codecs.detect { |c| c.match?(first_page.segments.first) } unless codec raise(StreamError,"unknown codec") end return codec end # Calculate the checksum from the page (or the pre packed data) # If data it supplied it will be updated to record the checksum value def compute_checksum(data_) data = data_.dup data[22..25] = [0].pack("V") crc = 0 data.each_byte do |byte| crc = (crc << 8)^CHECKSUM_TABLE[((crc >> 24)&0xff) ^ byte] crc = crc & 0xffffffff end crc end end end if __FILE__ == $0 require 'pp' infile = ARGV[0] outfile = ARGV[1] vendor = "" tags = { } File.open(infile,"r") do |input| info = Ogg.read_headers(input) pp info vendor = info[:tag_vendor] end File.open(infile,"r") do | input | File.open(outfile,"w") do | output | Ogg.replace_tags(input,output,tags,vendor) end end File.open(outfile,"r") do | output | pp Ogg.read_headers(output) end end ruby-ogginfo-0.6.12/lib/ogginfo.rb0000644000004100000410000001162512222371263016767 0ustar www-datawww-data# see http://www.xiph.org/ogg/vorbis/docs.html for documentation on vorbis format # http://www.xiph.org/vorbis/doc/v-comment.html # http://www.xiph.org/vorbis/doc/framing.html # # License: ruby require 'forwardable' require "tempfile" require File.join(File.dirname(__FILE__), 'ogg.rb') class Hash ### lets you specify hash["key"] as hash.key ### this came from CodingInRuby on RubyGarden ### http://www.rubygarden.org/ruby?CodingInRuby def method_missing(meth,*args) if /=$/=~(meth=meth.id2name) then self[meth[0...-1]] = (args.length<2 ? args[0] : args) else self[meth] end end end # Raised on any kind of error related to ruby-ogginfo class OggInfoError < StandardError ; end class OggInfo VERSION = "0.6.12" extend Forwardable include Ogg attr_reader :channels, :samplerate, :nominal_bitrate # +tag+ is a hash containing the vorbis tag like "Artist", "Title", and the like attr_reader :tag # create new instance of OggInfo # use of charset is deprecated! please use utf-8 encoded strings and leave +charset+ to nil") def initialize(filename, charset = nil) if charset warn("use of charset is deprecated! please use utf-8 encoded tags") end @filename = filename @length = nil @bitrate = nil File.open(@filename, 'rb') do |file| begin info = read_headers(file) @samplerate = info[:samplerate] @nominal_bitrate = info[:nominal_bitrate] @channels = info[:channels] @tag = info[:tag] # filesize is used to calculate bitrate # but we don't want to include the headers @filesize = file.stat.size - file.pos rescue Ogg::StreamError => se raise(OggInfoError, se.message, se.backtrace) end end @original_tag = @tag.dup end # The length in seconds of the track # since this requires reading the whole file we only get it # if called def length unless @length File.open(@filename) do |file| @length = compute_length(file) end end return @length end # Calculated bit rate, also lazily loaded # since we depend on the length def bitrate @bitrate ||= (@filesize * 8).to_f / length() end # "block version" of ::new() def self.open(*args) m = self.new(*args) ret = nil if block_given? begin ret = yield(m) ensure m.close end else ret = m end ret end # commits any tags to file def close if tag != @original_tag Tempfile.open(["ruby-ogginfo", ".ogg"]) do |tempfile| tempfile.close tempfile = File.new(tempfile.path, "wb") File.open(@filename, "rb") do | input | replace_tags(input, tempfile, tag) end tempfile.close FileUtils.cp(tempfile.path, @filename) end end end # check the presence of a tag def hastag? !tag.empty? end def to_s "channels #{channels} samplerate #{samplerate} bitrate #{nominal_bitrate} #{tag.inspect}" end private def read_headers(input) reader = Reader.new(input) codec = Ogg.detect_codec(input) codec.decode_headers(reader) end # For both Vorbis and Speex, the granule_pos is the number of samples # strictly this should be a codec function. def compute_length(input) reader = Reader.new(input) last_page = nil begin reader.each_pages(:skip_body => true, :skip_checksum => true) do |page| if page.granule_pos last_page = page end end rescue Ogg::StreamError end if last_page return last_page.granule_pos.to_f / @samplerate else return 0 end end # Pipe input to output transforming tags along the way # input/output must be open streams reading for reading/writing def replace_tags(input, output, new_tags, vendor = "ruby-ogginfo") # use the same serial number... first_page = Page.read(input) codec = Ogg.detect_codec(first_page) bitstream_serial_no = first_page.bitstream_serial_no reader = Reader.new(input) writer = Writer.new(bitstream_serial_no, output) # Write the first page as is (including presumably the b_o_s header) writer.write_page(first_page) upcased_tags = new_tags.inject({}) do |memo, (k, v)| memo[k.upcase] = v memo end # The codecs we know about put comments etc in following pages # as suggested by the spec written_pages_count = codec.replace_tags(reader, writer, upcased_tags, vendor) if written_pages_count > 1 # Write the rest of the pages. We have to do page at a time # because our tag replacement may have changed the number of # pages and thus every subsequent page needs to have its # sequence_no updated. reader.each_pages(:skip_checksum => true) do |page| writer.write_page(page) end else FileUtils.copy_stream(reader.input, writer.output) end end end ruby-ogginfo-0.6.12/lib/ogg/0000755000004100000410000000000012222371263015561 5ustar www-datawww-dataruby-ogginfo-0.6.12/lib/ogg/writer.rb0000644000004100000410000000254112222371263017424 0ustar www-datawww-datarequire 'stringio' module Ogg # Writes pages or packets to an output io class Writer attr_reader :output def initialize(bitstream_serial_no, output) @output = output @page_sequence = 0 @bitstream_serial_no = bitstream_serial_no end # Writes a page to the output, the serial number and page sequence are # are overwritten to be appropriate for this stream. def write_page(page) page.sequence_no = @page_sequence @output << page.pack @page_sequence += 1 end def write_packets(granule_pos, *packets) written_pages_count = 1 page = Page.new(@bitstream_serial_no, granule_pos) packets.each do |packet| io = StringIO.new(packet) while !io.eof? do page.segments << io.read(255) if (page.segments.length == 255) page.granule_pos = -1 write_page(page) page = Page.new(@bitstream_serial_no, granule_pos) written_pages_count += 1 end end #If our packet was an exact multiple of 255 we need to put in an empty closing segment if (page.segments.length == 0 || page.segments.last.length == 255) page.segments << "" end end #we always need to flush the final page. write_page(page) written_pages_count end end end ruby-ogginfo-0.6.12/lib/ogg/codecs/0000755000004100000410000000000012222371263017021 5ustar www-datawww-dataruby-ogginfo-0.6.12/lib/ogg/codecs/comments.rb0000644000004100000410000000316612222371263021201 0ustar www-datawww-datarequire "stringio" module Ogg::Codecs # See http://www.xiph.org/vorbis/doc/v-comment.html # Methods to pack/unpack vorbis comment packets # intended to be included into Codec classes module VorbisComments # unpack a packet, skipping the preamble # returns a 2 element array being a Hash of tag/value pairs and the vendor string def unpack_comments(packet, preamble="") pio = StringIO.new(packet) pio.read(preamble.length) vendor_length = pio.read(4).unpack("V").first vendor = pio.read(vendor_length) tag = {} tag_size = pio.read(4).unpack("V")[0] tag_size.times do |i| size = pio.read(4).unpack("V")[0] comment = pio.read(size) unless RUBY_VERSION[0..2] == "1.8" comment.force_encoding("UTF-8") end key, val = comment.split(/=/, 2) tag[key.downcase] = val end #framing bit = pio.read(1).unpack("C")[0] [ tag, vendor ] end # Pack tag Hash and vendor string into an ogg packet. def pack_comments(tag, vendor, preamble="") packet_data = "" packet_data << preamble packet_data << [ vendor.length ].pack("V") packet_data << vendor packet_data << [tag.size].pack("V") tag.each do |k,v| tag_data = "#{ k }=#{ v }" packet_data << [ binary_size(tag_data) ].pack("V") packet_data << tag_data end packet_data << "\001" packet_data end def binary_size(s) if RUBY_VERSION[0..2] == "1.8" s.size else s.bytes.to_a.size end end end end ruby-ogginfo-0.6.12/lib/ogg/codecs/speex.rb0000644000004100000410000000216512222371263020476 0ustar www-datawww-datamodule Ogg::Codecs class Speex class << self include VorbisComments def match?(packet) /^Speex/ =~ packet end def decode_headers(reader) init_packet, tag_packet = reader.read_packets(2) info = extract_info(init_packet) info[:tag], info[:tag_vendor] = unpack_comments(tag_packet) return info end def replace_tags(reader, writer, new_tags, vendor) _ = reader.read_packets(1) # tag_packet writer.write_packets(0, pack_comments(new_tags, vendor)) end def extract_info(info_packet) _, #speex_string, _, #speex_version, _, #speex_version_id, _, #header_size, samplerate, _, #mode, _, #mode_bitstream_version, channels, nominal_bitrate, #framesize, vbr _, _ = info_packet.unpack("A8A20VVVVVVVVV") #not sure how to make sense of the bitrate info,picard doesn't show it either... return { :channels => channels, :samplerate => samplerate, :nominal_bitrate => nominal_bitrate } end end end end ruby-ogginfo-0.6.12/lib/ogg/codecs/vorbis.rb0000644000004100000410000000303712222371263020655 0ustar www-datawww-datamodule Ogg::Codecs class Vorbis class << self include VorbisComments # return true/false based on whether the header packet belongs to us def match?(header_packet) /^\001vorbis.*/ =~ header_packet end #consume header and tag pages, return array of two hashes, info and tags def decode_headers(reader) init_pkt, tag_pkt, _ = reader.read_packets(3) # init_pkt, tag_pkt, setup_pkt info = extract_info(init_pkt) info[:tag], info[:tag_vendor] = unpack_comments(tag_pkt, "\003vorbis") info end # consume pages with old tags/setup packets and rewrite newtags,setup packets # return the number of pages written def replace_tags(reader, writer, new_tags, vendor) _, setup_pkt = reader.read_packets(2) # tag_pkt, setup_pkt writer.write_packets(0, pack_comments(new_tags, vendor, "\003vorbis"), setup_pkt) end def extract_info(packet) _, #vorbis_string, _, # vorbis_version, channels, samplerate, upper_bitrate, nominal_bitrate, lower_bitrate = packet.unpack("a7VCV4") if nominal_bitrate == 0 if (upper_bitrate == 2**32 - 1) || (lower_bitrate == 2**32 - 1) nominal_bitrate = 0 else nominal_bitrate = ( upper_bitrate + lower_bitrate) / 2 end end return { :channels => channels, :samplerate => samplerate, :nominal_bitrate => nominal_bitrate } end end end end ruby-ogginfo-0.6.12/lib/ogg/page.rb0000644000004100000410000000414212222371263017023 0ustar www-datawww-datamodule Ogg class Page attr_accessor :granule_pos, :bitstream_serial_no, :sequence_no, :segments, :header attr_reader :checksum # read an ogg frame from the +file+ # file must be positioned at end of frame after this loop # options - :skip_body = seek to end of frame rather than reading in the data def self.read(io, options = {}) return nil if io.eof? chunk = io.read(27) capture_pattern, _, # version header, granule_pos, bitstream_serial_no, sequence_no, @checksum, segments = chunk.unpack("a4CCQVVVC") #a4CCQNNNC if capture_pattern != "OggS" raise(StreamError, "bad magic number") end page = Page.new(bitstream_serial_no, granule_pos) page.header = header page.sequence_no = sequence_no unless io.eof? segment_sizes = io.read(segments).unpack("C*") if options[:skip_body] body_size = segment_sizes.inject(0) { |sum, i| sum + i } io.seek(body_size, IO::SEEK_CUR) else segment_sizes.each do |size| break if io.eof? page.segments << io.read(size) end if options[:checksum] if @checksum != Ogg.compute_checksum(page.pack) raise(StreamError, "bad checksum: expected #{ @checksum }, got #{ page.checksum }") end end end end page end def initialize(bitstream_serial_no = 0, granule_pos = 0) @bitstream_serial_no = bitstream_serial_no @granule_pos = granule_pos @segments = [] @header = 0 end def pack packed = [ "OggS", 0, #version @header, @granule_pos, @bitstream_serial_no, @sequence_no, 0, #checksum @segments.length ].pack("a4CCQVVVC") packed << @segments.collect { |segment| segment.length }.pack("C*") packed << @segments.join crc = Ogg.compute_checksum(packed) packed[22..25] = [crc].pack("V") packed end end end ruby-ogginfo-0.6.12/lib/ogg/reader.rb0000644000004100000410000000153612222371263017355 0ustar www-datawww-datamodule Ogg #Reads pages and packets from an ogg stream class Reader attr_reader :input def initialize(input) @input = input end def each_pages(options = {}) until @input.eof? yield Page.read(@input, options) end end def read_packets(max_packets) result = [] partial_packet = "" each_pages do |page| partial_packet = page.segments.inject(partial_packet) do |packet,segment| packet << segment if segment.length < 255 #end of packet result << packet return result if result.length == max_packets "" else packet end end end # We expect packets to reach page boundaries, consider raising exception if partial_packet here. result end end end