#!/usr/bin/env ruby # encoding: UTF-8 def secure_require(name) begin require name rescue LoadError $stderr.print "#{File.basename(__FILE__)} requires #{name} gem to work\n Pleas install it with: gem install #{name}\n" exit end end require 'rubygems' secure_require 'highline' secure_require 'highline/import' secure_require 'parseconfig' secure_require 'nokogiri' secure_require 'iconv' require File.join(File.dirname(__FILE__),'..','lib','lib-ampache') require File.join(File.dirname(__FILE__),'..','lib','lib-classes') # XXX monkey patch for utf8 on ruby 1.9 if /^1\.9/ === RUBY_VERSION then class HighLine def wrap (text) text = text.force_encoding("UTF-8") wrapped = [ ] text.each_line do |line| while line =~ /([^\n]{#{@wrap_at + 1},})/ search = $1.dup replace = $1.dup if index = replace.rindex(" ", @wrap_at) replace[index, 1] = "\n" replace.sub!(/\n[ \t]+/, "\n") line.sub!(search, replace) else line[$~.begin(1) + @wrap_at, 0] = "\n" end end wrapped << line end return wrapped.join end end end # Ampache ruby parameters begin ar_config = ParseConfig.new(File.expand_path('~/.ruby-ampache')) rescue raise "\nPlease create a .ruby-ampache file on your home\n See http://github.com/ghedamat/ruby-ampache for infos\n" end # ruby-ampache highline version $terminal.wrap_at = 80 $terminal.page_at = 22 def print_albums(albums) choose do |menu| menu.prompt = "Choose an album or abort (1) " menu.choice(HighLine.new.color "ABORT", :red) albums.each do |a| menu.choice(a.name) { a.addToPlaylist(@pl)} end end end def print_artists(artists) if artists.empty? reset_token say("No results, retrying") artists = @ar.artists end choose do |menu| menu.prompt = "Choose an artists or abort (1)" menu.choice(HighLine.new.color "ABORT", :red) artists.each do |a| menu.choice(a.name) { print_albums(a.albums) } end end end # try to reset token if it's not valid def reset_token @ar.token = @ar.getAuthToken(@ar.user,@ar.psw) end def credits s = <