capa 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '05080bdfeb1a0581396527263a2f51dcdeb03fc3a67a7f34e2cc6de46f40f49c'
4
+ data.tar.gz: 99aef93f6bb49bee183c4598bdfcb326fc972c272cb06a0dc711ccade633b4f3
5
+ SHA512:
6
+ metadata.gz: b1e30a080b60d3c9927ec4daa264f13163d32eaf6cb81baf3a2523dc5aee3989e7cfdd9dd3dc538309361ba6bb1c8f0253d578b20484bec140deb25490eae8e2
7
+ data.tar.gz: e5d12d20d0fb0145cc516852e282af52f27056d2e303289a29ccec0b81463b2f208351f9ea8ed6385c4c54ce9d5f06280d5696b0d17485b7fe4130223b03b144
data/bin/capa-android ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/capa/emulator_recorder'
4
+ require_relative '../lib/capa/gif_generator'
5
+
6
+ def command?(command)
7
+ system("which #{command} > /dev/null 2>&1")
8
+ end
9
+
10
+ abort('Please install adb') unless command?('adb')
11
+ abort('Please install gifify: https://github.com/vvo/gifify') unless command?('gifify')
12
+
13
+ @video_filename = ARGV.count == 1 ? ARGV[0] : 'video.mp4'
14
+
15
+ recorder = EmulatorRecorder.new(filename: @video_filename)
16
+ generator = GIFGenerator.new(input_video: @video_filename, output_gif: "#{@video_filename}.gif")
17
+
18
+ Signal.trap("SIGINT") do
19
+ recorder.stop
20
+ recorder.pull_video_from_emulator
21
+ generator.generate
22
+ exit 0
23
+ end
24
+
25
+ video = recorder.record
data/bin/capa-ios ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/capa/simulator_recorder'
4
+ require_relative '../lib/capa/gif_generator'
5
+
6
+ def command?(command)
7
+ system("which #{command} > /dev/null 2>&1")
8
+ end
9
+
10
+ abort('Please install gifify: https://github.com/vvo/gifify') unless command?('gifify')
11
+
12
+ @video_filename = ARGV.count == 1 ? ARGV[0] : 'video.mp4'
13
+
14
+ Signal.trap("SIGINT") do
15
+ generator = GIFGenerator.new(input_video: @video_filename, output_gif: "#{@video_filename}.gif")
16
+ generator.generate
17
+ end
18
+
19
+ recorder = SimulatorRecorder.new(filename: @video_filename)
20
+ video = recorder.record
data/lib/capa.rb ADDED
@@ -0,0 +1,3 @@
1
+ require_relative 'lib/simulator_recorder'
2
+ require_relative 'lib/emulator_recorder'
3
+ require_relative 'lib/gif_generator'
@@ -0,0 +1,45 @@
1
+ require_relative 'string'
2
+
3
+ class EmulatorRecorder
4
+ def initialize(filename: '')
5
+ abort('Please provide a name for the video') if filename.blank?
6
+ @filename = filename
7
+ end
8
+
9
+ def record
10
+ abort("You need exactly one emulator or device connected") unless can_record?
11
+ puts 'Capturing video... Use CTRL+C to save'
12
+ # Might want to add '--size 720x1280' flag. That's the maximum permitted size for video recordings
13
+ # We can specify the device, in case there is more than one connected: -s emulator-5554
14
+ message = `adb shell screenrecord --verbose #{emulator_video_path}`
15
+
16
+ abort("Maximum permitted resolution is 720x1280. Minimum Android version is Marshmallow.\n"\
17
+ "Please choose a different device.\n"\
18
+ "Tip: Galaxy Nexus works great!") if /err=-38/ =~ message
19
+ end
20
+
21
+ def stop
22
+ `killall -SIGINT adb`
23
+ end
24
+
25
+ def pull_video_from_emulator
26
+ # We can specify the device, in case there is more than one connected: -s emulator-5554
27
+ puts `adb pull #{emulator_video_path}`
28
+ end
29
+
30
+ private
31
+
32
+ def emulator_video_path
33
+ "/sdcard/#{@filename}"
34
+ end
35
+
36
+ def can_record?
37
+ # Example response
38
+ #
39
+ # "List of devices attached\n
40
+ # emulator-5554 device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:1\n
41
+ # emulator-5556 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:2\n\n"
42
+ #
43
+ `adb devices -l`.split("\n").count == 2
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'string'
2
+
3
+ class GIFGenerator
4
+ def initialize(input_video: '', output_gif: '')
5
+ abort('Please provide a video to generate a GIF from') if input_video.blank?
6
+ abort('Please provide a name for the GIF') if output_gif.blank?
7
+ @input_video = input_video
8
+ @output_gif = output_gif
9
+ end
10
+
11
+ def generate
12
+ abort("File not found: #{@input_video}") unless File.exists?(@input_video)
13
+ puts "Generating GIF, please wait..."
14
+ `gifify #{@input_video} -o #{@output_gif} --resize 300:-1 --colors 220 --fps 7`
15
+ video_directory = File.dirname(Dir.pwd)
16
+ puts "Video: #{video_directory}/#{@input_video}"
17
+ puts "GIF: #{video_directory}/#{@output_gif}"
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'string'
2
+
3
+ class SimulatorRecorder
4
+ def initialize(filename: '')
5
+ abort('Please provide a name for the video') if filename.blank?
6
+ @filename = filename
7
+ end
8
+
9
+ def record
10
+ abort unless can_record?
11
+ puts 'Capturing video... Use CTRL+C to save'
12
+ `xcrun simctl io booted recordVideo #{@filename}`
13
+ return @filename
14
+ end
15
+
16
+ private
17
+
18
+ def can_record?
19
+ # Will output 'No devices are booted.' if Simulator.app is closed
20
+ `xcrun simctl io booted enumerate`
21
+ $?.exitstatus == 0
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def blank?
3
+ self.nil? || self.empty?
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Salom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: capa can record animated GIFs (and videos) from the iOS Simulator and
14
+ the Android Emulator because a GIF is worth a thousand lines of code.
15
+ email: alex.salom@gmail.com
16
+ executables:
17
+ - capa-ios
18
+ - capa-android
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/capa-android
23
+ - bin/capa-ios
24
+ - lib/capa.rb
25
+ - lib/capa/emulator_recorder.rb
26
+ - lib/capa/gif_generator.rb
27
+ - lib/capa/simulator_recorder.rb
28
+ - lib/capa/string.rb
29
+ homepage: https://github.com/crvshlab/capa
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.7.3
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Record animated GIFs (and videos) from the iOS Simulator and the Android
53
+ Emulator.
54
+ test_files: []