airstream 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/airimg CHANGED
@@ -1,10 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- PROGRAM_VERSION = "0.2.1"
4
-
5
- require 'optparse'
6
- require 'airplay'
7
- require 'yaml'
3
+ require 'airstream'
8
4
 
9
5
  options = {
10
6
  reciever: '192.168.1.8',
@@ -38,7 +34,7 @@ Basic options: (configure default in ~/.airstreamrc)
38
34
 
39
35
  opts.on("-v", "--version",
40
36
  "output version information then quit") do |path|
41
- puts "airstream airimg v" + PROGRAM_VERSION
37
+ puts "airstream airimg v" + Airstream::VERSION
42
38
  exit 0
43
39
  end
44
40
  end
@@ -57,16 +53,17 @@ begin
57
53
  exit 68
58
54
  end
59
55
 
60
- node = Airplay::Server::Node.new(options[:reciever],
61
- options[:reciever], options[:reciever], 7000)
62
- ap = Airplay::Client.new node
63
- ap.use node # does not work without that second assign
56
+ server = Airstream::Server.new(options[:reciever])
64
57
 
65
58
  ARGV.each do |file|
66
- ap.send_image file
59
+ server.image = file
67
60
  sleep options[:interval]
68
61
  end
69
62
 
63
+ rescue Interrupt
64
+ STDERR.puts
65
+ STDERR.puts "exiting"
66
+ exit 0
70
67
  rescue OptionParser::InvalidArgument => ex
71
68
  STDERR.puts ex.message
72
69
  STDERR.puts option_parser
data/bin/airstream CHANGED
@@ -1,13 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- PROGRAM_VERSION = "0.2.1"
4
-
5
- require 'optparse'
6
- require 'airplay'
7
- require 'ruby-progressbar'
8
- require 'digest'
9
- require 'fileutils'
10
- require 'yaml'
3
+ require 'airstream'
11
4
 
12
5
  options = {
13
6
  reciever: '192.168.1.8',
@@ -67,9 +60,15 @@ Basic options: (configure default in ~/.airstreamrc)
67
60
  options[:http_path] = path
68
61
  end
69
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
67
+ # end
68
+
70
69
  opts.on("-v", "--version",
71
70
  "output version information then quit") do |path|
72
- puts "airstream v" + PROGRAM_VERSION
71
+ puts "airstream v" + Airplay::VERSION
73
72
  exit 0
74
73
  end
75
74
  end
@@ -88,50 +87,38 @@ begin
88
87
  exit 68
89
88
  end
90
89
 
91
- node = Airplay::Server::Node.new(options[:reciever],
92
- options[:reciever], options[:reciever], 7000)
93
- ap = Airplay::Client.new node
94
- ap.use node # does not work without that second assign
90
+ server = Airstream::Server.new(options[:reciever])
95
91
 
96
92
  ARGV.each do |file|
97
- if File.exists?(file) && options[:use_local_httpd]
98
- # raise ArgumentError unless options[:use_local_httpd]
99
- # raise ArgumentError unless options[:http_path]
100
- # raise ArgumentError unless options[:http_url]
101
- filename = Digest::MD5.hexdigest(File.basename(file, '.mp4')) + ".mp4"
102
-
103
- puts "generated hash-filename for local webserver: #{filename}" if options[:verbose]
104
-
105
- unless File.exists?(options[:http_path] + filename)
106
- FileUtils.cp(file, options[:http_path] + filename)
107
- puts "copied file to #{options[:http_path]}#{filename}" if options[:verbose]
108
- end
109
- puts "sending local file #{filename}" unless options[:quiet]
110
- ap.send_video options[:http_url] + filename
111
- else
112
- puts "sending remote file #{filename}" unless options[:quiet]
113
- ap.send_video 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]
114
97
  end
115
- print "loading" unless options[:quiet]
116
- while ap.scrub['position'] == 0
117
- # do not wait a second to make user believie it is
118
- # loading much faster... psychology is a bitch
119
- sleep 0.8
120
- print "." unless options[:quiet]
98
+
99
+ server.video = file
100
+
101
+ "|/-\\".chars.cycle.each do |c|
102
+ print c; sleep(0.2); print "\b"
103
+ break unless server.loading?
121
104
  end
122
105
 
123
106
  pbar_options = {
124
107
  title: File.basename(file, '.mp4'),
125
- total: ap.scrub['duration'],
108
+ total: server.video_duration,
126
109
  format: '%t %a |%b>>%i| %p%%'
127
110
  }
128
111
  pbar = ProgressBar.create(pbar_options)
129
- while ap.scrub['position'] < ap.scrub['duration']
130
- pbar.progress = ap.scrub['position']
112
+ while server.video_position < server.video_duration
113
+ pbar.progress = server.video_position
131
114
  sleep 1.0
132
115
  end
133
116
  pbar.finish
134
117
  end
118
+ rescue Interrupt
119
+ STDERR.puts
120
+ STDERR.puts "exiting"
121
+ exit 0
135
122
  rescue OptionParser::InvalidArgument => ex
136
123
  STDERR.puts ex.message
137
124
  STDERR.puts option_parser
data/lib/airstream.rb ADDED
@@ -0,0 +1,14 @@
1
+
2
+ require 'optparse'
3
+ require 'airplay'
4
+ require 'ruby-progressbar'
5
+ require 'digest'
6
+ require 'fileutils'
7
+ require 'yaml'
8
+
9
+ module Airstream
10
+ VERSION = '0.2.3'
11
+ DEFAULT_PORT = 7000
12
+ end
13
+
14
+ require 'airstream/server.rb'
@@ -0,0 +1,53 @@
1
+
2
+ module Airstream
3
+ class Server < Airplay::Client
4
+ attr_accessor :http_path, :http_url, :video_duration
5
+
6
+ @local_httpd_allowed = false
7
+
8
+ 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
13
+ end
14
+
15
+ def image=(image_file)
16
+ @device.send_image image_file
17
+ end
18
+
19
+ 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
30
+ end
31
+
32
+ def allow_local_httpd=(is_allowed)
33
+ @local_httpd_allowed = is_allowed
34
+ end
35
+
36
+ def local_httpd_allowed?
37
+ @local_httpd_allowed
38
+ end
39
+
40
+ def loading?
41
+ @device.scrub['position'] == 0
42
+ end
43
+
44
+ def video_position
45
+ @device.scrub['position']
46
+ end
47
+
48
+ def video_duration
49
+ @video_duration = @video_duration || @device.scrub['duration']
50
+ end
51
+
52
+ end
53
+ 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.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -71,12 +71,15 @@ extra_rdoc_files: []
71
71
  files:
72
72
  - bin/airstream
73
73
  - bin/airimg
74
+ - lib/airstream.rb
75
+ - lib/airstream/server.rb
74
76
  homepage: https://github.com/unused/airstream
75
77
  licenses: []
76
78
  post_install_message:
77
79
  rdoc_options: []
78
80
  require_paths:
79
81
  - lib
82
+ - lib
80
83
  required_ruby_version: !ruby/object:Gem::Requirement
81
84
  none: false
82
85
  requirements: