danta 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ require_relative 'dispatcher'
2
+
3
+ class RequestHandler
4
+
5
+ attr_reader :request
6
+
7
+ def initialize(request:)
8
+ @request = request
9
+ end
10
+
11
+ def process
12
+ if request.websocket?
13
+ process_web_socket_request
14
+ else
15
+ process_http_request
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def process_web_socket_request
22
+ request.websocket do |ws|
23
+
24
+ ws.onopen do
25
+ ws.send({ action: 'open_connection', status: 'success', data: {} }.to_json)
26
+ p "Connection opened"
27
+ end
28
+
29
+ ws.onmessage do |msg|
30
+ dispatcher = Dispatcher.new(raw_data: msg)
31
+ ws.send(dispatcher.dispatch)
32
+ end
33
+
34
+ ws.onclose do
35
+ ws.send({ action: 'close_connection', status: 'success', data: {} }.to_json)
36
+ p "Connection closed"
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+ def process_http_request
43
+ p "HTTP requests are not supported"
44
+ end
45
+
46
+ def dispatcher
47
+ @dispatcher ||= Dispatcher.new
48
+ end
49
+
50
+ end
data/lib/danta/root.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'sinatra'
2
+ require_relative 'app'
3
+ require_relative 'api'
4
+
5
+ module Danta
6
+
7
+ class Root
8
+
9
+ def rack_builder
10
+ rack = Rack::Builder.new
11
+
12
+ rack.map '/' do
13
+ run Danta::App.new
14
+ end
15
+
16
+ rack.map '/api' do
17
+ run Danta::Api.new
18
+ end
19
+
20
+ rack
21
+ end
22
+
23
+ def start
24
+ rack = rack_builder
25
+ danta_host = ENV['DANTA_HOST'] || '0.0.0.0'
26
+ danta_port = ENV['DANTA_PORT'] || 9292
27
+ startup_msg(danta_host, danta_port)
28
+ Rack::Server.start app: rack, Host: danta_host, Port: danta_port
29
+ exit
30
+ end
31
+
32
+ def startup_msg(danta_host, danta_port)
33
+ p
34
+ p '====================================================='
35
+ p 'Danta app is starting up with the following settings:'
36
+ p "Host: #{danta_host} # Set DANTA_HOST env var for custom host, defaults on 0.0.0.0"
37
+ p "Port: #{danta_port} # Set DANTA_PORT env var for custom port, defaults on 9292"
38
+ p '====================================================='
39
+ p
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,3 @@
1
+ module Danta
2
+ VERSION = '0.0.0'
3
+ end
@@ -0,0 +1,63 @@
1
+ require 'yaml'
2
+ require_relative 'library/tree'
3
+
4
+ module Danta
5
+
6
+ class VideoLibrary
7
+
8
+ VIDEO_FORMATS = [ :mkv, :mov, :mp4 ]
9
+
10
+ def videos
11
+ video_libraries
12
+ .map { |library| Library::Tree.new(paths: video_paths(library)) }
13
+ .flat_map { |library| library.to_h }
14
+ end
15
+
16
+ private
17
+
18
+ def video_paths(path)
19
+ Dir.glob("#{path}/**/*.{#{extensions}}")
20
+ end
21
+
22
+ def extensions
23
+ VIDEO_FORMATS.join(',')
24
+ end
25
+
26
+ def video_libraries
27
+ YAML.load(video_library_file)['videos']
28
+ end
29
+
30
+ def video_library_file
31
+ File.open(File.join(Dir.home, 'video_library.yml'))
32
+ rescue Errno::ENOENT
33
+ p "Cannot find video_library.yml in your home directory."
34
+ p "Either create the file or set the env variable DANTA_VIDEO_LIBRARY pointing to the dir where the file exists."
35
+ p "Create it with the following data:"
36
+ p " ---"
37
+ p " videos:"
38
+ p " - '/path/to/movies/'"
39
+ raise Danta::UnexistingVideoLibraryFile
40
+ end
41
+
42
+ def video_library_dir
43
+ ENV['DANTA_VIDEO_LIBRARY'] || Dir.home
44
+ end
45
+
46
+ end
47
+
48
+ class UnexistingVideoLibraryFile < StandardError
49
+
50
+ def message
51
+ <<-EOF
52
+ Cannot find video_library.yml in your home directory.
53
+ Either create the file or set the env variable DANTA_VIDEO_LIBRARY pointing to the dir where the file exists.
54
+ Create it with the following data:
55
+ ---
56
+ videos:
57
+ - '/path/to/movies/'
58
+ EOF
59
+ end
60
+
61
+ end
62
+
63
+ end
data/lib/danta.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'danta/root'
2
+ module Danta
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Chacon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Danta is a web app for easy video playing in your Raspberry Pi using
14
+ Sinatra and Omxplayer.
15
+ email: caedo.00@gmail.com
16
+ executables:
17
+ - danta
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - bin/danta
24
+ - lib/danta.rb
25
+ - lib/danta/api.rb
26
+ - lib/danta/app.rb
27
+ - lib/danta/dispatcher.rb
28
+ - lib/danta/library/node.rb
29
+ - lib/danta/library/null_node.rb
30
+ - lib/danta/library/tree.rb
31
+ - lib/danta/public/css/bootstrap-treeview.min.css
32
+ - lib/danta/public/css/danta.css
33
+ - lib/danta/public/index.html
34
+ - lib/danta/public/js/bootstrap-treeview.min.js
35
+ - lib/danta/public/js/danta.js
36
+ - lib/danta/public/js/jquery-2.1.4.min.js
37
+ - lib/danta/public/js/jquery.mobile.custom.min.js
38
+ - lib/danta/public/js/player_actions.js
39
+ - lib/danta/public/js/player_modal.js
40
+ - lib/danta/public/js/response_dispatcher.js
41
+ - lib/danta/public/js/video_library.js
42
+ - lib/danta/public/js/video_tree.js
43
+ - lib/danta/public/js/videos_response.js
44
+ - lib/danta/public/js/web_socket_client.js
45
+ - lib/danta/public/ws.html
46
+ - lib/danta/request_handler.rb
47
+ - lib/danta/root.rb
48
+ - lib/danta/version.rb
49
+ - lib/danta/video_library.rb
50
+ homepage:
51
+ licenses: []
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.4.5.1
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Danta is a video webplayer for the Raspberry Pi.
73
+ test_files: []