Skip to content

Instantly share code, notes, and snippets.

@telent
Created December 6, 2010 22:36
Show Gist options
  • Save telent/731115 to your computer and use it in GitHub Desktop.
Save telent/731115 to your computer and use it in GitHub Desktop.
# put this file in the same directory as your media, and run it
# then run e.g. mplayer -playlist http://mediaserver:5656/flac/Various-Sasha\*/*
# it wants a directory name or a shell wildcard.
# No attempt has been made to make this secure. Do not use it on an internet-facing host, or god will kill your kittens
require 'sinatra'
set :port,5656
Root=File.dirname(__FILE__)
def playlist(request,files)
content_type "audio/x-mpegurl"
# hope the filenames each start with a zero-padded track number or that the
# user wanted to listen in alphabetical order ...
files.sort.map do |f|
"#{request.scheme}://#{request.host}:#{request.port}/bits#{f[Root.length..-1]}"
end.join "\n"
end
get '/bits/*' do |fn|
warn File.join(Root,fn)
send_file File.join(Root,fn)
end
get '/*' do |fn|
files=Dir.glob("#{Root}/#{fn}")
if files.length==1 then
f=files[0]
if File.directory? f then
files=Dir.glob(File.join(f,"*"))
end
end
playlist request,files
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment