Skip to content

Commit

Permalink
Rebuild preview cheat fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie0 committed Mar 28, 2018
1 parent c4b2264 commit b1c38cf
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
9 changes: 5 additions & 4 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
require 'sinatra/xsendfile'
require 'yaml'

require './modules'
$: << '.'
require_relative 'modules'

Bundler.require
$config = YAML::load(File.read("config.yml"))
$genres = YAML::load(File.read("genres.yml"))
$config = YAML::load(File.read(File.join(File.dirname(__FILE__), "config.yml")))
$genres = YAML::load(File.read(File.join(File.dirname(__FILE__), "genres.yml")))
$env = {:slave => false}

require './database'
require_relative 'database'

Resque::Plugins::Status::Hash.expire_in = (60 * 60) * 24

Expand Down
6 changes: 4 additions & 2 deletions jobs/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,14 @@ def tag file, data



def generate_waveform file, length
def generate_waveform file, length, output = nil

output = "#{file}.dat" if output == nil

_debug "Generating a waveform of the input - hang on"
pps = (20000 / length).to_i
result = _sys('audiowaveform',
'-i', file, '-o', @wave_path = "#{file}.dat",
'-i', file, '-o', @wave_path = output,
'-b', '8', '--pixels-per-second', pps.to_s)


Expand Down
67 changes: 67 additions & 0 deletions scripts/rebuild_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'json'
require 'rest-client'
require 'base64'

$: << '..'
require_relative '../app'

#$config = YAML::load(File.read("../config.yml"))

class Processor < Nerve::Job::Process

include Object.const_get($config["export"]["mode"])

def initialize; end

def process_track track

# rebuild the track's preview and peaks
path = track.local_path
prev_path = $config["export"]["directory"] + "/" + path + ".ogg"
wave_path = $config["export"]["directory"] + "/" + path + ".dat"

# If we already have the preview, we probably
if File.exist?(prev_path) or !File.exist?(track)
_debug "Skipping for some reason"
return
end

exported_path = self.find_path(track)

_debug "Generating preview"

convert(exported_path, prev_path, "ogg", "-1")

raise "Conversion failed!" unless File.exists? prev_path

_debug "Generating waveform"

generate_waveform(prev_path, options["length"], wave_path)

raise "Generating waveform failed" unless File.exists?

_debug "Done!"

end

end


processor = Processor.new

tracks = Nerve::Model::Track.all
tracks.each { | t |

begin
processor.process_track t
rescue
begin
processor.process_track t
rescue
p "Track #{t.id} failed"
p $!
p $!.backtrace
end
end
sleep 0.2
}

0 comments on commit b1c38cf

Please sign in to comment.