Module: Airplay::CLI

Defined in:
lib/airplay/cli.rb,
lib/airplay/cli/doctor.rb,
lib/airplay/cli/version.rb,
lib/airplay/cli/image_viewer.rb

Overview

Public: Airplay CLI module

Defined Under Namespace

Classes: Doctor, ImageViewer

Constant Summary collapse

VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.doctorObject



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/airplay/cli.rb', line 93

def doctor
  puts <<-EOS.gsub!(" "*10, "")

    This will run some basic tests on your network trying to find errors
    and debug information to help fix them.

  EOS

  who = Airplay::CLI::Doctor.new

  puts "Running dns-sd tests:"
  who.information
end

.helpObject

Public: Shows CLI help

Returns nothing.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/airplay/cli.rb', line 17

def help
  Airplay.configuration.load
  puts <<-EOS.gsub!(" "*10, "")
    Usage: air [OPTIONS] ACTION [URL OR PATH]

    Command line for the apple tv.
    Example: air play my_video.mov

    Actions:

    list    - Lists the available devices in the network.
    help    - This help.
    version - The current airplay-cli version.
    play    - Plays a local or remote video.
    view    - Shows an image or a folder of images, can be an url.
    doctor  - Shows some debug information to trace bugs.

    Options:

    --device      - Name of the device where it should be played (Default: The first one)
    --wait        - The wait time for playing an slideshow (Default: 3)
    --interactive - Control the slideshow using left and right arrows.
    --password    - Adds the device password
    --url         - Allows you to specify an Apple TV url

  EOS
end

.listObject

Public: Lists all the devices to STDOUT

Returns nothing.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/airplay/cli.rb', line 49

def list
  Airplay.devices.each do |device|
    puts <<-EOS.gsub(/^\s{12}/,'')
      * #{device.name} (#{device.info.model} running #{device.info.os_version})
        ip: #{device.ip}
        mac: #{device.id}
        password?: #{device.password? ? "yes" : "no"}
        type: #{device.type}
        resolution: #{device.info.resolution}

    EOS
  end
end

.play(video, options) ⇒ Object

Public: Plays a video given a device

video - The url or file path to the video options - Options that include the device

* device: The device in which it should run

Returns nothing.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/airplay/cli.rb', line 71

def play(video, options)
  device = options[:device]
  password = options[:password]
  url = options[:url]

  Airplay.devices.add("Apple TV", url) if url
  device.password = password if password

  player = device.play(video)
  puts "Playing #{video}"
  bar = ProgressBar.create(
    title: device.name,
    format: "%a [%B] %p%% %t"
  )

  player.progress -> playback {
    bar.progress = playback.percent if playback.percent
  }

  player.wait
end

.versionObject

Public: Shows the current CLI version

Returns nothing



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/airplay/cli.rb', line 148

def version
  Airplay.configuration.load
  v = Airplay::CLI::VERSION
  puts <<-EOS

                      i@@@@@@@@@@@@@@@@@@@@@@@@@
                    i80000000000000000000000000000
                  i80000000000000000000000000000000G
                i8000000000000000000000000000000000000
              i80000000000000000000000000000000000000000
      @00000    @0000000000000000000000000000000000000@   000000@
      @0000008    @000000000000000000000000000000000@   80000000@
      @001          @00000000000000000000000000000@          100@
      @001            @0000000000000000000000000@            100@
      @001              80000000000000000000008              t00@
      @001                8000000000000000008                t00@
      @001                  800000000000008                  t00@
      @001                    G000000000G                    t00@
      @001                      G00000G                      t00@
      @001                        L0L                        t00@
      @001                                                   t00@
      @001                        air                        t00@
      @001                       #{v}                       t00@
      @001                                                   t00@
      @001                                                   t00@
      @001                                                   100@
      @00000000000000000000000000000000000000000000000000000G000@
      @000000000000000000000000000000000000000000000000000000000@

  EOS
end

.view(file_or_dir, options) ⇒ Object

Public: Show an image given a device

file_or_dir - The url, file path or folder path to the image/s options - Options that include the device

* device: The device in which it should run
* interactive: Boolean flag to control playback with the
               arrow keys

Returns nothing.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/airplay/cli.rb', line 117

def view(file_or_dir, options)
  device = options[:device]
  password = options[:password]
  url = options[:url]

  if url
    Airplay.configure { |c| c.autodiscover = false }
    device = Airplay.devices.add("Apple TV", url)
  end
  device.password = password if password

  viewer = ImageViewer.new(device, options)

  if File.directory?(file_or_dir)
    files = Dir.glob("#{file_or_dir}/*")

    if options[:interactive]
      viewer.interactive(files)
    else
      viewer.slideshow(files)
    end
  else
    viewer.view(file_or_dir)
    sleep
  end
end