script/electric-sheep-dump-screen-video.pl untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 94 CC 1 SCAR 6.9
CC
1
Cov
0%
usage
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 use strict;
4 use warnings;
5  
6 our $VERSION = '0.09';
7  
8 use lib ('blib/lib');
9  
10 use Getopt::Long qw(:config no_ignore_case);
11 use Data::Roundtrip qw/perl2dump perl2json no-unicode-escape-permanently/;
12  
13 use Android::ElectricSheep::Automator;
14  
15 my $VERBOSITY = 0; # we need verbosity of 10 (max), so this is not used
16 my $DEVICE;
17 my $CONFIGFILE;
18 my $OUTFILE;
19 my %OTHEROPTIONS;
20 if( ! Getopt::Long::GetOptions(
21 'time-limit=s' => sub { $OTHEROPTIONS{$_[0]} = $_[1] },
22 'bit-rate=s' => sub { $OTHEROPTIONS{$_[0]} = $_[1] },
23 'width=s' => sub { $OTHEROPTIONS{'size'}->{$_[0]} = $_[1] },
24 'height=s' => sub { $OTHEROPTIONS{'size'}->{$_[0]} = $_[1] },
25 'bugreport' => sub { $OTHEROPTIONS{'size'}->{$_[0]} = 1 },
26  
27 'device|d=s' => \$DEVICE,
28 'verbosity|v=i' => \$VERBOSITY,
29 'output|o=s'=> \$OUTFILE,
30 'configfile|c=s' => \$CONFIGFILE,
31 'help|h' => sub { print STDOUT usage(); exit(0); }
32 ) ){ die usage() }
33  
34 if( ! defined $OUTFILE ){ print STDERR usage(); print STDERR "\n$0 : error, an output filename must be specified with '--output'.\n"; exit(1); }
35 if( ! defined $CONFIGFILE ){ print STDERR usage(); print STDERR "\n$0 : error, a configuration file must be specified with '--configfile'.\n"; exit(1); }
36 if( ! -f $CONFIGFILE ){ die "$0 : failed to find config file '$CONFIGFILE'." }
37  
38 if( exists($OTHEROPTIONS{'size'}) ){ for (qw/width height/){ if( ! exists($OTHEROPTIONS{'size'}->{$_}) || ! defined($OTHEROPTIONS{'size'}->{$_}) ){ print STDERR usage(); print STDERR "\n$0 : error, the output video size must be specified completely with 'width' AND 'height'. '$_' is missing.\n"; exit(1); } } }
39  
40 my $params = {
41 'configfile' => $CONFIGFILE,
42 'verbosity' => $VERBOSITY,
43 };
44 # we assume there is a device connected which the user
45 # must specify by serial, of if just one, we connect to
46 # it without the serial
47 if( defined $DEVICE ){ $params->{'device-serial'} = $DEVICE }
48 else { $params->{'device-is-connected'} = 1 }
49  
50 my $client = Android::ElectricSheep::Automator->new($params);
51 if( ! defined($client) ){ die "$0 : failed to instantiate the automator." }
52  
53 if( $client->dump_current_screen_video({
54 %OTHEROPTIONS,
55 'filename' => $OUTFILE,
56 }) ){ die "$0 : failed to record current screen as an MP4 video." }
57  
58 print STDOUT "$0 : done, success! Output written to file '$OUTFILE'.\n";
59  
60 sub usage {
61 return "Usage $0 --configfile CONFIGFILE --output video.mp4 [--bit-rate BITSperSECONDS] [--time-limit SECONDS] [--width W --height H] [--bugreport] [--device DEVICE] [--verbosity v]\n"
62 . "\nThis script will record the current screen as an MP4 video to the specified output filename with some optional settings like duration (--time-limit SECONDS), --bit-rate BPS, --bugreport, etc.\n"
63 . "\nExample:\n"
64 . "$0 --configfile config/myapp.conf --output video.mp4\n"
65 . "$0 --configfile config/myapp.conf --output video.mp4 --width 1280 --height 720 --bit-rate 20000000\n"
66 . "\nProgram by Andreas Hadjiprocopis (c) 2025 / bliako at cpan.org / andreashad2 at gmail.com\n\n"
67 ;
68 }
69  
70 1;