Class: Catori::Catalogador
- Inherits:
-
Object
- Object
- Catori::Catalogador
- Defined in:
- lib/catori/Catalogador.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
-
#dev ⇒ Object
Returns the value of attribute dev.
-
#disco ⇒ Object
Returns the value of attribute disco.
-
#fp ⇒ Object
Returns the value of attribute fp.
Instance Method Summary collapse
- #deletePrevious ⇒ Object
-
#initialize(disco, pretend, dev = "/mnt/dvd") ⇒ Catalogador
constructor
A new instance of Catalogador.
- #llenarArchivo(oInfo) ⇒ Object
- #llenarDisco(disco) ⇒ Object
- #rastrea ⇒ Object
Constructor Details
#initialize(disco, pretend, dev = "/mnt/dvd") ⇒ Catalogador
Returns a new instance of Catalogador.
6 7 8 9 10 11 |
# File 'lib/catori/Catalogador.rb', line 6 def initialize(disco,pretend, dev="/mnt/dvd") @dev=dev @disco=disco @pretend=pretend @db = Catori::Db::conectar end |
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
5 6 7 |
# File 'lib/catori/Catalogador.rb', line 5 def db @db end |
#dev ⇒ Object
Returns the value of attribute dev.
5 6 7 |
# File 'lib/catori/Catalogador.rb', line 5 def dev @dev end |
#disco ⇒ Object
Returns the value of attribute disco.
5 6 7 |
# File 'lib/catori/Catalogador.rb', line 5 def disco @disco end |
#fp ⇒ Object
Returns the value of attribute fp.
5 6 7 |
# File 'lib/catori/Catalogador.rb', line 5 def fp @fp end |
Instance Method Details
#deletePrevious ⇒ Object
12 13 14 |
# File 'lib/catori/Catalogador.rb', line 12 def deletePrevious @db.do("DELETE FROM cd where cd_id=?",@disco) end |
#llenarArchivo(oInfo) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/catori/Catalogador.rb', line 57 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 |
#llenarDisco(disco) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/catori/Catalogador.rb', line 15 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 |
#rastrea ⇒ Object
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 48 49 50 51 52 53 54 55 56 |
# File 'lib/catori/Catalogador.rb', line 22 def rastrea llenarDisco(disco) unless @pretend oDir=Dir[@dev+"/**/*"]; = ProgressBar.new("#{@disco}", oDir.size) unless @pretend oDir.each do |sFile| begin .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. puts sFile p oInfo p exp.backtrace exit end # end begin end # end do .finish unless @pretend end |