Giter Site home page Giter Site logo

phw / ruby-discid Goto Github PK

View Code? Open in Web Editor NEW
3.0 4.0 0.0 240 KB

Ruby bindings for MusicBrainz libdiscid

License: GNU Lesser General Public License v3.0

Ruby 100.00%
ruby rubygems musicbrainz ruby-bindings cd audio library libdiscid discid ffi-bindings

ruby-discid's Introduction

Ruby bindings for MusicBrainz libdiscid

Gem Version Maintainability Test Coverage

About

ruby-discid provides Ruby bindings for the MusicBrainz DiscID library libdiscid. It allows calculating DiscIDs (MusicBrainz and freedb) for Audio CDs. Additionally the library can extract the MCN/UPC/EAN and the ISRCs from disc.

ruby-discid supports all features from libdiscid 0.6, but will also work with any earlier version. If a feature is unsupported in the libdiscid version used ruby-discid will just return a default value. The version required for a feature is documented in the API documentation.

Requirements

  • Ruby >= 2.0
  • RubyGems >= 1.3.6
  • Ruby-FFI >= 1.6.0
  • libdiscid >= 0.1.0

Installation

Before installing ruby-discid make sure you have libdiscid installed. See http://musicbrainz.org/doc/libdiscid for more information on how to do this. For Windows see also the notes below.

Installing with RubyGems

Installing ruby-discid is best done using RubyGems:

gem install discid

Installing from package repository

For some Linux distributions packages are available:

Install from source

You can also install from source. This requires RubyGems and Bundler installed. First make sure you have installed bundler:

gem install bundler

Then inside the ruby-discid source directory run:

bundle install
rake install

bundle install will install additional development dependencies (Rake, Yard etc.). rake install will build the discid gem and install it.

Windows installation notes

On Windows you will need discid.dll available in a place where Windows can find it, see Search Path Used by Windows to Locate a DLL. You can install the discid.dll system wide, but it is recommended to place it in the local working directory of your application.

Also the architecture (32 or 64 bit) of the DLL must match your Ruby version. As the official build of libdiscid contains only a 32 bit version of discid.dll it is recommended to use the 32 bit version of Ruby.

If you want or need to use 64 bit Ruby you will have to compile libdiscid yourself. Refer to the libdiscid install instructions for further details.

Usage

Read only the TOC

require 'discid'

# Specifying the device is optional. If omitted a platform
# specific default will be used.
device = "/dev/cdrom"
disc = DiscId.read(device)
puts disc.id

Read the TOC, MCN and ISRCs

require 'discid'

device = "/dev/cdrom"
disc = DiscId.read(device, :mcn, :isrc)

# Print information about the disc:
puts "DiscID      : #{disc.id}"
puts "FreeDB ID   : #{disc.freedb_id}"
puts "Total length: #{disc.seconds} seconds"
puts "MCN         : #{disc.mcn}"

# Print information about individual tracks:
disc.tracks do |track|
  puts "Track ##{track.number}"
  puts "  Length: %02d:%02d (%i sectors)" %
      [track.seconds / 60, track.seconds % 60, track.sectors]
  puts "  ISRC  : %s" % track.isrc
end

See the API documentation of {DiscId} or the files in the examples directory for more usage information.

Contribute

The source code for ruby-discid is available on GitHub.

Please report any issues on the issue tracker.

License

ruby-discid Copyright (c) 2007-2023 by Philipp Wolfer [email protected]

ruby-discid is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 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 Lesser General Public License for more details.

See LICENSE for details.

ruby-discid's People

Contributors

jonnyjd avatar phw avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ruby-discid's Issues

Example in "Read the TOC, MCN and ISRCs" does not work

I get this error:

/home/ossi/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/discid-1.4.0/lib/discid/disc.rb:205:in `new': tried to create Proc object without a block (ArgumentError)
        from /home/ossi/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/discid-1.4.0/lib/discid/disc.rb:205:in `tracks'
        from ./discid.rb:15:in `<main>'

Using disc.tracks.each do |track| would fix this issue.

Provide libdiscid version

discid_get_version_string is already attached in the Lib module, but should not be considered public.

Probably set this to a constant DiscId::LIBDISCID_VERSION

discid.rb: rounding & Installation

In discid.rb you round the result in sectors_to_seconds, which can return the wrong value when constructing a TOC string for such as XMCD (freeDB) files, see:
http://ftp.freedb.org/pub/freedb/latest/DBFORMAT

"# Disc length: N"

where the number of seconds in the CD's play length is substituted for "N".
The number of seconds should be computed by dividing the total number of
1/75th second frames in the CD by 75 and truncating any remainder. This number
may not be rounded.

As for the documentation, it may be worth adding a note for Windows users that the MusicBrainz discid.dll in the download is to be copied to the bin directory of the Ruby installation. Also, I gave no thought to having had installed the 64-bit version of Ruby and was thus left scratching my head when discid.dll couldn't be loaded, so it's probably worth mentioning that a 32-bit install is required.

Finally, thanks for both working on this and acting so promptly :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.