Skip to content

Instantly share code, notes, and snippets.

@bear454
Created March 22, 2010 20:49
Show Gist options
  • Save bear454/340514 to your computer and use it in GitHub Desktop.
Save bear454/340514 to your computer and use it in GitHub Desktop.
sinatra media browser
#! /usr/bin/ruby
require 'rubygems'
require 'sinatra'
require 'haml'
require 'thin'
set :public, File.dirname(__FILE__)
get '/' do
haml Dir.open("/mediadisk").collect{|e| "%li\n %a{:href => \"/#{e}\"}&= \"#{e}\"\n" if e.match(/^[A-Z]/) }.compact.sort.to_s
end
get '/*.m4v' do
`vlc --fullscreen --video-on-top --no-video-title-show --play-and-exit --quiet /mediadisk/#{params[:splat].to_s.gsub(' ', '\ ') }.m4v`
#or... `totem --replace --fullscreen /mediadisk/#{params[:splat].to_s.gsub(' ', '\ ') }.m4v`
redirect "/#{/^(.+)\/(.+)$/.match(params[:splat].to_s)[1] }"
end
get '/*' do
path = /^(.+?)[\/]*$/.match(params[:splat].to_s)[1]
haml Dir.open("/mediadisk/#{path}").collect{|e| "%li\n %a{:href => \"/#{path}/#{e}\"}&= \"#{e == '..' ? '|<< Back |' : e}\"\n"}.sort[1..-1].to_s
end
__END__
@@ layout
!!! XML
!!!
%html
%head
%link{:rel => 'icon', :type => 'image/icon', :href => '/favicon.ico'}
%body
%div{:align => 'center'}
%ul= yield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment