rawq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ gem "rr"
14
+ end
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2)
10
+ rcov (0.9.11)
11
+ rr (1.0.4)
12
+ shoulda (2.11.3)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.0.0)
19
+ jeweler (~> 1.6.4)
20
+ rcov
21
+ rr
22
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Craig Jackson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ RawQ
2
+ ====
3
+
4
+ Ruby media streaming web application
5
+
6
+ Simply install and run on a server. Access the web application with any well-supported HTML5 browser.
7
+
8
+ Installation
9
+ ------------
10
+
11
+ gem install rawq
12
+
13
+ Contributing
14
+ ------------
15
+
16
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
17
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
18
+ * Fork the project
19
+ * Start a feature/bugfix branch
20
+ * Commit and push until you are happy with your contribution
21
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
22
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
23
+
24
+ Copyright
25
+ ---------
26
+
27
+ Copyright (c) 2011 Craig Jackson. See LICENSE.txt for
28
+ further details.
29
+
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rawq"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{Ruby web app for media management/streaming through HTTP with HTML5 interface}
20
+ gem.description = <<-DESC
21
+ Ruby media streaming web application
22
+
23
+ Simply install and run on a server. Access the web application with any well-supported HTML5 browser.
24
+ DESC
25
+ gem.email = "tapocol@gmail.com"
26
+ gem.authors = ["Craig Jackson"]
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ test.rcov_opts << '--exclude "gems/*"'
43
+ end
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "rawq #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require "rawq/generator"
4
+
5
+ exit RawQ::Generator::Application.run!(*ARGV)
6
+
@@ -0,0 +1,6 @@
1
+ require "rawq/version"
2
+
3
+ class RawQ
4
+ autoload :Generator, "rawq/generator"
5
+ end
6
+
@@ -0,0 +1,84 @@
1
+ require "erb"
2
+ require "rawq/version"
3
+
4
+ class RawQ
5
+ class FileExists < StandardError
6
+ end
7
+
8
+ class Generator
9
+ require "rawq/generator/options"
10
+ require "rawq/generator/application"
11
+
12
+ attr_accessor :options, :path, :application_name, :music_dir, :username, :password
13
+
14
+ def initialize(options = [])
15
+ self.options = options
16
+ self.path, self.application_name = File.split(options[:application_name])
17
+ self.music_dir = options[:music_dir] || File.join(self.path, "media/music")
18
+ self.username = options[:username] || self.application_name
19
+ self.password = (0...8).map{('a'..'z').to_a[rand(26)]}.join
20
+ end
21
+
22
+ def run
23
+ create_dirs
24
+ create_files
25
+ end
26
+
27
+ def target_dir
28
+ File.join(self.path, self.application_name)
29
+ end
30
+
31
+ def template_dir
32
+ File.join(File.dirname(__FILE__), 'templates')
33
+ end
34
+
35
+ def create_dirs
36
+ if File.exists?(target_dir)
37
+ raise FileExists, "A directory or file at #{self.path} already exists. Aborted."
38
+ end
39
+ create_dir target_dir
40
+ end
41
+
42
+ def create_dir(dir)
43
+ $stdout.puts "\tmkdir\t#{dir}"
44
+ Dir.mkdir dir
45
+ end
46
+
47
+ def create_files
48
+ find_templates(".").each do |template|
49
+ next create_dir File.join(target_dir, template) if File.directory?(File.join(template_dir, template))
50
+ create_template template
51
+ end
52
+ end
53
+
54
+ def find_templates(pwd)
55
+ templates = []
56
+ Dir.new(File.join(template_dir, pwd)).each do |filename|
57
+ next if [".", ".."].include?(filename)
58
+ templates << File.join(pwd, filename)
59
+ templates = templates + find_templates(File.join(pwd, filename)) if File.directory?(File.join(template_dir, pwd, filename))
60
+ end
61
+ templates
62
+ end
63
+
64
+ def render_template(source)
65
+ contents = File.read(File.join(template_dir, source))
66
+ template = ERB.new(contents, nil, "<>")
67
+ template.result(binding)
68
+ end
69
+
70
+ def create_template(source)
71
+ target = File.join(target_dir, source)
72
+ if File.extname(source) == ".erb"
73
+ template_result = render_template(source)
74
+ target = File.join(File.dirname(target), File.basename(target, ".erb"))
75
+ else
76
+ template_result = File.read(File.join(template_dir, source))
77
+ end
78
+
79
+ $stdout.puts "\tcreate\t#{target}"
80
+ File.open(target, "w") { |file| file.write(template_result) }
81
+ end
82
+ end
83
+ end
84
+
@@ -0,0 +1,38 @@
1
+ require "shellwords"
2
+
3
+ class RawQ
4
+ class Generator
5
+ class Application
6
+ class << self
7
+ include Shellwords
8
+
9
+ def run!(*arguments)
10
+ options = RawQ::Generator::Options.new(arguments)
11
+
12
+ if options[:invalid_option]
13
+ $stderr.puts options[:invalid_option]
14
+ options[:show_help] = true
15
+ end
16
+
17
+ if options[:show_help]
18
+ $stderr.puts options.opts
19
+ return 1
20
+ end
21
+
22
+ if options[:application_name].nil? || options[:application_name].squeeze.strip == ""
23
+ $stderr.puts "missing application name"
24
+ $stderr.puts options.opts
25
+ return 1
26
+ end
27
+
28
+ begin
29
+ generator = RawQ::Generator.new(options)
30
+ generator.run
31
+ return 0
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,40 @@
1
+ class RawQ
2
+ class Generator
3
+ class Options < Hash
4
+ attr_reader :opts
5
+
6
+ def initialize(args)
7
+ super()
8
+
9
+ require "optparse"
10
+ @opts = OptionParser.new do |o|
11
+ o.banner = "Usage: #{File.basename($0)} [options] application_name\ne.g. #{File.basename($0)} RawQorApp"
12
+
13
+ o.on("--music-dir [MUSIC_DIR]", "set your music directory") do |music_dir|
14
+ self[:music_dir] = music_dir
15
+ end
16
+
17
+ o.separator ""
18
+
19
+ o.on("--username [USERNAME]", "set your username") do |username|
20
+ self[:username] = username
21
+ end
22
+
23
+ o.separator ""
24
+
25
+ o.on_tail("-h", "--help", "display this help and exit") do
26
+ self[:show_help] = true
27
+ end
28
+ end
29
+
30
+ begin
31
+ @opts.parse!(args)
32
+ self[:application_name] = args.shift
33
+ rescue OptionParser::InvalidOption => e
34
+ self[:invalid_option] = e.message
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "sinatra", "~> 1.3"
4
+ gem "mongoid", "~> 2.3"
5
+ gem "bson_ext", "~> 1.4"
6
+
@@ -0,0 +1,56 @@
1
+ require "sinatra"
2
+ require "mongoid"
3
+ require File.join(File.dirname(__FILE__), "/lib/config")
4
+
5
+ class Media
6
+ include Mongoid::Document
7
+ embeds_many :sources
8
+ end
9
+
10
+ class Source
11
+ include Mongoid::Document
12
+ embedded_in :media
13
+ field :file, type: String
14
+ field :mimetype, type: String
15
+ end
16
+
17
+ module Sinatra
18
+ module RawQExtension
19
+ def self.registered(app)
20
+ app.use Rack::Auth::Basic, "Restricted Area" do |username, password|
21
+ [username, password] == [app.username, app.password]
22
+ end
23
+
24
+ app.get "/" do
25
+ send_file File.join(settings.public_folder, "index.html")
26
+ end
27
+
28
+ app.get "/media" do
29
+ media = Media.all
30
+ media.to_json :include => :sources
31
+ end
32
+
33
+ app.get "/media/:id" do
34
+ begin
35
+ media = Media.find(params[:id])
36
+ rescue Mongoid::Errors::DocumentNotFound
37
+ raise Sinatra::NotFound
38
+ end
39
+ media.to_json :include => :sources
40
+ end
41
+
42
+ app.get "/media/:id/:source_id" do
43
+ begin
44
+ media = Media.find(params[:id])
45
+ source = media.sources.find(params[:source_id])
46
+ rescue Mongoid::Errors::DocumentNotFound
47
+ raise Sinatra::NotFound
48
+ end
49
+ send_file File.join(source.file), :type => source.mimetype
50
+ end
51
+ end
52
+ end
53
+
54
+ register RawQExtension
55
+ end
56
+
@@ -0,0 +1,12 @@
1
+ configure do
2
+ set :username, "<%= username %>"
3
+ set :password, "<%= password %>"
4
+ set :media_types, {
5
+ :music => {:dir => "<%= music_dir %>"}
6
+ }
7
+
8
+ Mongoid.configure do |config|
9
+ config.master = Mongo::Connection.new.db("<%= application_name %>")
10
+ end
11
+ end
12
+
File without changes
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title><%= application_name %></title>
6
+ <script type="text/javascript" src="/javascript/jquery/jquery.min.js"></script>
7
+ <script type="text/javascript" src="/javascript/ejs/ejs_production.js"></script>
8
+ <script type="text/javascript" src="/javascript/audio_player.js"></script>
9
+ <script type="text/javascript" src="/javascript/music_list.js"></script>
10
+ <script type="text/javascript" src="/javascript/local_storage.js"></script>
11
+ <script type="text/javascript" src="/javascript/view.js"></script>
12
+ <script type="text/javascript" src="/javascript/rawq.js"></script>
13
+ <script type="text/javascript">
14
+ //<![CDATA[
15
+
16
+ $(function() {
17
+ window.rawq = new Rawq();
18
+ window.rawq.download_media(function() { window.rawq.render_music_list(); });
19
+ });
20
+
21
+ //]]>
22
+ </script>
23
+ </head>
24
+ <body>
25
+ <div id="media_lists">
26
+ <ul id="music_list" class="media_list"></ul>
27
+ </div>
28
+ <div id="media_players">
29
+ <audio id="audio_player" controls="controls"></audio>
30
+ </div>
31
+ </body>
32
+ </html>
33
+