Class: Audiobank::Client::LocalFile
- Inherits:
-
Object
- Object
- Audiobank::Client::LocalFile
- Defined in:
- lib/audiobank/client/local_file.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#uploaded_file ⇒ Object
readonly
Returns the value of attribute uploaded_file.
Instance Method Summary collapse
- #basename ⇒ Object
- #convert ⇒ Object
- #default_title ⇒ Object
- #document_id ⇒ Object
- #extension ⇒ Object
- #file_uuid ⇒ Object
- #filename_without_extension ⇒ Object
- #flac_file ⇒ Object
- #import(account) ⇒ Object
- #import_options ⇒ Object
-
#initialize(filename) ⇒ LocalFile
constructor
A new instance of LocalFile.
- #report_file ⇒ Object
Constructor Details
#initialize(filename) ⇒ LocalFile
Returns a new instance of LocalFile.
9 10 11 |
# File 'lib/audiobank/client/local_file.rb', line 9 def initialize(filename) @filename = @uploaded_file = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/audiobank/client/local_file.rb', line 7 def filename @filename end |
#uploaded_file ⇒ Object (readonly)
Returns the value of attribute uploaded_file.
7 8 9 |
# File 'lib/audiobank/client/local_file.rb', line 7 def uploaded_file @uploaded_file end |
Instance Method Details
#basename ⇒ Object
17 18 19 |
# File 'lib/audiobank/client/local_file.rb', line 17 def basename @basename ||= File.basename(filename) end |
#convert ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/audiobank/client/local_file.rb', line 45 def convert if extension == "wav" # unless FileUtils.uptodate? flac_file, filename Audiobank::Client.logger.info "Create flac version" system "flac -f -o #{flac_file} '#{filename}'" or raise "Can't convert file to wav" # end Audiobank::Client.logger.info "Use flac version" @uploaded_file = flac_file end end |
#default_title ⇒ Object
35 36 37 |
# File 'lib/audiobank/client/local_file.rb', line 35 def default_title File.basename(filename, File.extname(filename)) end |
#document_id ⇒ Object
25 26 27 28 29 |
# File 'lib/audiobank/client/local_file.rb', line 25 def document_id if basename =~ /^([0-9]+)-/ $1.to_i end end |
#extension ⇒ Object
21 22 23 |
# File 'lib/audiobank/client/local_file.rb', line 21 def extension @extension ||= File.extname(filename)[1..-1] end |
#file_uuid ⇒ Object
31 32 33 |
# File 'lib/audiobank/client/local_file.rb', line 31 def file_uuid document_id or Digest::SHA256.hexdigest(filename) end |
#filename_without_extension ⇒ Object
13 14 15 |
# File 'lib/audiobank/client/local_file.rb', line 13 def filename_without_extension @filename_without_extension ||= filename.gsub(/\.#{extension}$/, "") end |
#flac_file ⇒ Object
39 40 41 42 43 |
# File 'lib/audiobank/client/local_file.rb', line 39 def flac_file # "#{filename_without_extension}.flac" # (@flac_tempfile ||= Tempfile.new(['audiobank', '.flac'])).path "/tmp/#{file_uuid}.flac" end |
#import(account) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/audiobank/client/local_file.rb', line 60 def import(account) unless FileUtils.uptodate? uploaded_file, [report_file] Audiobank::Client.logger.info "File already imported" return end convert imported = false if document_id Audiobank::Client.logger.debug "Found document id : #{document_id}" document = account.document(document_id) if document imported = document.import uploaded_file, else raise "Document #{document_id} not found" end else imported = account.documents.import uploaded_file, { :title => default_title }, end if imported Audiobank::Client.logger.debug "Create report #{report_file}" system "touch '#{report_file}'" # FileUtils.touch report_file else Audiobank::Client.logger.info "Failed to import #{filename}" end end |
#import_options ⇒ Object
56 57 58 |
# File 'lib/audiobank/client/local_file.rb', line 56 def { :resume => true, :debug => true, :retries => 10, :progress => true } end |
#report_file ⇒ Object
90 91 92 |
# File 'lib/audiobank/client/local_file.rb', line 90 def report_file "#{filename}.audiobank" end |