airplayer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ vendor
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --profile
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ before_script:
3
+ - sudo apt-get -qq update
4
+ - sudo apt-get -qq install rdnssd libavahi-compat-libdnssd-dev
5
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in airplayer.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ airplayer (0.0.1)
5
+ airplay
6
+ rack
7
+ ruby-progressbar
8
+ thor
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ airplay (0.2.9)
14
+ dnssd (~> 2.0)
15
+ net-http-digest_auth (~> 1.2)
16
+ net-http-persistent (>= 2.6)
17
+ diff-lcs (1.1.3)
18
+ dnssd (2.0)
19
+ net-http-digest_auth (1.2.1)
20
+ net-http-persistent (2.7)
21
+ rack (1.4.1)
22
+ rspec (2.11.0)
23
+ rspec-core (~> 2.11.0)
24
+ rspec-expectations (~> 2.11.0)
25
+ rspec-mocks (~> 2.11.0)
26
+ rspec-core (2.11.1)
27
+ rspec-expectations (2.11.3)
28
+ diff-lcs (~> 1.1.3)
29
+ rspec-mocks (2.11.3)
30
+ ruby-progressbar (1.0.1)
31
+ thor (0.16.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ airplayer!
38
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tomohiro, TAIRA
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,65 @@
1
+ AirPlayer
2
+ ================================================================================
3
+
4
+ Command-line AirPlay video client for AppleTV
5
+
6
+ [![Build Status](https://secure.travis-ci.org/Tomohiro/airplayer.png)](https://secure.travis-ci.org/Tomohiro/airplayer)
7
+ [![Dependency Status](https://gemnasium.com/Tomohiro/airplayer.png)](https://gemnasium.com/Tomohiro/airplayer)
8
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/Tomohiro/airplayer)
9
+
10
+
11
+ ---
12
+
13
+
14
+ Requirements
15
+ -------------------------------------------------------------------------------
16
+
17
+ - Ruby 1.9.2 or later
18
+ - AppleTV 2G or later
19
+
20
+
21
+ Installation
22
+ --------------------------------------------------------------------------------
23
+
24
+ ## Bundler
25
+
26
+ ```sh
27
+ $ git clone git://github.com/Tomohiro/airplayer.git
28
+ $ cd airplayer
29
+ $ bundle install --path vendor/bundle
30
+ ```
31
+
32
+
33
+ ### RubyGems
34
+
35
+ ```sh
36
+ $ gem install airplayer
37
+ ```
38
+
39
+
40
+ Usage
41
+ --------------------------------------------------------------------------------
42
+
43
+ ### Play online video
44
+
45
+ ```sh
46
+ $ airplayer play http://example.com/my-video.mp4
47
+ AirPlay: http://example.com/my-video.mp4 to Apple TV(10.0.1.18)
48
+ Time: 00:00:31 |==============================================| 100% Complete
49
+ ```
50
+
51
+ ### Play local video
52
+
53
+ ```sh
54
+ $ airplayer play $HOME/Movies/video.mp4
55
+ AirPlay: http://10.0.1.13:7070 to Apple TV(10.0.1.18)
56
+ Time: 00:00:31 |==============================================| 100% Complete
57
+ ```
58
+
59
+
60
+ LICENSE
61
+ --------------------------------------------------------------------------------
62
+
63
+ © 2012 Tomohiro, TAIRA.
64
+ This project is licensed under the MIT license.
65
+ See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+
4
+ # RSpec
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
data/airplayer.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/airplayer/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'airplayer'
6
+ gem.version = AirPlayer::VERSION
7
+ gem.authors = ['Tomohiro, TAIRA']
8
+ gem.email = ['tomohiro.t@gmail.com']
9
+ gem.description = %q{Command-line AirPlay video client for AppleTV}
10
+ gem.summary = %q{Command-line AirPlay video client for AppleTV}
11
+ gem.homepage = 'https://github.com/Tomohiro/airplayer'
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_runtime_dependency 'thor'
19
+ gem.add_runtime_dependency 'ruby-progressbar'
20
+ gem.add_runtime_dependency 'airplay'
21
+ gem.add_runtime_dependency 'rack'
22
+
23
+ gem.add_development_dependency 'rspec'
24
+ end
data/bin/airplayer ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'airplayer'
5
+ AirPlayer::App.start
data/lib/airplayer.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'airplayer/version'
3
+
4
+ module AirPlayer
5
+ autoload :App, 'airplayer/app'
6
+ autoload :Player, 'airplayer/player'
7
+ autoload :Server, 'airplayer/server'
8
+ end
@@ -0,0 +1,16 @@
1
+ require 'thor'
2
+
3
+ module AirPlayer
4
+ class App < Thor
5
+ desc 'play [URI|FILE]', 'Play video(URI or local video file path)'
6
+ def play(uri)
7
+ Player.new.play(uri)
8
+ end
9
+
10
+ map '--version' => :version
11
+ desc 'version, --version', 'Display version'
12
+ def version
13
+ puts VERSION
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,88 @@
1
+ require 'timeout'
2
+ require 'uri'
3
+ require 'airplay'
4
+ require 'airplayer/progress_bar/base'
5
+
6
+ module AirPlayer
7
+ class Player
8
+ BufferingTimeoutError = Class.new(TimeoutError)
9
+
10
+ def initialize
11
+ @airplay = Airplay::Client.new
12
+ @player = nil
13
+ @progressbar = nil
14
+ @timeout = 30
15
+ @interval = 1
16
+ @total_sec = 0
17
+ @current_sec = 0
18
+ end
19
+
20
+ def play(target)
21
+ path = File.expand_path(target)
22
+ if local_file? path
23
+ video_server = AirPlayer::Server.new(path)
24
+ uri = video_server.uri
25
+ Thread.start { video_server.start }
26
+ else
27
+ uri = URI.encode(target)
28
+ end
29
+
30
+ device = @airplay.browse.first
31
+ puts "AirPlay: #{uri} to #{device.name}(#{device.ip})"
32
+
33
+ @progressbar = ProgressBar.create(:format => ' %a |%b%i| %p%% %t', :title => :Waiting)
34
+ @player = @airplay.send_video(uri)
35
+ buffering
36
+ while playing do
37
+ @progressbar.progress = @current_sec
38
+ end
39
+ stop
40
+ rescue BufferingTimeoutError
41
+ abort 'Buffering timeout error.'
42
+ end
43
+
44
+ def stop
45
+ unless @player.nil?
46
+ @player.stop
47
+ end
48
+
49
+ unless @progressbar.nil?
50
+ @progressbar.title = :Complete
51
+ @progressbar.finish
52
+ end
53
+ end
54
+
55
+ private
56
+ def local_file?(path)
57
+ File.exist? path
58
+ end
59
+
60
+ def buffering
61
+ timeout @timeout, BufferingTimeoutError do
62
+ loop do
63
+ playing
64
+ redo unless buffering?
65
+ @progressbar.title = :Streaming
66
+ @progressbar.total = @total_sec
67
+ break
68
+ end
69
+ end
70
+ end
71
+
72
+ def playing
73
+ scrub = @player.scrub
74
+ @total_sec = scrub['duration']
75
+ @current_sec = scrub['position']
76
+ sleep @interval
77
+ progress?
78
+ end
79
+
80
+ def progress?
81
+ 0 < @current_sec && @current_sec < @total_sec
82
+ end
83
+
84
+ def buffering?
85
+ 0 < @total_sec && 0 < @current_sec
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,9 @@
1
+ require 'ruby-progressbar'
2
+
3
+ class ProgressBar
4
+ class Base
5
+ def total=(new_total)
6
+ with_update { with_progressables(:total=, new_total) }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ require 'rack'
2
+ require 'socket'
3
+
4
+ module AirPlayer
5
+ class Server
6
+ attr_reader :uri
7
+
8
+ def initialize(video_path)
9
+ @server = Rack::Server.new(:server => :webrick, :Host => local_ip, :Port => 7070)
10
+ @server.instance_variable_set(:@app, Rack::File.new(video_path))
11
+ @uri = "http://#{@server.options[:Host]}:#{@server.options[:Port]}"
12
+ end
13
+
14
+ def start
15
+ # silenced WEBrick access log
16
+ $stderr = File.open('/dev/null', 'w')
17
+ @server.start
18
+ $stderr = STDERR
19
+ end
20
+
21
+ # networking - Getting the Hostname or IP in Ruby on Rails - Stack Overflow
22
+ # http://stackoverflow.com/questions/42566/getting-the-hostname-or-ip-in-ruby-on-rails
23
+ def local_ip
24
+ # turn off reverse DNS resolution temporarily
25
+ orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
26
+
27
+ UDPSocket.open do |s|
28
+ s.connect('8.8.8.8', 1)
29
+ s.addr.last
30
+ end
31
+ ensure
32
+ Socket.do_not_reverse_lookup = orig
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module AirPlayer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe AirPlayer do
4
+ let(:app) { AirPlayer::App.new }
5
+ context 'App' do
6
+ it 'class type is Thor' do
7
+ expect(app).to be_kind_of Thor
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'airplayer'
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: airplayer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tomohiro, TAIRA
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: ruby-progressbar
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: airplay
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rack
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Command-line AirPlay video client for AppleTV
95
+ email:
96
+ - tomohiro.t@gmail.com
97
+ executables:
98
+ - airplayer
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - .rspec
104
+ - .travis.yml
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE
108
+ - README.markdown
109
+ - Rakefile
110
+ - airplayer.gemspec
111
+ - bin/airplayer
112
+ - lib/airplayer.rb
113
+ - lib/airplayer/app.rb
114
+ - lib/airplayer/player.rb
115
+ - lib/airplayer/progress_bar/base.rb
116
+ - lib/airplayer/server.rb
117
+ - lib/airplayer/version.rb
118
+ - spec/airplayer_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: https://github.com/Tomohiro/airplayer
121
+ licenses: []
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ hash: -1081237066405276269
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ segments:
142
+ - 0
143
+ hash: -1081237066405276269
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 1.8.23
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: Command-line AirPlay video client for AppleTV
150
+ test_files:
151
+ - spec/airplayer_spec.rb
152
+ - spec/spec_helper.rb