capa 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '056684bd0e821dfdd60e6e3f8164ff46bea56991e64a9220d124165a2e5ef539'
4
- data.tar.gz: afcfed449e5f6ff18782afbca68356513b1015232be02624c38630ef2a10ec62
3
+ metadata.gz: a5774c2dc81775fcb01070ec5f107ee6d6619c8820a877b0c55dd6509d1266f9
4
+ data.tar.gz: 70cedf1db2030087a9bc1e2100a1aa0e817fdf3b66c8f5028645441f86cf2515
5
5
  SHA512:
6
- metadata.gz: 8705c6d0974c4833ee1c0dd88c9cd0afa7c430430e225c97bfa6eb5511c8f53f877f4ea11a8eaf162d45ae43ec7cf0878b7b3c9c20ac81e42f1d1809add19910
7
- data.tar.gz: dad80eedc9b2a4863e817afa004a5bcb18fbbdad0c67361738796ded0dfd65cf2dc84ad3338e79421af848c7aee2bcfc82046516972a52a95f2f1c0475ea4553
6
+ metadata.gz: 5f2f11dee1c55172dc0ac094d97dd1ead53ef5b8185435b9174a984f0b812ef9eb98bb3e40988281d42d5c508ce1de3243af0966df4e01f9b6e1c2888c668fc1
7
+ data.tar.gz: 909ceb3236834024a08f0e16daddb59df46499e83bdd8a728f0d44fd4ad3b192fcd0c6af64e5b628d1d2e384baddc81422d3b40edc933c8357fbc3926dea3ab2
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/capa'
@@ -13,15 +13,18 @@ options = {}
13
13
 
14
14
  # Set up the options you are looking for
15
15
  optparse = OptionParser.new do |opts|
16
- explanation = "> The command #{"$ capa-ios".bold} will generate a video and a GIF from the iOS Simulator\
17
- > The command #{"$ capa-android".bold} will generate a video and a GIF from the Android Emulator .\n\n"
16
+ explanation = "> #{"$ capa".bold} will generate a video and a GIF from the iOS Simulator or the Android Emulator. #{"capa".bold} will try to infer the platform. Alternatively you can select which platform you wish to record in.\n\n"
18
17
  usage = "Usage: #{$0} [options]".bold
19
18
  opts.banner = "#{explanation} #{usage}"
20
19
 
21
- opts.on( '-o', '--output NAME', "Output filename. Defaults to 'recording'" ) do |o|
20
+ opts.on( '-o', '--output NAME', "Output filename. Defaults to #{"recording".italic}" ) do |o|
22
21
  options[:output] = o
23
22
  end
24
23
 
24
+ opts.on( '-p', '--platform NAME', "Available platforms: #{"ios".italic} and #{"android".italic}" ) do |o|
25
+ options[:platform] = o
26
+ end
27
+
25
28
  opts.on("-v", "--version", "Display version") do
26
29
  puts Capa::VERSION
27
30
  exit
@@ -36,4 +39,22 @@ end
36
39
  # The parse! method also removes any options it finds from ARGV.
37
40
  optparse.parse!
38
41
 
39
- @video_filename = "#{options[:output] || 'recording'}.mp4"
42
+ video_filename = "#{options[:output] || 'recording'}.mp4"
43
+
44
+ recorder_factory = RecorderFactory.new(filename: video_filename)
45
+ platform = platform = options[:platform] || recorder_factory.infer_platform
46
+ recorder = recorder_factory.create(from_platform: platform)
47
+
48
+ abort("Please choose a platform. Help: #{$0} -h") if recorder.nil?
49
+
50
+ generator = GIFGenerator.new(input_video: video_filename, output_gif: "#{video_filename}.gif")
51
+
52
+ begin
53
+ recorder.record
54
+ rescue Capa::UserAbort
55
+ puts 'Exiting...'
56
+ recorder.cancel
57
+ exit
58
+ end
59
+
60
+ generator.generate
@@ -1,7 +1,8 @@
1
1
  require_relative 'string'
2
2
  require_relative 'helper'
3
+ require_relative 'recorder_factory'
3
4
 
4
- class EmulatorRecorder
5
+ class EmulatorRecorder < Recorder
5
6
  def initialize(filename: '')
6
7
  abort('Please provide a name for the video') if filename.blank?
7
8
  @filename = filename
@@ -23,25 +24,28 @@ class EmulatorRecorder
23
24
  "Tip: Galaxy Nexus works great!") if /err=-38/ =~ message
24
25
  end
25
26
 
26
- puts 'Capturing video... Press ENTER to save'
27
+ puts 'Capturing video from the Android Emulator... Press ENTER to save'
27
28
  p = gets.chomp
28
29
  `adb shell killall -SIGINT screenrecord`
29
30
  sleep 0.5
30
31
  pull_video_from_emulator
31
32
  end
32
33
 
34
+ def cancel
35
+ `adb shell killall screenrecord`
36
+ end
37
+
33
38
  def pull_video_from_emulator
34
39
  # We can specify the device, in case there is more than one connected: -s emulator-5554
35
40
  puts `adb pull #{emulator_video_path}`
36
41
  end
37
42
 
38
- private
39
-
40
43
  def emulator_video_path
41
44
  "/sdcard/#{@filename}"
42
45
  end
43
46
 
44
47
  def can_record?
48
+ return false if command?('adb') == false
45
49
  # Example response
46
50
  #
47
51
  # "List of devices attached\n
@@ -2,7 +2,6 @@ module Capa
2
2
  class UserAbort < StandardError; end
3
3
  end
4
4
 
5
-
6
5
  def command?(command)
7
6
  system("which #{command} > /dev/null 2>&1")
8
7
  end
@@ -0,0 +1,34 @@
1
+ class RecorderFactory
2
+ def initialize(filename: '')
3
+ @recorders = {
4
+ 'ios' => SimulatorRecorder.new(filename: filename),
5
+ 'android' => EmulatorRecorder.new(filename: filename)
6
+ }
7
+ end
8
+
9
+ def infer_platform
10
+ available_platforms = @recorders
11
+ .select { |key, recorder| recorder.can_record? }
12
+ .map { |key, recorder| key }
13
+
14
+ return available_platforms.first if available_platforms.count == 1
15
+ end
16
+
17
+ def create(from_platform: '')
18
+ @recorders[from_platform] unless from_platform.nil?
19
+ end
20
+ end
21
+
22
+ class Recorder
23
+ def record
24
+ raise 'not implemented'
25
+ end
26
+
27
+ def cancel
28
+ raise 'not implemented'
29
+ end
30
+
31
+ def can_record?
32
+ raise 'not implemented'
33
+ end
34
+ end
@@ -1,13 +1,14 @@
1
1
  require_relative 'string'
2
+ require_relative 'recorder_factory'
2
3
 
3
- class SimulatorRecorder
4
+ class SimulatorRecorder < Recorder
4
5
  def initialize(filename: '')
5
6
  abort('Please provide a name for the video') if filename.blank?
6
7
  @filename = filename
7
8
  end
8
9
 
9
10
  def record
10
- abort unless can_record?
11
+ abort("You need to open the iOS Simulator") unless can_record?
11
12
 
12
13
  Signal.trap("SIGINT") { raise Capa::UserAbort }
13
14
  Signal.trap("SIGTSTP") { raise Capa::UserAbort }
@@ -16,16 +17,21 @@ class SimulatorRecorder
16
17
  `xcrun simctl io booted recordVideo #{@filename}`
17
18
  end
18
19
 
19
- puts 'Capturing video... Press ENTER to save'
20
+ puts 'Capturing video from the iOS Simulator... Press ENTER to save'
20
21
  p = gets.chomp
21
22
  `killall -SIGINT simctl`
22
23
  end
23
24
 
24
- private
25
+ def cancel
26
+ if system('pgrep simctl > /dev/null')
27
+ `killall simctl`
28
+ end
29
+ end
25
30
 
26
31
  def can_record?
32
+ return false if command?('xcrun') == false
27
33
  # Will output 'No devices are booted.' if Simulator.app is closed
28
- `xcrun simctl io booted enumerate`
34
+ `xcrun simctl io booted enumerate > /dev/null 2>&1`
29
35
  $?.exitstatus == 0
30
36
  end
31
37
  end
@@ -1,3 +1,3 @@
1
1
  module Capa
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Salom
@@ -14,17 +14,16 @@ description: capa can record animated GIFs (and videos) from the iOS Simulator a
14
14
  the Android Emulator because a GIF is worth a thousand lines of code.
15
15
  email: alex.salom@gmail.com
16
16
  executables:
17
- - capa-ios
18
- - capa-android
17
+ - capa
19
18
  extensions: []
20
19
  extra_rdoc_files: []
21
20
  files:
22
- - bin/capa-android
23
- - bin/capa-ios
21
+ - bin/capa
24
22
  - lib/capa.rb
25
23
  - lib/capa/emulator_recorder.rb
26
24
  - lib/capa/gif_generator.rb
27
25
  - lib/capa/helper.rb
26
+ - lib/capa/recorder_factory.rb
28
27
  - lib/capa/simulator_recorder.rb
29
28
  - lib/capa/string.rb
30
29
  - lib/capa/version.rb
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require_relative '../lib/capa'
4
-
5
- abort('Please install adb https://developer.android.com/studio/') unless command?('adb')
6
- abort('Please install gifify: https://github.com/vvo/gifify') unless command?('gifify')
7
-
8
- recorder = EmulatorRecorder.new(filename: @video_filename)
9
- generator = GIFGenerator.new(input_video: @video_filename, output_gif: "#{@video_filename}.gif")
10
-
11
- begin
12
- recorder.record
13
- rescue Capa::UserAbort
14
- puts 'Exiting...'
15
- `adb shell killall screenrecord`
16
- exit
17
- end
18
-
19
- generator.generate
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require_relative '../lib/capa'
4
-
5
- abort('Please install gifify: https://github.com/vvo/gifify') unless command?('gifify')
6
-
7
- recorder = SimulatorRecorder.new(filename: @video_filename)
8
- generator = GIFGenerator.new(input_video: @video_filename, output_gif: "#{@video_filename}.gif")
9
-
10
- begin
11
- recorder.record
12
- rescue Capa::UserAbort
13
- puts 'Exiting...'
14
- if system('pgrep simctl > /dev/null')
15
- `killall simctl`
16
- end
17
- exit
18
- end
19
-
20
- generator.generate