plexWatch - Plex Notify Script - Send Push Alerts On New Sessions and Stopped

One small difference I am noticing since last night's update is the formatting of the notification. For instance with Prowl it has typically been:

$appname $pushtitle

$user $state $title $platform etc 

but what I see now is username as the $appname and $state as the push $title:

$user $state

$title $platform etc 
 

Also, if you are still planning on keeping the $appname as part of the script can it be an available option for the email subject too? I've personally been formatting my notifications as:

$appname $pushtitle //I make $appname my server or domain name and the $pushtitle "Notification"

$user $state $title $platform etc
 

One small difference I am noticing since last night's update is the formatting of the notification. For instance with Prowl it has typically been:

$appname $pushtitle

$user $state $title $platform etc 

but what I see now is username as the $appname and $state as the push $title:

$user $state

$title $platform etc 
 

Almost correct :) It is not $state though, it will uses the push_title. 

$user $push_title

$title $platform etc

This is the default now, however it can be changed back to the original if you really want it to. The only caveat is if you keep set $appname as the application in prowl, i.e. 'application' => $appname, then it will override that with the '{user}'. So if you really want the original behaviour, you will have to set the $appname to something more unique and then set the application name in the provider yourself. This is what you have to do to the config.pl

# set appname to something unique ( that will not be used in the application name of the push event )
$appname = 'PlexWatchApp'; # mainly just internally used and may be removed from further releases anyways

# change the alert_format back to include '{user} watched...' for all types
$alert_format = {
    'start'    =>  '{user} watched {title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] {ip_address}',
      .....

# change the prowl application from either $appname or '{user}' to:
$notify = {
...
 'prowl' => {
    ...
       'application' => 'plexWatch',

Also, if you are still planning on keeping the $appname as part of the script can it be an available option for the email subject too? I've personally been formatting my notifications as:

$appname $pushtitle //I make $appname my server or domain name and the $pushtitle "Notification"

$user $state $title $platform etc
 

If you noticed, with EMAIL provider in the config.pl, it has a 'subject' key and 'alert_format' override to use. The explanation above will correct that behavior and let you modify it however you'd like. Let me know if you run into any issues. I tried to make most things possible, it just takes some config work. 

ps. As with email you can override the specific alert_format types. Well, it's not technically just for the email provider,  you can add that block of code into every provider to override it ( I just didn't want to clutter or over complicate the config as it already is )

This chunk of code can be added into the other providers: 

'alert_format' => {
                'start'    =>  '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] {ip_address} {all_details}',
                'paused'   =>  '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%] {ip_address} {all_details}',
                'resumed'  =>  '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%] {ip_address} {all_details}',
                'stop'     =>  '{title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%] {ip_address} {all_details}',
            },

Thanks for the explanation. I couldn't figure out why $appname was displaying the $user name. I easily made all the changes and of the services I've been testing (prowl, gntp, email), the changes are working the way I had it with the exception of GNTP.

In the config.pl file, if I change the 'application' name from $appname to 'myserver' for GNTP and trigger a notification it registers an application with my GNTP server called myserver but the notification that appears is:

$user $push_title
$user $state $title
 

Anything I can do about that or is this a limitation in the way notifications must be sent to GNTP? It's not a deal breaker for me if I can't format GNTP. I'm thinking I'll just stick with Prowl and Email after testing.

Thanks for the explanation. I couldn't figure out why $appname was displaying the $user name. I easily made all the changes and of the services I've been testing (prowl, gntp, email), the changes are working the way I had it with the exception of GNTP.

In the config.pl file, if I change the 'application' name from $appname to 'myserver' for GNTP and trigger a notification it registers an application with my GNTP server called myserver but the notification that appears is:

$user $push_title
$user $state $title
 

Anything I can do about that or is this a limitation in the way notifications must be sent to GNTP? It's not a deal breaker for me if I can't format GNTP. I'm thinking I'll just stick with Prowl and Email after testing.

GNTP is a different beast, but anything is always possible with time :) I will see if I can fix it to imitate the original display. 

Thanks for the explanation. I couldn't figure out why $appname was displaying the $user name. I easily made all the changes and of the services I've been testing (prowl, gntp, email), the changes are working the way I had it with the exception of GNTP.

In the config.pl file, if I change the 'application' name from $appname to 'myserver' for GNTP and trigger a notification it registers an application with my GNTP server called myserver but the notification that appears is:

$user $push_title
$user $state $title
 

Anything I can do about that or is this a limitation in the way notifications must be sent to GNTP? It's not a deal breaker for me if I can't format GNTP. I'm thinking I'll just stick with Prowl and Email after testing.

Ok, so GNTP was put into place after I named some of the config variables, so it actually made more sense, but it's kind of confusing based on the config.. it uses 'title' as a key for the title :) I did however have to push a small change to fix the spacing when someone uses title in the config, so pull a new copy of plexWatch.pl

 Add this to the config.pl for GNTP

 GNTP' => {
        '1' =>  {
           ...
            'title' => 'PlexWatch', 

I will probably look into updating the config.pl at some point to use a more standard key name for each provider, I.E. "title" instead of "application" but I would of course want to make it interchangeable so people don't have to always change the config. 

Hi Guys,

Really cool script. Totally needed it. It worked during testing but now, in "production", this is what I get:

[root@servidor ~]# /opt/plexWatch/plexWatch.pl 
Cannot decode string with wide characters at /usr/lib64/perl5/vendor_perl/Encode.pm line 176.
 
How do i deal with this?
 
Thanks!
 
Andre
 
[root@servidor ~]# uname -a
Linux servidor 3.10.9-200.fc19.x86_64 #1 SMP Wed Aug 21 19:27:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@servidor ~]# 

Hi Guys,

Really cool script. Totally needed it. It worked during testing but now, in "production", this is what I get:


[root@servidor ~]# /opt/plexWatch/plexWatch.pl
Cannot decode string with wide characters at /usr/lib64/perl5/vendor_perl/Encode.pm line 176.

How do i deal with this?

Thanks!

Andre



[root@servidor ~]# uname -a
Linux servidor 3.10.9-200.fc19.x86_64 #1 SMP Wed Aug 21 19:27:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@servidor ~]#


Can you give me the output of both:

plexWatch.pl --version

plexWatch.pl --notify --debug

ljunkie, thanks for the latest release. Now that we have email notifications, is there a way to automatically email stats to the users? Would be great to send them a weekly or a monthly report of what the user(or their kids) have been watching.

Thanks again.

Hi LJunkie,

I was using .19 downloaded from github, but noticed there was version 20 and tried it as well. Same issue on both. Also, if it helps, the issue comes and goes. I have a feeling it's got something to do with the filename, possibly?

Here's the data you requested:

[root@servidor plexWatch]# ./plexWatch.pl --version
 
Version: 0.0.20-dev
 
##########################################
#   Author: Rob Reed
#  Created: 2013-06-26
# Modified: 2013-09-13 23:23 PST
#
#  Version: 0.0.20-dev
##########################################
 
 
[root@servidor plexWatch]# ./plexWatch.pl --notify --debug
Uncaught exception from user code:
Cannot decode string with wide characters at /usr/lib64/perl5/vendor_perl/Encode.pm line 176.
Encode::decode('UTF-8', '?>\x{a}\x{a}<Video addedAt="1374789215" art=...') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl/Reader/UnicodeExt.pm line 19
XML::SAX::PurePerl::Reader::switch_encoding_string('?>\x{a}\x{a}<Video addedAt="1374789215" art=...', 'UTF-8', 'utf-8') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl/Reader/String.pm line 69
XML::SAX::PurePerl::Reader::String::set_encoding('XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)', 'UTF-8') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl/XMLDecl.pm line 100
XML::SAX::PurePerl::EncodingDecl('XML::SAX::PurePerl=HASH(0x37ceaf0)', 'XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl/XMLDecl.pm line 28
XML::SAX::PurePerl::XMLDecl('XML::SAX::PurePerl=HASH(0x37ceaf0)', 'XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl.pm line 143
XML::SAX::PurePerl::prolog('XML::SAX::PurePerl=HASH(0x37ceaf0)', 'XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl.pm line 130
XML::SAX::PurePerl::document('XML::SAX::PurePerl=HASH(0x37ceaf0)', 'XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl.pm line 103
XML::SAX::PurePerl::_parse('XML::SAX::PurePerl=HASH(0x37ceaf0)', 'XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl.pm line 64
XML::SAX::PurePerl::_parse_string('XML::SAX::PurePerl=HASH(0x37ceaf0)', '<?xml version="1.0" encoding="UTF-8"?>\x{a}\x{a}\x{a}<MediaContainer size="...', 'KeyAttr', 'HASH(0x378b4f0)', 'ForceArray', 'ARRAY(0x357fd00)') called at ./plexWatch.pl line 1265</div> <div>main::GetSessions() called at ./plexWatch.pl line 632</div> <div>[root@servidor plexWatch]# </div> <div> </div> </div>

ljunkie, thanks for the latest release. Now that we have email notifications, is there a way to automatically email stats to the users? Would be great to send them a weekly or a monthly report of what the user(or their kids) have been watching.

Thanks again.


Reports are not added yet, email provider was just step one. You can however cron a few jobs to email the reports of watched. Incan give a better example later when I'm home.

I'm thinking about adding an option, --email to --watched so it will email the output instead of printing it. That way you can do something like:

plexWatch.pl --watched --start=yesterday --end=today --user=userName --email=recipient

you could create as many of those as you want and run them on a cronjob at any time you'd like, this one at midnight.

Much Appreciated ljunkie, I sent a donation..again.  ;)

Hi LJunkie,

I was using .19 downloaded from github, but noticed there was version 20 and tried it as well. Same issue on both. Also, if it helps, the issue comes and goes. I have a feeling it's got something to do with the filename, possibly?



Here's the data you requested:


[root@servidor plexWatch]# ./plexWatch.pl --version

Version: 0.0.20-dev

##########################################
# Author: Rob Reed
# Created: 2013-06-26
# Modified: 2013-09-13 23:23 PST
#
# Version: 0.0.20-dev
# https://github.com/ljunkie/plexWatch
##########################################




[root@servidor plexWatch]# ./plexWatch.pl --notify --debug
Uncaught exception from user code:
Cannot decode string with wide characters at /usr/lib64/perl5/vendor_perl/Encode.pm line 176.
Encode::decode('UTF-8', '?>\x{a}\x{a}<Video addedAt="1374789215" art=...') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl/Reader/UnicodeExt.pm line 19
XML::SAX::PurePerl::Reader::switch_encoding_string('?>\x{a}\x{a}<Video addedAt="1374789215" art=...', 'UTF-8', 'utf-8') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl/Reader/String.pm line 69
XML::SAX::PurePerl::Reader::String::set_encoding('XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)', 'UTF-8') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl/XMLDecl.pm line 100
XML::SAX::PurePerl::EncodingDecl('XML::SAX::PurePerl=HASH(0x37ceaf0)', 'XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl/XMLDecl.pm line 28
XML::SAX::PurePerl::XMLDecl('XML::SAX::PurePerl=HASH(0x37ceaf0)', 'XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl.pm line 143
XML::SAX::PurePerl::prolog('XML::SAX::PurePerl=HASH(0x37ceaf0)', 'XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl.pm line 130
XML::SAX::PurePerl::document('XML::SAX::PurePerl=HASH(0x37ceaf0)', 'XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl.pm line 103
XML::SAX::PurePerl::_parse('XML::SAX::PurePerl=HASH(0x37ceaf0)', 'XML::SAX::PurePerl::Reader::String=ARRAY(0x38f2140)') called at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl.pm line 64
XML::SAX::PurePerl::_parse_string('XML::SAX::PurePerl=HASH(0x37ceaf0)', '<?xml version="1.0" encoding="UTF-8"?>\x{a}\x{a}\x{a}<MediaContainer size="...', 'KeyAttr', 'HASH(0x378b4f0)', 'ForceArray', 'ARRAY(0x357fd00)') called at ./plexWatch.pl line 1265<br /> main::GetSessions() called at ./plexWatch.pl line 632<br /> [root@servidor plexWatch]# <br /></p></blockquote> <br /> Might need one more. <br /> <br /> plexWatch.pl --notify --debug --show_xml<br /> <br /> It's going to be something in the XML response that isn't ASCII. Thought I fixed that a long time ago.. must be another place.

Much Appreciated ljunkie, I sent a donation..again. ;)


Thank you! Donations are always appreciated!

Hi Guys,

Really cool script. Totally needed it. It worked during testing but now, in "production", this is what I get:


[root@servidor ~]# /opt/plexWatch/plexWatch.pl
Cannot decode string with wide characters at /usr/lib64/perl5/vendor_perl/Encode.pm line 176.

How do i deal with this?

Thanks!

Andre



[root@servidor ~]# uname -a
Linux servidor 3.10.9-200.fc19.x86_64 #1 SMP Wed Aug 21 19:27:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@servidor ~]#


It has to be some none ASCII char in the XML response from the PMS. Please play the video that caused the issue an run the command below to cause the error again.

plexWatch.pl --notify --debug --show_xml

Please post it some something like pastebin.com

Not sure if my last message made it.. My phone did something crazy.

Here it is!

http://pastebin.com/zZGdNgTc

Thanks so much!

Here it is!

http://pastebin.com/zZGdNgTc


Thanks so much!


I tested that XML as if it was my server responding with it. Everything works great. The only thing now is maybe something in your config.pl or maybe a perl module is old. Can you PM me the config.

How can i show special characters like umlauts (äöü) properly?

This should be working in the dev branch - http://forums.plexapp.com/index.php/topic/72552-plexwatch-plex-notify-script-send-push-alerts-on-new-sessions-and-stopped/page-15#entry463897

Thanks for all the work on the script.  Exactly what I needed.  I donated.  

I haven't played around with email notifications yet but is there a way or is it planned to add a method to have the stats emailed each day? 

I haven't played around with email notifications yet but is there a way or is it planned to add a method to have the stats emailed each day?


http://forums.plexapp.com/index.php/topic/72552-plexwatch-plex-notify-script-send-push-alerts-on-new-sessions-and-stopped/page-16#entry464302