Sha256: 50d08edcb962ace9b540a47ce5d96068c40b75d3955d01ed82b3978bf186984a
Contents?: true
Size: 1.98 KB
Versions: 4
Compression:
Stored size: 1.98 KB
Contents
require 'digest/sha1' require 'progressbar' module Catori class Catalogador attr_accessor :fp,:dev,:disco,:db def initialize(disco,pretend, dev="/mnt/dvd") @dev=dev @disco=disco @pretend=pretend @db = Catori::Db::conectar end def deletePrevious @db.do("DELETE FROM cd where cd_id=?",@disco) end def llenarDisco(disco) if(@db.select_one("select COUNT(*) from cd WHERE cd_id=?",disco).to_s=="0") #puts "Agregar cd #{disco}" sql="INSERT INTO cd (cd_id) VALUES (?)" @db.execute(sql,disco) end end def rastrea llenarDisco(disco) unless @pretend oDir=Dir[@dev+"/**/*"]; pbar = ProgressBar.new("#{@disco}", oDir.size) unless @pretend oDir.each do |sFile| begin pbar.inc unless @pretend sPath=sFile.gsub(@dev,"") if oInfo=AudioInfo::infoFile(sFile) if oInfo.title.nil? puts "Error!"+sFile exit end if (!@pretend) Catori::Db.llenarArtista(oInfo) Catori::Db.llenarAlbum(oInfo) Catori::Db.llenarCancion(oInfo) llenarArchivo(oInfo) else p oInfo end else #puts sPath+" No es musica" end rescue StandardError => exp puts "Error running script: " + exp.message puts sFile p oInfo p exp.backtrace exit end # end begin end # end do pbar.finish unless @pretend end def llenarArchivo(oInfo) sPath=oInfo.sFile.gsub(@dev,'') sPathId=sPath.crearSha(); sAlbum=oInfo.album.crearSha sArtist=oInfo.artist.crearSha sSong=oInfo.title.crearSha if (@db.select_one("SELECT COUNT(*) from file WHERE cd_id=? AND file_id=?",@disco,sPathId).to_s=="0") sql="INSERT INTO file (artist_id,album_id,song_id,cd_id,file_id,file_name, sample_rate, bps, time, bits_per_sample, channels,size) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)" #puts "Archivo #{sPath}: "+oInfo.tracknumber.to_s+" - "+oInfo.title @db.execute(sql,sArtist,sAlbum,sSong,@disco,sPathId,sPath, oInfo.sample_rate, oInfo.bps,oInfo.time, oInfo.bits_per_sample,oInfo.channels, oInfo.size) end end end end
Version data entries
4 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
catori-0.2.6 | lib/catori/Catalogador.rb |
catori-0.2.5 | ./lib/catori/Catalogador.rb |
catori-0.2.5 | lib/catori/Catalogador.rb |
catori-0.2.6 | ./lib/catori/Catalogador.rb |