« script/electric-sheep-dump-current-screen-ui.pl
↑ Summary
script/electric-sheep-dump-screen-video.pl »
| 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 | |||
| 20 | if( ! Getopt::Long::GetOptions( | ||
| 21 | 'device|d=s' => \$DEVICE, | ||
| 22 | 'verbosity|v=i' => \$VERBOSITY, | ||
| 23 | 'output|o=s'=> \$OUTFILE, | ||
| 24 | 'configfile|c=s' => \$CONFIGFILE, | ||
| 25 | 'help|h' => sub { print STDOUT usage(); exit(0); } | ||
| 26 | ) ){ die usage() } | ||
| 27 | |||
| 28 | if( ! defined $OUTFILE ){ print STDERR usage(); print STDERR "\n$0 : error, an output filename must be specified with '--output'.\n"; exit(1); } | ||
| 29 | if( ! defined $CONFIGFILE ){ print STDERR usage(); print STDERR "\n$0 : error, a configuration file must be specified with '--configfile'.\n"; exit(1); } | ||
| 30 | if( ! -f $CONFIGFILE ){ die "$0 : failed to find config file '$CONFIGFILE'." } | ||
| 31 | |||
| 32 | my $params = { | ||
| 33 | 'configfile' => $CONFIGFILE, | ||
| 34 | 'verbosity' => $VERBOSITY, | ||
| 35 | }; | ||
| 36 | # we assume there is a device connected which the user | ||
| 37 | # must specify by serial, of if just one, we connect to | ||
| 38 | # it without the serial | ||
| 39 | if( defined $DEVICE ){ $params->{'device-serial'} = $DEVICE } | ||
| 40 | else { $params->{'device-is-connected'} = 1 } | ||
| 41 | |||
| 42 | my $client = Android::ElectricSheep::Automator->new($params); | ||
| 43 | if( ! defined($client) ){ die "$0 : failed to instantiate the automator." } | ||
| 44 | |||
| 45 | my $pngimg = $client->dump_current_screen_shot({ | ||
| 46 | 'filename' => $OUTFILE | ||
| 47 | }); | ||
| 48 | if( ! defined($pngimg) ){ die "$0 : failed to dump current screen as a PNG image." } | ||
| 49 | |||
| 50 | print STDOUT "$0 : done, success! Output written to file '$OUTFILE'.\n"; | ||
| 51 | |||
| 52 | sub usage { | ||
| 53 | return "Usage $0 --configfile CONFIGFILE [--output screenshot.png] [--device DEVICE] [--verbosity v]\n" | ||
| 54 | . "\nThis script will dump the current screen as a PNG image to the specified output filename.\n" | ||
| 55 | . "\nExample:\n" | ||
| 56 | . "$0 --configfile config/myapp.conf --output screenshot.png\n" | ||
| 57 | . "\nProgram by Andreas Hadjiprocopis (c) 2025 / bliako at cpan.org / andreashad2 at gmail.com\n\n" | ||
| 58 | ; | ||
| 59 | } | ||
| 60 | |||
| 61 | 1; |