4 require 'yajl/json_gem'
8 $metafile = "tmp/songtitle"
11 file = "sets/#{$set}/tracklist.csv"
12 csv = CSV.read(File.open(file), encoding: 'UTF-8')
13 names = csv.shift.map(&:to_sym)
14 $tracklist = csv.map do |row|
15 Hash[*names.zip(row).flatten]
24 $tracklist.sort! {|a,b| a[:index].to_i <=> b[:index].to_i }
33 class App < Sinatra::Base
35 set :protection, :except => :frame_options
38 get '/tracklist.json' do
43 index = params["index"].to_i
44 if ( index < 0 || index > $tracklist.length )
46 return "No such track index."
49 title = ( index < 1 ) ? "-" : $tracklist.detect{|a| a[:index].to_i == index.to_i }[:title]
51 File.open($metafile, "a+") do |fp|
52 fp.flock(File::LOCK_EX)
57 fp.flock(File::LOCK_UN)
62 get '/js/handler.js' do
63 content_type 'text/javascript'
67 get '/css/meta.css' do
68 content_type 'text/css'
73 erb :index, :locals => { :mixtitle => $set, :tracklist => tracklist_json }