File: gettrack.rb

package info (click to toggle)
libmusicbrainz-ruby 0.3.0-1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 488 kB
  • ctags: 157
  • sloc: ansic: 650; ruby: 286; makefile: 5
file content (47 lines) | stat: -rwxr-xr-x 1,123 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/ruby 

require 'musicbrainz'

# allocate a new MusicBrainz client
mb = MusicBrainz::Client.new
mb.depth = 2

# handle environment variables
mb.server = server if server = ENV['MB_SERVER']
mb.debug = true if ENV['MB_DEBUG']
mb.depth = depth.to_i if depth = ENV['MB_DEPTH']


unless ARGV.size > 1
  $stderr.puts 'Missing query strings.'
  exit -1
end

query = [ARGV[0], ARGV[1]]

# search for track
puts "Queries: #{query[0]}, #{query[1]}"
if mb.query(MusicBrainz::Query::QuickTrackInfoFromTrackId, *query)
  # extract artist name from track
  if artist = mb.result(MusicBrainz::Query::QuickGetArtistName)
    puts 'Artist: ' << artist
  end

  # extract album name from track
  if album = mb.result(MusicBrainz::Query::QuickGetAlbumName)
    puts 'Album: ' << album
  end

  # extract track name
  if track = mb.result(MusicBrainz::Query::QuickGetTrackName)
    puts 'Track: ' << track
  end

  # extract track name
  track_num = mb.result(MusicBrainz::Query::TrackGetTrackNum).to_i
  if track_num > 0 && track_num < 100
    puts 'TrackNum: ' << track_num.to_s
  end
else
  $stderr.puts 'Error: ' << mb.error
end