airplay-cli 0.1.0.beta4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/air +26 -16
  2. data/lib/airplay/cli.rb +32 -55
  3. metadata +7 -7
data/bin/air CHANGED
@@ -2,26 +2,36 @@
2
2
 
3
3
  require "clap"
4
4
  require "airplay/cli"
5
+ require "airplay/cli/version"
5
6
 
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 },
7
+ begin
8
+ Clap.run ARGV,
9
+ "--device" => lambda { |device_name| @device = Airplay[device_name] },
10
+ "--wait" => lambda { |sec| @wait = sec.to_i },
11
+ "--interactive" => lambda { @interactive = true },
10
12
 
11
- "list" => Airplay::CLI.method(:list),
13
+ "list" => Airplay::CLI.method(:list),
12
14
 
13
- "play" => lambda { |video|
14
- options = { device: @device || Airplay.devices.first }
15
- Airplay::CLI.play(video, options)
16
- },
15
+ "version" => lambda { puts Airplay::CLI::VERSION },
17
16
 
18
- "view" => lambda { |file|
19
- options = {
20
- device: @device || Airplay.devices.first,
21
- interactive: @interactive || false,
22
- wait: @wait || 3
17
+ "play" => lambda { |video|
18
+ options = { device: @device || Airplay.devices.first }
19
+ Airplay::CLI.play(video, options)
20
+ },
21
+
22
+ "view" => lambda { |file|
23
+ options = {
24
+ device: @device || Airplay.devices.first,
25
+ interactive: @interactive || false,
26
+ wait: @wait || 3
27
+ }
28
+ Airplay::CLI.view(file, options)
23
29
  }
24
- Airplay::CLI.view(file, options)
25
- }
30
+
31
+ rescue Airplay::Browser::NoDevicesFound
32
+ puts "No devices found."
33
+ rescue Interrupt
34
+ puts "Bye!"
35
+ end
26
36
 
27
37
  # vim: ft=ruby
@@ -1,9 +1,18 @@
1
- require "airplay"
2
1
  require "ruby-progressbar"
2
+ require "airplay"
3
+ require "airplay/cli/image_viewer"
3
4
 
5
+ # Public: Airplay core module
6
+ #
4
7
  module Airplay
8
+ # Public: Airplay CLI module
9
+ #
5
10
  module CLI
6
11
  class << self
12
+ # Public: Lists all the devices to STDOUT
13
+ #
14
+ # Returns nothing.
15
+ #
7
16
  def list
8
17
  Airplay.devices.each do |device|
9
18
  puts <<-EOS.gsub(/^\s{12}/,'')
@@ -15,6 +24,14 @@ module Airplay
15
24
  end
16
25
  end
17
26
 
27
+ # Public: Plays a video given a device
28
+ #
29
+ # video - The url or file path to the video
30
+ # options - Options that include the device
31
+ # * device: The device in which it should run
32
+ #
33
+ # Returns nothing.
34
+ #
18
35
  def play(video, options)
19
36
  device = options[:device]
20
37
  player = device.play(video)
@@ -31,74 +48,34 @@ module Airplay
31
48
  player.wait
32
49
  end
33
50
 
51
+ # Public: Show an image given a device
52
+ #
53
+ # file_or_dir - The url, file path or folder path to the image/s
54
+ # options - Options that include the device
55
+ # * device: The device in which it should run
56
+ # * interactive: Boolean flag to control playback with the
57
+ # arrow keys
58
+ #
59
+ # Returns nothing.
60
+ #
34
61
  def view(file_or_dir, options)
35
62
  device = options[:device]
36
- wait = options[:wait]
63
+ viewer = ImageViewer.new(device, options)
37
64
 
38
65
  if File.directory?(file_or_dir)
39
66
  files = Dir.glob("#{file_or_dir}/*")
40
67
 
41
68
  if options[:interactive]
42
- view_interactive(files)
69
+ viewer.interactive(files)
43
70
  else
44
- view_slideshow(files)
71
+ viewer.slideshow(files)
45
72
  end
46
73
  else
47
- view_image(device, file_or_dir)
74
+ viewer.view(file_or_dir)
48
75
  sleep
49
76
  end
50
77
  end
51
78
 
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
79
  end
103
80
  end
104
81
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airplay-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta4
5
- prerelease: 6
4
+ version: 0.1.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - elcuervo
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-22 00:00:00.000000000 Z
12
+ date: 2013-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: airplay
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.0.0.beta3
21
+ version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.0.0.beta3
29
+ version: 1.0.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: clap
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -86,9 +86,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  none: false
88
88
  requirements:
89
- - - ! '>'
89
+ - - ! '>='
90
90
  - !ruby/object:Gem::Version
91
- version: 1.3.1
91
+ version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
94
  rubygems_version: 1.8.23