feature/share-libs
rb 36 lines 1011 Bytes
Raw
1 # The SplitFire naming, i.e; camel-cased style, is only being used for branding.
2 # Inside the code, we refer this tool as Splitfire.
3
4 # This meant tobe just a demo job.
5 class DownloadFileJob < ApplicationJob
6 # TODO: Set priority based on account type.
7 queue_as :default
8
9 def perform(audio_file_id, public_url)
10 require 'open-uri'
11
12 # Change to spleeter working directory.
13 if Rails.env.production?
14 Dir.chdir('/home/deploy/apps/spleeter/')
15 else
16 Dir.chdir('../spleeter/')
17 end
18
19 download = URI.open(public_url)
20 filepath = "#{download.base_uri.to_s.split('/')[-1]}"
21 IO.copy_stream(download, filepath)
22
23 file = File.open(filepath)
24
25 audio_file = AudioFile.find_by(id: audio_file_id)
26 audio_file.source_file.attach(io: file, filename: filepath)
27
28 return unless audio_file.save
29
30 audio_file.audio_file_splitfire_status.update_attribute(:processing_progress, 10)
31
32 SplitfireDemoJob.perform_later(audio_file.id)
33
34 system("rm -rf #{filepath}")
35 end
36 end