require 'catori' module Catori class Query def initialize(hQuery) @hQuery=hQuery @db = Catori::Db.conectar aCond=Array.new aCond.push("(artist_name like '%"+@hQuery['artist'].to_s+"%')") if !@hQuery['artist'].nil? aCond.push("(album_name like '%"+@hQuery['album'].to_s+"%')") if !@hQuery['album'].nil? aCond.push("(song_name like '%"+@hQuery['title'].to_s+"%')") if !@hQuery['title'].nil? aCond.push("(cd_id ='"+@hQuery['cd'].to_s+"')") if !@hQuery['cd'].nil? aCond.push("(file_name like '%"+@hQuery['file'].to_s+"%')") if !@hQuery['file'].nil? sCond=aCond.join(" AND ") @sQuery="SELECT * from edicion WHERE "+sCond+" ORDER by cd_id, artist_name, album_name, as_track,song_name,file_name" end def plain sSupport= AudioInfo::SUPPORT.join('|') out=[] @db.select_all(@sQuery) {|row| row['file_name']=~/\.(#{sSupport})$/i sType=$1 out << sprintf("CD:%s , Artist: %s,Album: %s, Song:[%02d] %s, Type: %s",row['cd_id'],row['artist_name'], row['album_name'],row['as_track'],row['song_name'],sType) } out.join("\n") end def xml require "rexml/document" doc=REXML::Document.new root=doc.add_element('catori') @db.select_all(@sQuery) {|row| file=root.add_element('file', {'cd'=>row['cd_id'], 'path'=>row['file_name'],'id'=>row['file_id']}) file.add_element('artist').text=row['artist_name'] file.add_element('album').text=row['album_name'] file.add_element('tracknumber').text=row['as_track'].to_s file.add_element('title').text=row['song_name'] file.add_element('year').text=row['album_year'].to_s } s="" doc.write(s,1,0) s end def gtk(widget,pix) ts=Gtk::TreeStore.new(String,String,String,String,Gdk::Pixbuf) widget.model=ts widget.headers_visible=true cd=nil artist=nil album=nil cdi=nil artisti=nil albumi=nil @db.select_all(@sQuery) {|row| if row['cd_id']!=cd cdi=ts.append(nil) artisti=nil albumi=nil artist=nil album=nil end cd=row['cd_id'] cdi[0]=cd cdi[4]=pix['cd'] artisti=ts.append(cdi) if row['artist_name']!=artist artist=row['artist_name'] artisti[0]=artist artisti[4]=pix['artist'] albumi=ts.append(artisti) if row['album_name']!=album album=row['album_name'] albumi[0]=album+"("+row['album_year'].to_s+")" albumi[4]=pix['album'] titlei=ts.append(albumi) titlei[1]=row['as_track'].to_s titlei[2]=row['song_name'] titlei[3]=row['file_name'] titlei[4]=pix['song'] # p row } end end end