airstream 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/airstream CHANGED
@@ -6,9 +6,7 @@ options = {
6
6
  reciever: '192.168.1.8',
7
7
  quiet: false,
8
8
  verbose: false,
9
- use_local_http: false,
10
- http_path: '/var/www/html/airstream/',
11
- http_url: 'http://192.168.1.2/airstream/'
9
+ use_local_http: true
12
10
  }
13
11
 
14
12
  CONFIG_FILE = File.join(ENV['HOME'], '.airstreamrc')
@@ -45,30 +43,14 @@ Basic options: (configure default in ~/.airstreamrc)
45
43
  options[:verbose] = verbose
46
44
  end
47
45
 
48
- opts.on("--enable-use-httpd",
49
- "use httpd to offer local files") do |use_httpd|
50
- options[:use_local_httpd] = true
51
- end
52
-
53
- opts.on("-u HTTP_URL",
54
- "the local webserver url") do |http_url|
55
- options[:http_url] = http_url
56
- end
57
-
58
- opts.on("-p HTTP_PATH",
59
- "the local webserver directory path") do |path|
60
- options[:http_path] = path
61
- end
62
-
63
- # opts.on("--cleanup",
64
- # "remove the local webserver files and exit") do |path|
65
- # FileUtils.rm(Dir.glob(options[:http_path] + '/*'))
66
- # exit 0
46
+ # opts.on("--enable-use-httpd",
47
+ # "use httpd to offer local files") do |use_httpd|
48
+ # options[:use_local_httpd] = true
67
49
  # end
68
50
 
69
51
  opts.on("-v", "--version",
70
52
  "output version information then quit") do |path|
71
- puts "airstream v" + Airplay::VERSION
53
+ puts "airstream v" + Airstream::VERSION
72
54
  exit 0
73
55
  end
74
56
  end
@@ -80,6 +62,7 @@ if ARGV.empty?
80
62
  end
81
63
 
82
64
  begin
65
+
83
66
  option_parser.parse!
84
67
 
85
68
  unless options[:reciever]
@@ -89,32 +72,46 @@ begin
89
72
 
90
73
  server = Airstream::Server.new(options[:reciever])
91
74
 
75
+ puts "=> Ctrl-C to exit airstream"
92
76
  ARGV.each do |file|
93
- server.allow_local_httpd = options[:use_local_httpd]
94
- if server.local_httpd_allowed?
95
- server.http_path = options[:http_path]
96
- server.http_url = options[:http_url]
97
- end
98
77
 
78
+ server.allow_local_httpd = options[:use_local_httpd]
79
+ puts "sending video file #{file}" if options[:verbose]
99
80
  server.video = file
100
81
 
82
+ print "loading " unless options[:quiet]
101
83
  "|/-\\".chars.cycle.each do |c|
102
- print c; sleep(0.2); print "\b"
84
+ print c unless options[:quiet]
85
+ sleep(0.2)
86
+ print "\b" unless options[:quiet]
103
87
  break unless server.loading?
104
88
  end
89
+ puts "done" unless options[:quiet]
105
90
 
91
+ video_title = File.basename(file, '.mp4')
106
92
  pbar_options = {
107
- title: File.basename(file, '.mp4'),
93
+ title: video_title,
108
94
  total: server.video_duration,
109
- format: '%t %a |%b>>%i| %p%%'
95
+ format: '%t |%b%i| %p%%'
110
96
  }
111
97
  pbar = ProgressBar.create(pbar_options)
112
- while server.video_position < server.video_duration
113
- pbar.progress = server.video_position
98
+ while (elapsed_time=server.video_position) < server.video_duration
99
+ pbar.progress = elapsed_time
100
+ formatted_time = Time.at(elapsed_time).gmtime.strftime('%R:%S')
101
+ pbar.title = "#{video_title} #{formatted_time}"
114
102
  sleep 1.0
115
103
  end
116
104
  pbar.finish
117
105
  end
106
+
107
+ rescue Airplay::Protocol::InvalidMediaError
108
+ STDERR.puts
109
+ STDERR.puts "invalid media file"
110
+ exit 0
111
+ rescue NoMethodError # @FIX webrick raises no method error
112
+ STDERR.puts
113
+ STDERR.puts "file host shutdown"
114
+ exit 0
118
115
  rescue Interrupt
119
116
  STDERR.puts
120
117
  STDERR.puts "exiting"
data/lib/airstream.rb CHANGED
@@ -2,13 +2,16 @@
2
2
  require 'optparse'
3
3
  require 'airplay'
4
4
  require 'ruby-progressbar'
5
- require 'digest'
6
- require 'fileutils'
7
5
  require 'yaml'
6
+ require 'rack'
8
7
 
9
8
  module Airstream
10
- VERSION = '0.2.3'
11
- DEFAULT_PORT = 7000
9
+ AIRPLAY_PORT = 7000
10
+ AIRSTREAM_PORT = 7000
12
11
  end
13
12
 
13
+ require 'airstream/version.rb'
14
+ require 'airstream/network.rb'
15
+ require 'airstream/node.rb'
16
+ require 'airstream/video.rb'
14
17
  require 'airstream/server.rb'
@@ -0,0 +1,11 @@
1
+
2
+ require 'socket'
3
+
4
+ module Airstream
5
+ class Network
6
+ # http://stackoverflow.com/questions/5029427/ruby-get-local-ip-nix
7
+ def self.get_local_ip
8
+ Socket.ip_address_list.detect{|intf| intf.ipv4_private?}.ip_address
9
+ end
10
+ end
11
+ end
@@ -1,15 +1,11 @@
1
1
 
2
2
  module Airstream
3
- class Server < Airplay::Client
4
- attr_accessor :http_path, :http_url, :video_duration
3
+ class Server
5
4
 
6
5
  @local_httpd_allowed = false
7
6
 
8
7
  def initialize(reciever)
9
- node = Airplay::Server::Node.new(
10
- reciever, reciever, reciever, Airstream::DEFAULT_PORT)
11
- @device = Airplay::Client.new(node)
12
- @device.use(node) # does not work without that second assign
8
+ @device = Airstream::Node.new reciever
13
9
  end
14
10
 
15
11
  def image=(image_file)
@@ -17,16 +13,9 @@ module Airstream
17
13
  end
18
14
 
19
15
  def video=(video_file)
20
- video_duration = nil
21
- if File.exists?(video_file) && local_httpd_allowed?
22
- filename = Digest::MD5.hexdigest(File.basename(video_file, '.mp4')) + ".mp4"
23
- unless File.exists?(http_path + filename)
24
- FileUtils.cp(video_file, http_path + filename)
25
- end
26
- @device.send_video http_url + filename
27
- else
28
- @device.send_video video_file
29
- end
16
+ @video_duration = nil
17
+ video = Video.new(video_file)
18
+ @device.send_video(video.url)
30
19
  end
31
20
 
32
21
  def allow_local_httpd=(is_allowed)
@@ -0,0 +1,4 @@
1
+
2
+ module Airstream
3
+ VERSION = '0.3.1'
4
+ end
@@ -0,0 +1,35 @@
1
+
2
+ require 'rack'
3
+ require 'webrick'
4
+
5
+ module Airstream
6
+ class Video
7
+
8
+ @@server = nil
9
+ attr_reader :url
10
+
11
+ def initialize(video_file)
12
+ if File.exists? video_file
13
+ @@server.server.shutdown if @@server
14
+ @url = host_file(video_file)
15
+ else
16
+ @url = video_file
17
+ end
18
+ end
19
+
20
+ def host_file(file)
21
+ @@server = Rack::Server.new(
22
+ :server => :webrick,
23
+ :Host => Airstream::Network.get_local_ip,
24
+ :Port => AIRSTREAM_PORT,
25
+ :app => Rack::File.new(file),
26
+ :AccessLog => [], # stfu webrick
27
+ :Logger => WEBrick::Log::new("/dev/null", 7)
28
+ )
29
+ Thread.start do
30
+ @@server.start
31
+ end
32
+ "http://#{@@server.options[:Host]}:#{@@server.options[:Port]}"
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airstream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-04 00:00:00.000000000 Z
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: airplay
@@ -59,8 +59,7 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- description: ! "A command line tool to stream video and image files to\n airplay-devices,
63
- a webserver is needed for local video\n files."
62
+ description: ! "A command line tool to stream video and image files to\n airplay-devices."
64
63
  email:
65
64
  - christoph at lipautz.org
66
65
  executables:
@@ -72,6 +71,9 @@ files:
72
71
  - bin/airstream
73
72
  - bin/airimg
74
73
  - lib/airstream.rb
74
+ - lib/airstream/version.rb
75
+ - lib/airstream/network.rb
76
+ - lib/airstream/video.rb
75
77
  - lib/airstream/server.rb
76
78
  homepage: https://github.com/unused/airstream
77
79
  licenses: []