App-Automaton
view release on metacpan or search on metacpan
lib/App/Automaton.pm view on Meta::CPAN
* Unshorten: Looks for URLs from several known URL shortener services and expands them to full URLs
* Action
* YouTube: Downloads the video from a YouTube.com url
* TedTalks: Downloads the video from a TedTalks.com url
* NZB: Downloads the NZB file specified in the url
As you can see, these are all geared towards downloading videos. It's the first real world use case that I felt I could really do well.
The plugins can be appear multiple times in a config file, or left out completely. This allows you to download YouTube videos to multiple locations, for instance.
In the future, I picture giving it input that could tell it to do more interesting things. However, as long as commands are coming in over email, I'll leave the security implications minimal.
Obviously, you don't have to use that plugin. If you do, I certainly suggest not using your primary email since the password must be in the config file.
=head1 INSTALLATION
If you are working directly from source, this module can be installed using the Dist::Zilla tools:
sudo dzil install
=head1 CONFIGURATION
Once installed, you will have to create a configuration file for Automaton to operate on. Here is a sample config file that uses all of the currently available plugins.
sources:
automaton email:
bypass: 1
type: IMAP
server: imap.gmail.com
port: 993
account: notyourprimary@emailaccount.com
password: 123456
ssl: yes
delete: 0
file1:
type: File
path: ../input.txt
delete: 0
empty: 1
filters:
unshorten:
type: Unshorten
lib/App/Automaton.pm view on Meta::CPAN
Here is a commented example of an IMAP plugin:
automaton email: # name, can be anything unique within it's section
bypass: 1 # OPTIONAL; if true, this plugin will be skipped, defaults to false
type: IMAP # plguin type: This is how it finds the plugin code, case sensitive
delete: 0 # OPTIONAL; if true, messages will be deleted after reading, defaults to false
# These are passed on to the plugin and have obvious purposes
server: imap.gmail.com
port: 993
account: notyourprimary@emailaccount.com
password: 123456
ssl: yes
The plugins work in generally the same way. They should all respect the bypass flag and, if applicable, the delete flag.
Action plugins will usually have a "target" flag to specify where the downloaded files should be put.
In my personal config, I have my NZB files dropped into my news reader's "watch" folder which will execute that download.
I have my video files targets set to drop right into a folder on my Plex media server, so they are waiting for me at home.
=head1 PLUGINS
Feel free to create additional plugins. I'm currently re-evaluating this, but they must meet the following criteria:
lib/App/Automaton/Plugin/Source/IMAP.pm view on Meta::CPAN
my $in = shift;
my $d = $in->{debug};
my $server = $in->{server} . ':' . $in->{port};
# Create the object
my $imap = Net::IMAP::Simple->new( $server, use_ssl => $in->{ssl} )
|| die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";
# Log on
$imap->login( $in->{account}, $in->{password} )
|| die "imap login failed";
my @output;
# Get messages
my $nm = $imap->select('INBOX');
_logger($d, "Found $nm messages");
for ( my $i = 1; $i <= $nm; $i++ ) {
_logger($d, "getting message $i");
#my $message = $imap->get( $i, 2 ) || $imap->get($i);
t/automaton.t view on Meta::CPAN
require_ok( 'App::Automaton' );
my $yaml_conf = <<EOF;
sources:
automaton email:
type: IMAP
server: imap.gmail.com
port: 993
account: notyourprimary\@email.com
password: goodpassword
ssl: yes
file1:
type: file
path: .
dir1:
type: directory
path: /var/tmp/input
EOF
my $conf = {
'sources' => {
'automaton email' => {
'password' => 'goodpassword',
'server' => 'imap.gmail.com',
'type' => 'IMAP',
'ssl' => 'yes',
'port' => '993',
'account' => 'notyourprimary@email.com'
},
'file1' => {
'path' => '.',
'type' => 'file'
},
t/plugin/source/imap.t view on Meta::CPAN
use Test::More;
use Data::Dumper;
use strict;
use warnings;
require_ok( 'App::Automaton::Plugin::Source::IMAP');
my $conf = {
'password' => 'goodpassword',
'server' => 'imap.gmail.com',
'type' => 'IMAP',
'ssl' => 'yes',
'port' => '993',
'account' => 'notyourprimary@email.com'
};
ok(App::Automaton::Plugin::Source::IMAP->new(), 'new');
done_testing();
( run in 1.139 second using v1.01-cache-2.11-cpan-49f99fa48dc )