diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2f65a3b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "lib/vendor/musicbrainz"] + path = lib/vendor/musicbrainz + url = git@github.com:danbee/musicbrainz.git + branch = feature/find-release-by-discid diff --git a/Gemfile b/Gemfile index 5e7d2c4..4d54c53 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' -# Specify your gem's dependencies in ripper.gemspec +# Specify your gem's dependencies in rippr.gemspec gemspec diff --git a/README.md b/README.md index 1be03a9..33a7308 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Ripper +# Rippr TODO: Write a gem description @@ -6,7 +6,7 @@ TODO: Write a gem description Add this line to your application's Gemfile: - gem 'ripper' + gem 'rippr' And then execute: @@ -14,7 +14,7 @@ And then execute: Or install it yourself as: - $ gem install ripper + $ gem install rippr ## Usage diff --git a/bin/rippr b/bin/rippr new file mode 100755 index 0000000..512a54d --- /dev/null +++ b/bin/rippr @@ -0,0 +1,23 @@ +#!/usr/bin/env ruby + +require 'bundler' +Bundler.setup + +require 'ostruct' +require 'thor' +require 'musicbrainz' +require 'rippr' + +class Cli < Thor + desc "rip", "Rip the CD currently in the drive." + + def rip + disc = 'pmzhT6ZlFiwSRCdVwV0eqire5_Y-' + metadata = Rippr::MetaData.new(disc) + metadata.releases.each do |release| + puts release.title + end + end +end + +Cli.start(ARGV) diff --git a/lib/musicbrainz_discid.rb b/lib/musicbrainz_discid.rb new file mode 100644 index 0000000..c28b13c --- /dev/null +++ b/lib/musicbrainz_discid.rb @@ -0,0 +1,28 @@ +# Extend the MusicBrainz library to enable discid lookups. + +module MusicBrainz + module Bindings + module DiscidReleases + def parse(xml) + xml.xpath('./disc/release-list/release').map do |xml| + MusicBrainz::Bindings::Release.parse(xml) + end + end + + extend self + end + end +end + +module MusicBrainz + class Release + class << self + def find_by_discid(id) + client.load(:discid, { id: id }, { + binding: :discid_releases, + create_models: :release + }) + end + end + end +end diff --git a/lib/ripper.rb b/lib/ripper.rb deleted file mode 100644 index a302754..0000000 --- a/lib/ripper.rb +++ /dev/null @@ -1,5 +0,0 @@ -require "ripper/version" - -module Ripper - # Your code goes here... -end diff --git a/lib/rippr.rb b/lib/rippr.rb new file mode 100644 index 0000000..1ef48b8 --- /dev/null +++ b/lib/rippr.rb @@ -0,0 +1,27 @@ +require "musicbrainz_discid" +require "rippr/version" + +module Rippr + class MetaData + attr_accessor :releases + + def initialize(discid) + MusicBrainz.configure do |c| + c.app_name = "Rippr" + c.app_version = "0.1" + c.contact = "rippr@danbarber.me" + end + @discid = discid + end + + def releases + @releases ||= MusicBrainz::Release.find_by_discid(@discid) + end + end +end + +class DiscId + def self.read(dev) + OpenStruct.new(id: 'pmzhT6ZlFiwSRCdVwV0eqire5_Y-') # Stubbed for initial testing + end +end diff --git a/lib/ripper/version.rb b/lib/rippr/version.rb similarity index 63% rename from lib/ripper/version.rb rename to lib/rippr/version.rb index 6f4ee8c..32c07bf 100644 --- a/lib/ripper/version.rb +++ b/lib/rippr/version.rb @@ -1,3 +1,3 @@ -module Ripper +module Rippr VERSION = "0.0.1" end diff --git a/ripper.gemspec b/rippr.gemspec similarity index 86% rename from ripper.gemspec rename to rippr.gemspec index d6d9746..e1cdf16 100644 --- a/ripper.gemspec +++ b/rippr.gemspec @@ -1,11 +1,11 @@ # coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'ripper/version' +require 'rippr/version' Gem::Specification.new do |spec| - spec.name = "ripper" - spec.version = Ripper::VERSION + spec.name = "rippr" + spec.version = Rippr::VERSION spec.authors = ["Dan Barber"] spec.email = ["dan@new-bamboo.co.uk"] spec.description = %q{Rip your CD's on the command line. Uses MusicBrainz and CDParanoia.} @@ -22,5 +22,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rake" spec.add_dependency "discid" + spec.add_dependency "musicbrainz" spec.add_dependency "thor" end