Module: Airplay::CLI

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

Overview

Public: Airplay CLI module

Defined Under Namespace

Classes: ImageViewer

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.helpObject

Public: Shows CLI help

Returns nothing.



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

def help
  Airplay.configuration.load
  puts "    Usage: air [OPTIONS] ACTION [URL OR PATH]\n\n    Command line for the apple tv.\n    Example: air play my_video.mov\n\n    Actions:\n\n    list    - Lists the available devices in the network.\n    help    - This help.\n    version - The current airplay-cli version.\n    play    - Plays a local or remote video.\n    view    - Shows an image or a folder of images, can be an url.\n\n    Options:\n\n    --device      - Name of the device where it should be played (Default: The first one)\n    --wait        - The wait time for playing an slideshow (Default: 3)\n    --interactive - Control the slideshow using left and right arrows.\n\n  EOS\nend\n".gsub!(" "*10, "")

.listObject

Public: Lists all the devices to STDOUT

Returns nothing.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/airplay/cli.rb', line 45

def list
  Airplay.devices.each do |device|
    puts "      * \#{device.name} (\#{device.info.model} running \#{device.info.os_version})\n        ip: \#{device.ip}\n        type: \#{device.type}\n        resolution: \#{device.info.resolution}\n\n    EOS\n  end\nend\n".gsub(/^\s{12}/,'')

.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.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/airplay/cli.rb', line 65

def play(video, options)
  device = options[:device]
  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



113
114
115
116
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
143
# File 'lib/airplay/cli.rb', line 113

def version
  Airplay.configuration.load
  v = Airplay::CLI::VERSION
  puts "\n                      i@@@@@@@@@@@@@@@@@@@@@@@@@\n                    i80000000000000000000000000000\n                  i80000000000000000000000000000000G\n                i8000000000000000000000000000000000000\n              i80000000000000000000000000000000000000000\n      @00000    @0000000000000000000000000000000000000@   000000@\n      @0000008    @000000000000000000000000000000000@   80000000@\n      @001          @00000000000000000000000000000@          100@\n      @001            @0000000000000000000000000@            100@\n      @001              80000000000000000000008              t00@\n      @001                8000000000000000008                t00@\n      @001                  800000000000008                  t00@\n      @001                    G000000000G                    t00@\n      @001                      G00000G                      t00@\n      @001                        L0L                        t00@\n      @001                                                   t00@\n      @001                        air                        t00@\n      @001                       \#{v}                       t00@\n      @001                                                   t00@\n      @001                                                   t00@\n      @001                                                   100@\n      @00000000000000000000000000000000000000000000000000000G000@\n      @000000000000000000000000000000000000000000000000000000000@\n\n  EOS\nend\n"

.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.



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

def view(file_or_dir, options)
  device = options[:device]
  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