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 +8 -11
- data/bin/airstream +26 -39
- data/lib/airstream.rb +14 -0
- data/lib/airstream/server.rb +53 -0
- metadata +4 -1
data/bin/airimg
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
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" +
|
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
|
-
|
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
|
-
|
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
|
-
|
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" +
|
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
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
sleep
|
120
|
-
|
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:
|
108
|
+
total: server.video_duration,
|
126
109
|
format: '%t %a |%b>>%i| %p%%'
|
127
110
|
}
|
128
111
|
pbar = ProgressBar.create(pbar_options)
|
129
|
-
while
|
130
|
-
pbar.progress =
|
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,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.
|
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:
|