airplay-cli 0.1.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/air +27 -0
- data/lib/airplay/cli.rb +104 -0
- metadata +98 -0
data/bin/air
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "clap"
|
4
|
+
require "airplay/cli"
|
5
|
+
|
6
|
+
Clap.run ARGV,
|
7
|
+
"--device" => lambda { |device_name| @device = Airplay[device_name] },
|
8
|
+
"--wait" => lambda { |sec| @wait = sec.to_i },
|
9
|
+
"--interactive" => lambda { @interactive = true },
|
10
|
+
|
11
|
+
"list" => Airplay::CLI.method(:list),
|
12
|
+
|
13
|
+
"play" => lambda { |video|
|
14
|
+
options = { device: @device || Airplay.devices.first }
|
15
|
+
Airplay::CLI.play(video, options)
|
16
|
+
},
|
17
|
+
|
18
|
+
"view" => lambda { |file|
|
19
|
+
options = {
|
20
|
+
device: @device || Airplay.devices.first,
|
21
|
+
interactive: @interactive || false,
|
22
|
+
wait: @wait || 3
|
23
|
+
}
|
24
|
+
Airplay::CLI.view(file, options)
|
25
|
+
}
|
26
|
+
|
27
|
+
# vim: ft=ruby
|
data/lib/airplay/cli.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require "airplay"
|
2
|
+
require "ruby-progressbar"
|
3
|
+
|
4
|
+
module Airplay
|
5
|
+
module CLI
|
6
|
+
class << self
|
7
|
+
def list
|
8
|
+
Airplay.devices.each do |device|
|
9
|
+
puts <<-EOS.gsub(/^\s{12}/,'')
|
10
|
+
* #{device.name} (#{device.info.model} running #{device.info.os_version})
|
11
|
+
ip: #{device.ip}
|
12
|
+
resolution: #{device.info.resolution}
|
13
|
+
|
14
|
+
EOS
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def play(video, options)
|
19
|
+
device = options[:device]
|
20
|
+
player = device.play(video)
|
21
|
+
puts "Playing #{video}"
|
22
|
+
bar = ProgressBar.create(
|
23
|
+
title: device.name,
|
24
|
+
format: "%a [%B] %p%% %t"
|
25
|
+
)
|
26
|
+
|
27
|
+
player.progress -> playback {
|
28
|
+
bar.progress = playback.percent
|
29
|
+
}
|
30
|
+
|
31
|
+
player.wait
|
32
|
+
end
|
33
|
+
|
34
|
+
def view(file_or_dir, options)
|
35
|
+
device = options[:device]
|
36
|
+
wait = options[:wait]
|
37
|
+
|
38
|
+
if File.directory?(file_or_dir)
|
39
|
+
files = Dir.glob("#{file_or_dir}/*")
|
40
|
+
|
41
|
+
if options[:interactive]
|
42
|
+
view_interactive(files)
|
43
|
+
else
|
44
|
+
view_slideshow(files)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
view_image(device, file_or_dir)
|
48
|
+
sleep
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def view_interactive(files)
|
55
|
+
numbers = Array(0...files.count)
|
56
|
+
transition = "None"
|
57
|
+
|
58
|
+
i = 0
|
59
|
+
loop do
|
60
|
+
view_image(device, files[i], transition)
|
61
|
+
|
62
|
+
case read_char
|
63
|
+
# Right Arrow
|
64
|
+
when "\e[C"
|
65
|
+
i = i + 1 > numbers.count - 1 ? 0 : i + 1
|
66
|
+
transition = "SlideLeft"
|
67
|
+
when "\e[D"
|
68
|
+
i = i - 1 < 0 ? numbers.count - 1 : i - 1
|
69
|
+
transition = "SlideRight"
|
70
|
+
else
|
71
|
+
break
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def view_slideshow(files)
|
77
|
+
files.each do |file|
|
78
|
+
view_image(device, file)
|
79
|
+
sleep wait
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def read_char
|
84
|
+
STDIN.echo = false
|
85
|
+
STDIN.raw!
|
86
|
+
|
87
|
+
input = STDIN.getc.chr
|
88
|
+
if input == "\e" then
|
89
|
+
input << STDIN.read_nonblock(3) rescue nil
|
90
|
+
input << STDIN.read_nonblock(2) rescue nil
|
91
|
+
end
|
92
|
+
ensure
|
93
|
+
STDIN.echo = true
|
94
|
+
STDIN.cooked!
|
95
|
+
|
96
|
+
return input
|
97
|
+
end
|
98
|
+
|
99
|
+
def view_image(device, image, transition = "SlideLeft")
|
100
|
+
device.view(image, transition: transition)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: airplay-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.beta2
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- elcuervo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: airplay
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0.beta2
|
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: 1.0.0.beta2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: clap
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.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: 1.0.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ruby-progressbar
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.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: 1.2.0
|
62
|
+
description: Send pics and videos using the terminal
|
63
|
+
email:
|
64
|
+
- yo@brunoaguirre.com
|
65
|
+
executables:
|
66
|
+
- air
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- bin/air
|
71
|
+
- lib/airplay/cli.rb
|
72
|
+
homepage: http://github.com/elcuervo/airplay
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
- HUGWARE
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>'
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 1.3.1
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.23
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Airplay client CLI
|
98
|
+
test_files: []
|