Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pushsafer.com support #131

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ plexWatch - 0.3.2 (2014-11-19)
**Supported Push Notifications**
* Email
* https://pushover.net
* https://www.pushsafer.com
* https://prowlapp.com
* http://growl.info/ (via GrowlNotify @ http://growl.info/downloads#generaldownloads)
* https://twitter.com/ (create a new app @ https://dev.twitter.com/apps)
Expand All @@ -38,7 +39,7 @@ plexWatch - 0.3.2 (2014-11-19)
* notify when a user pauses watching a video
* notify when a user resumes watching a video
* notify on recently added content to a PMS server
* notifies via email, prowl, pushover, growl, twitter, boxcar, pushbullet, GNTP and/or a log file
* notifies via email, prowl, pushover, pushsafer, growl, twitter, boxcar, pushbullet, GNTP and/or a log file
* enable/disable notifications per provider & per notification type (start, stop, paush, resume, recently added)
* backed by a SQLite DB (for state and history)
* CLI to query watched videos, videos being watched and stats on time watched per user
Expand Down Expand Up @@ -147,10 +148,11 @@ $debug_logging = 1; ## logs to $data_dir/debug.log ( only really helps debug IP

```bash
$notify = {...
* to enable a provider, i.e. file, prowl, pushover
* to enable a provider, i.e. file, prowl, pushover, pushsafer
set 'enabled' => 1, under selected provider
* Prowl : 'apikey' required
* Pushover : 'token' and 'user' required
* Pushsafer : 'privatekey' required
* Growl : 'script' required :: GrowlNotify from http://growl.info/downloads (GNTP replaces this)
* twitter : 'consumer_key', 'consumer_secret', 'access_token', 'access_token_secret' required
* boxcar : 'email' required
Expand Down Expand Up @@ -581,7 +583,7 @@ $backup_opts = {
--debug hit and miss - not very useful

OPTIONS
--notify This will send you a notification through prowl, pushover, boxcar, pushbullet, growl and/or twitter. It will also log the event to a file and to the database. This is the default if no
--notify This will send you a notification through prowl, pushover, pushsafer, boxcar, pushbullet, growl and/or twitter. It will also log the event to a file and to the database. This is the default if no
options are given.

--watched Print a list of watched content from all users.
Expand Down
8 changes: 5 additions & 3 deletions README.windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ http://forums.plexapp.com/index.php/topic/72552-plexwatch-plex-notify-script-sen

**Supported Push Notifications**
* https://pushover.net
* https://www.pushsafer.com
* https://prowlapp.com
* http://growl.info/ (via GrowlNotify @ http://growl.info/downloads#generaldownloads)
* https://twitter.com/ (create a new app @ https://dev.twitter.com/apps)
Expand All @@ -21,7 +22,7 @@ http://forums.plexapp.com/index.php/topic/72552-plexwatch-plex-notify-script-sen
* notify when a user starts watching a video
* notify when a user stops watching a video
* notify on recently added content to a PMS server
* notifies via prowl, pushover, growl, twitter, boxcar, GNTP and/or a log file
* notifies via prowl, pushover, pushsafer, growl, twitter, boxcar, GNTP and/or a log file
* enable/disable notifications per provider & per notification type (watching, watched, recently added)
* backed by a SQLite DB (for state and history)
* CLI to query watched videos, videos being watched and stats on time watched per user
Expand Down Expand Up @@ -117,10 +118,11 @@ $debug_logging = 1; ## logs to $data_dir/debug.log ( only really helps debug IP

```bash
$notify = {...
* to enable a provider, i.e. file, prowl, pushover
* to enable a provider, i.e. file, prowl, pushover, pushsafer
set 'enabled' => 1, under selected provider
* Prowl : 'apikey' required
* Pushover : 'token' and 'user' required
* Pushsafer : 'privatekey' required
* Growl : 'script' required :: GrowlNotify from http://growl.info/downloads (GNTP replaces this)
* twitter : 'consumer_key', 'consumer_secret', 'access_token', 'access_token_secret' required
* boxcar : 'email' required
Expand Down Expand Up @@ -512,7 +514,7 @@ $backup_opts = {
--debug hit and miss - not very useful

OPTIONS
--notify This will send you a notification through prowl, pushover, boxcar, growl and/or twitter. It will also log the event to a file and to the database. This is the default if no
--notify This will send you a notification through prowl, pushover, pushsafer, boxcar, growl and/or twitter. It will also log the event to a file and to the database. This is the default if no
options are given.

--watched Print a list of watched content from all users.
Expand Down
14 changes: 14 additions & 0 deletions config.pl-dist
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ $notify = {
'title' => '{user}',
'sound' => 'intermission',
},

'pushsafer' => {
'enabled' => 0, ## set to 1 to enable Pushover
'push_recentlyadded' => 0,
'push_watched' => 0,
'push_watching' => 0,
'push_paused' => 0,
'push_resumed' => 0,
'privatekey' => 'Private or Alias Key', ## your Private or Alias Key
'title' => '{user}',
'device' => '',
'sound' => '',
'vibration' => '',
},

'growl' => {
'enabled' => 0, ## set to 1 to enable local growl (You should probably used GNTP - growl supported for multiple platforms - below)
Expand Down
14 changes: 14 additions & 0 deletions config.pl-dist-win32
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ $notify = {
'title' => '{user}',
'sound' => 'intermission',
},

'pushsafer' => {
'enabled' => 0, ## set to 1 to enable Pushsafer
'push_recentlyadded' => 0,
'push_watched' => 0,
'push_watching' => 0,
'push_paused' => 0,
'push_resumed' => 0,
'privatekey' => 'Private or Alias Key', ## your Private or Alias Key
'title' => '{user}',
'device' => '',
'sound' => '',
'vibration' => '',
},

'growl' => {
'enabled' => 0, ## set to 1 to enable local growl (You should probably used GNTP - growl supported for multiple platforms - below)
Expand Down
68 changes: 67 additions & 1 deletion plexWatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,7 @@ ()
{ 'name' => 'GNTP', 'definition' => 'INTEGER',},
{ 'name' => 'EMAIL', 'definition' => 'INTEGER',},
{ 'name' => 'pushover', 'definition' => 'INTEGER',},
{ 'name' => 'pushsafer', 'definition' => 'INTEGER',},
{ 'name' => 'pushbullet', 'definition' => 'INTEGER',},
{ 'name' => 'pushalot', 'definition' => 'INTEGER',},
{ 'name' => 'boxcar', 'definition' => 'INTEGER',},
Expand Down Expand Up @@ -2389,6 +2390,70 @@ ()
return 1; ## success
}

sub NotifyPushsafer() {
my $provider = 'pushsafer';

#my $alert = shift;
my $info = shift;
my ($alert) = &formatAlert($info,$provider);

my $alert_options = shift;

if ($provider_452->{$provider}) {
if ($options{'debug'}) { print uc($provider) . " 452: backing off\n"; }
return 0;
}

my %po = %{$notify->{pushsafer}};
my $ua = LWP::UserAgent->new( ssl_opts => {
verify_hostname => 0,
SSL_verify_mode => SSL_VERIFY_NONE,
});
$ua->timeout(20);
$po{'message'} = $alert;

## Pushsafer title is AppName by default. If there is a real title for push type, It's 'AppName: push_type'

## allow formatting of appname
$po{'title'} = '{user}' if $po{'title'} eq $appname; ## force {user} if people still use $appname in config -- forcing update with the need to modify config.
my $format = $po{'title'};


if ($format =~ /\{.*\}/) {
my $regex = join "|", keys %{$alert_options};
$regex = qr/$regex/;
$po{'title'} =~ s/{($regex)}/$alert_options->{$1}/g;
$po{'title'} =~ s/{\w+}//g; ## remove any {word} - templates that failed
$po{'title'} = $appname if !$po{'title'}; ## replace appname if empty
}
$po{'title'} .= ': ' . $push_type_titles->{$alert_options->{'push_type'}} if $alert_options->{'push_type'};
$po{'title'} .= ' ' . ucfirst($alert_options->{'item_type'}) if $alert_options->{'item_type'};

my $response = $ua->post( "https://www.pushsafer.com/api", [
"k" => $po{'privatekey'},
"t" => $po{'title'},
"m" => $po{'message'},
'd' => $po{'device'},
's' => $po{'sound'},
'v' => $po{'vibration'},
]);
my $content = $response->decoded_content();


if ($content !~ /\"status\":1/) {
print STDERR "Failed to post Pushsafer notification -- $po{'message'} result:$content\n";
$provider_452->{$provider} = 1;
my $msg452 = uc($provider) . " failed: $alert - setting $provider to back off additional notifications\n";
&ConsoleLog($msg452,,1);

return 0;
}

my $dmsg = uc($provider) . " Notification successfully posted.\n" if $debug;
&DebugLog($dmsg) if $dmsg && $debug;
return 1; ## success
}

sub NotifyBoxcar() {
my $provider = 'boxcar';
## this will try to notifiy via box car
Expand Down Expand Up @@ -3594,6 +3659,7 @@ ()
prowl => \&NotifyProwl,
growl => \&NotifyGrowl,
pushover => \&NotifyPushOver,
pushsafer => \&NotifyPushsafer,
twitter => \&NotifyTwitter,
boxcar => \&NotifyBoxcar,
boxcar_v2 => \&NotifyBoxcar_V2,
Expand Down Expand Up @@ -4350,7 +4416,7 @@ =head1 OPTIONS

=item B<--notify>

This will send you a notification through prowl, pushover, boxcar, growl and/or twitter. It will also log the event to a file and to the database.
This will send you a notification through prowl, pushover, pushsafer, boxcar, growl and/or twitter. It will also log the event to a file and to the database.
This is the default if no options are given.

=item B<--watched>
Expand Down
Binary file added screenshots/iOS-plexWatch_pushsafer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.