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

I've reverted to 0.13 and it stopped the loop.

That is an ancient version and does not include GNTP anyways. 

 I just pushed a change that will remove the non-ascii chars in regards to 'Wide character' -- this still should not cause repeat messages. I'd like to get down to the bottom of that. 

 https://raw.github.com/ljunkie/plexWatch/dev/plexWatch.pl

 https://github.com/ljunkie/plexWatch/blob/dev/config.pl-dist  ( just verify you have all the required config options)

* If you run with '--notify --debug' , it will send the same notification over and over again, but I'd like to see the output.

* And of course, please run it without debug too. It's possible the repeats are fixed if it was due to the 'wide error'

ljunkie,

Thanks for all your hard work on this script, it has become quite handy in the few days I've been using it. I upgraded last night to your dev version and love the progress time and %complete options. Maybe I'm missing the location but I can't find these values stored in the db anywhere. Is it possible to have these stored in the plexWatch.db? I started working on a personal "viewingActivity" webpage similar to Netflix's and am using data from the plexWatch.db to populate the page. 

ljunkie,

Thanks for all your hard work on this script, it has become quite handy in the few days I've been using it. I upgraded last night to your dev version and love the progress time and %complete options. Maybe I'm missing the location but I can't find these values stored in the db anywhere. Is it possible to have these stored in the plexWatch.db? I started working on a personal "viewingActivity" webpage similar to Netflix's and am using data from the plexWatch.db to populate the page. 

Thank you! They are actually stored in the DB however I do not store them as individual colums anymore. Instead it's stored as the original XML result from PMS in the XML column. This has been something I have been doing since the initial public release. Most of the existing columns are maily cruft (even though they are updated on the initial insert). I end up parsing the XML on the fly from the DB instead of storing them every time. With version 0.0.18-dev I am updating the XML column every time the script is run with the most recent data, where previously it was just the initial result on insert. I know this might seem odd, but it's been very useful in many ways. I don't have to change the DB structure every time I want to include something. It also allows things to be added in new versions and usually make them compatitiable with data collected in previous versions.

The perl needs some cleanup ( and possible logic ) - but you can look at my logic inside of the " info_from_xml()" sub routine. This is where I parse the XML from Plex and come up with the variables your are looking for.  I hope this helps, even though it's probably not the answer you were hoping for.

I've seem to have trouble getting prowl to work on OSX. I verified prowl works by sending via the chrome extension to my phone. I created a separate API key for plexwatch, however I do not get any notifications with the following command ./plexWatch.pl -notify -watching. (yes I was watching a video)

Below is my config.pl settings. Anything I'm doing wrong? I get no errors after running plexWatch.pl Any ideas?

  'prowl' => {

       'enabled' => 1, ## 0 or 1 - set to 1 to enable PROWL
       'push_recentlyadded'  => 0,
       'push_watched'        => 1,
       'push_watching'       => 1,
       'apikey' => 'REMOVED REAL API KEY', ## your API key
       'application' => $appname,
       'priority' => 0,
       'url' => '',
       'collapse' => 0, ## will change for mating if collapsed notification are set in prowl   (deprecated)
    },

I've seem to have trouble getting prowl to work on OSX. I verified prowl works by sending via the chrome extension to my phone. I created a separate API key for plexwatch, however I do not get any notifications with the following command ./plexWatch.pl -notify -watching. (yes I was watching a video)

Below is my config.pl settings. Anything I'm doing wrong? I get no errors after running plexWatch.pl Any ideas?

try ./plexWatch.pl -notify -debug and see if you get anything. Also, are you running ./plexWatch at regular intervals? Are you using a Launch Agent? If so, can you paste your plist file contents?

try ./plexWatch.pl -notify -debug and see if you get anything. Also, are you running ./plexWatch at regular intervals? Are you using a Launch Agent? If so, can you paste your plist file contents?

Hmm, I get an error, is there a better way to debug? Any perl modules specific to prowl I should verify is installed correctly?

 DEBUG: PROWL failed: kiantech watching 21 Jump Street [2012] [R] on iPhone - setting prowl to back off additional notifications
Thu Aug 15 08:27:50 2013: DEBUG: kiantech watching 21 Jump Street [2012] [R] on iPhone

Hmm, I get an error, is there a better way to debug? Any perl modules specific to prowl I should verify is installed correctly?

 DEBUG: PROWL failed: kiantech watching 21 Jump Street [2012] [R] on iPhone - setting prowl to back off additional notifications
Thu Aug 15 08:27:50 2013: DEBUG: kiantech watching 21 Jump Street [2012] [R] on iPhone

perl Module required: LWP::UserAgent

try ./plexwatch.pl --test_notify=start 

 It should either post the notification successfully, tell you the API key is wrong due to a 401 response or print the response from the provider if we don't match the first two. 


Example with a bad API key

 ./plexWatch.pl --test_notify=start
PROWL - Notification not posted: incorrect API key.
Thu Aug 15 09:51:51 2013: DEBUG test_notify: PROWL failed: Adam & Hayley watching Lawless [T] [2012] [R] on Roku [45 minutes in] - setting prowl to back off additional notifications
Thu Aug 15 09:51:51 2013: DEBUG test_notify: Adam & Hayley watching Lawless [T] [2012] [R] on Roku [45 minutes in]
 

Example when it cannot connect to the prowl host:

PROWL - Notification not posted: Adam%20%26%20Hayley%20watching%20Lawless%20%5BT%5D%20%5B2012%5D%20%5BR%5D%20on%20Roku%20%5B45%20minutes%20in%5D 500 Can't connect to aprowlapp.com:443 (Bad hostname 'aprowlapp.com')

Thu Aug 15 09:57:29 2013: DEBUG test_notify: PROWL failed: Adam & Hayley watching Lawless [T] [2012] [R] on Roku [45 minutes in] - setting prowl to back off additional notifications
Thu Aug 15 09:57:29 2013: DEBUG test_notify: Adam & Hayley watching Lawless [T] [2012] [R] on Roku [45 minutes in]

If it's still not working, I suggest changing your API key to something obviously bad..  and verify you see the first error above. ' PROWL - Notification not posted: incorrect API key'

perl Module required: LWP::UserAgent

try ./plexwatch.pl --test_notify=start 

 It should either post the notification successfully, tell you the API key is wrong due to a 401 response or print the response from the provider if we don't match the first two. 


Example with a bad API key

 ./plexWatch.pl --test_notify=start
PROWL - Notification not posted: incorrect API key.
Thu Aug 15 09:51:51 2013: DEBUG test_notify: PROWL failed: Adam & Hayley watching Lawless [T] [2012] [R] on Roku [45 minutes in] - setting prowl to back off additional notifications
Thu Aug 15 09:51:51 2013: DEBUG test_notify: Adam & Hayley watching Lawless [T] [2012] [R] on Roku [45 minutes in]
 

Example when it cannot connect to the prowl host:

PROWL - Notification not posted: Adam%20%26%20Hayley%20watching%20Lawless%20%5BT%5D%20%5B2012%5D%20%5BR%5D%20on%20Roku%20%5B45%20minutes%20in%5D 500 Can't connect to aprowlapp.com:443 (Bad hostname 'aprowlapp.com')

Thu Aug 15 09:57:29 2013: DEBUG test_notify: PROWL failed: Adam & Hayley watching Lawless [T] [2012] [R] on Roku [45 minutes in] - setting prowl to back off additional notifications
Thu Aug 15 09:57:29 2013: DEBUG test_notify: Adam & Hayley watching Lawless [T] [2012] [R] on Roku [45 minutes in]

If it's still not working, I suggest changing your API key to something obviously bad..  and verify you see the first error above. ' PROWL - Notification not posted: incorrect API key'

I changed the API key to an invalid one (doesn't look related).I get this error.

/plexWatch.pl --test_notify=start

PROWL - Notification not posted: kiantech%20watching%2021%20Jump%20Street%20%5B2012%5D%20%5BR%5D%20on%20iPhone Can't verify SSL peers without knowning which Certificate Authorities to trust
 
This problem can be fixed by either setting the PERL_LWP_SSL_CA_FILE
envirionment variable or by installing the Mozilla::CA module.
 
To disable verification of SSL peers set the PERL_LWP_SSL_VERIFY_HOSTNAME
envirionment variable to 0.  If you do this you can't be sure that you
communicate with the expected peer.
 
Thu Aug 15 10:09:45 2013: DEBUG test_notify: PROWL failed: kiantech watching 21 Jump Street [2012] [R] on iPhone - setting prowl to back off additional notifications
Thu Aug 15 10:09:45 2013: DEBUG test_notify: kiantech watching 21 Jump Street [2012] [R] on iPhone

 

I installed the Mozilla:CA as recommended, and verified LWP::UserAgent is up to date, v 6.05  Still issue. Seems to be related to LWP::UserAgent module though.

I changed the API key to an invalid one (doesn't look related).I get this error.

/plexWatch.pl --test_notify=start

PROWL - Notification not posted: kiantech%20watching%2021%20Jump%20Street%20%5B2012%5D%20%5BR%5D%20on%20Kianoosh%27s%20iPhone Can't verify SSL peers without knowning which Certificate Authorities to trust
 
This problem can be fixed by either setting the PERL_LWP_SSL_CA_FILE
envirionment variable or by installing the Mozilla::CA module.
 
To disable verification of SSL peers set the PERL_LWP_SSL_VERIFY_HOSTNAME
envirionment variable to 0.  If you do this you can't be sure that you
communicate with the expected peer.
 
Thu Aug 15 10:09:45 2013: DEBUG test_notify: PROWL failed: kiantech watching 21 Jump Street [2012] [R] on iPhone - setting prowl to back off additional notifications
Thu Aug 15 10:09:45 2013: DEBUG test_notify: kiantech watching 21 Jump Street [2012] [R] on iPhone

 

I installed the Mozilla:CA as recommended, and verified LWP::UserAgent is up to date, v 6.05  Still issue. Seems to be related to LWP::UserAgent module though.

Can you re-install it just to verify:

sudo cpan 
install LWP::UserAgent Mozilla::CA  

I could add the option to not verify SSL, but I am not sure how I feel about that this morning. Let's see if the above works. 

Can you re-install it just to verify:

sudo cpan 
install LWP::UserAgent Mozilla::CA  

I could add the option to not verify SSL, but I am not sure how I feel about that this morning. Let's see if the above works. 

My Mozilla::CA is up to date (20130114). 

I did check the perl version in osx, 5.12.4 (built for darwin-thread-multi-2level

My Mozilla::CA is up to date (20130114). 

I did check the perl version in osx, 5.12.4 (built for darwin-thread-multi-2level

I believe i had the same issue with SSL and after installing Mozilla::CA it still did not work until i forced the reinstall of LWP::UserAgent

That is an ancient version and does not include GNTP anyways. 

 I just pushed a change that will remove the non-ascii chars in regards to 'Wide character' -- this still should not cause repeat messages. I'd like to get down to the bottom of that. 

 https://raw.github.com/ljunkie/plexWatch/dev/plexWatch.pl

 https://github.com/ljunkie/plexWatch/blob/dev/config.pl-dist  ( just verify you have all the required config options)

* If you run with '--notify --debug' , it will send the same notification over and over again, but I'd like to see the output.

* And of course, please run it without debug too. It's possible the repeats are fixed if it was due to the 'wide error'

Looks like this fixed my 'wide' issue and the looping.  Thanks!

I believe i had the same issue with SSL and after installing Mozilla::CA it still did not work until i forced the reinstall of LWP::UserAgent

I did a force reinstall with sudo cpan -f -i LWP::UserAgent and for Mozilla::CA seemed to reinstall it. However I get the same error.

rcork, are you using OSX perl 5.12 or a newer version? If so, how did you upgrade?

EDIT: I also tried getting twitter to work, I get the following error, maybe this will give a clue regarding my prowl perl problems.

installed twitter, made dev and get this error.

CPAN: Storable loaded ok (v2.22)
Reading '/Users/myun/.cpan/Metadata'
  Database was generated on Wed, 14 Aug 2013 23:53:03 GMT
CPAN: Module::CoreList loaded ok (v2.50)
Net::Twitter::Lite::WithAPIv1_1 is up to date (0.12004).
$ sudo cpan install Net::OAuth
CPAN: Storable loaded ok (v2.22)
Reading '/Users/myun/.cpan/Metadata'
  Database was generated on Wed, 14 Aug 2013 23:53:03 GMT
CPAN: Module::CoreList loaded ok (v2.50)
Net::OAuth is up to date (0.28).
 

plexWatch$ ./plexWatch.pl --test_notify=start

Can't locate Net/Twitter/Lite/WithAPIv1_1.pm in @INC (@INC contains: /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4/darwin-thread-multi-2level /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at ./plexWatch.pl line 45
 
UPDATE
 
installed plexWatch on my personal mac, fresh from dev tools like homebrew and port, everything worked fine including push. I'll try to figure out a way to clean my server's setup, I'll update if it's resolved.
 
ljunkie and rcork, thank you for the support.
 
UPDATE2
 
removed homebrew and macports... force reinstalled modules, highly recommend installing Mozilla::CA prior to LWP::UserAgent
 
everything seems to be working!

I did a force reinstall with sudo cpan -f -i LWP::UserAgent and for Mozilla::CA seemed to reinstall it. However I get the same error.

rcork, are you using OSX perl 5.12 or a newer version? If so, how did you upgrade?

EDIT: I also tried getting twitter to work, I get the following error, maybe this will give a clue regarding my prowl perl problems.

installed twitter, made dev and get this error.

CPAN: Storable loaded ok (v2.22)
Reading '/Users/myun/.cpan/Metadata'
  Database was generated on Wed, 14 Aug 2013 23:53:03 GMT
CPAN: Module::CoreList loaded ok (v2.50)
Net::Twitter::Lite::WithAPIv1_1 is up to date (0.12004).
$ sudo cpan install Net::OAuth
CPAN: Storable loaded ok (v2.22)
Reading '/Users/myun/.cpan/Metadata'
  Database was generated on Wed, 14 Aug 2013 23:53:03 GMT
CPAN: Module::CoreList loaded ok (v2.50)
Net::OAuth is up to date (0.28).
 

plexWatch$ ./plexWatch.pl --test_notify=start

Can't locate Net/Twitter/Lite/WithAPIv1_1.pm in @INC (@INC contains: /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4/darwin-thread-multi-2level /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at ./plexWatch.pl line 45
 
UPDATE
 
installed plexWatch on my personal mac, fresh from dev tools like homebrew and port, everything worked fine including push. I'll try to figure out a way to clean my server's setup, I'll update if it's resolved.
 
ljunkie and rcork, thank you for the support.
 
UPDATE2
 
removed homebrew and macports... force reinstalled modules, highly recommend installing Mozilla::CA prior to LWP::UserAgent
 
everything seems to be working!

Glad to hear you got it working. I originally was using MacPorts but that was more work to get plexWatch working than using the built-in perl. That's because MacPorts installs it's own perl and modules in different directories. By using the built-in perl and removing port, it is much easier to install.

 Version 0.0.18 released

 

https://github.com/ljunkie/plexWatch


config.plhttps://raw.github.c.../config.pl-dist
plexWatch.plhttps://raw.github.c...er/plexWatch.pl

 

Major changes:

 

* The ability to specify a myPlex user/pass: will allow this script to be execute from any computer instead of the local PMS. If you are an existing user and want to run this on a different computer, make sure you copy your existing database to the new location. 

* Automatic DB backups

* New format options: {streamtype}, {transcoded},  {percent_complete}, {state}, {progress}

 

Change Log:  0.0.18

* MyPlex Login Token: The script can now be executed on any computer.
       -- Specify a $myPlex_user and $myPlex_pass in config.pl
       -- Will only retrieve a token from my.plexapp.com if the PMS server returns a 401 (authorization required)
 * Backup SQLite DB
    -- automatically happens daily, weekly and monthly
    -- force Daily backup with --backup
 * format_options update/new:
    -- {streamtype} [T|D] for Transcoded/Direct
    -- {transcoded} [1|0] for Transcoded/Direct
    -- {percent_complete} - percent of video watched ( not dependent on time watched, but where progress of video/length.
    -- {state} - playing/paused/buffering
    -- {progress} - exact time spot the user is at  (I.E. "15 minutes" )
 * XML is now updated on every run -- allows us to view current state of content ( i.e. paused, playing, percent_completed, etc)
 * CheckLock fixed: script can NOT to be ran multiple times at once (fixed repeat notifications when providers are offline)
 * Provider notifications: timeout is now 20 seconds instead of 3 minutes (we should not wait 3 minutes to reach a provider!)
 * Fixed: GNTP ProviderEnabled check was broken -- if one was enabled, all were enabled"
 * Fixed: 'Wide character in send at' errors
 

Thank you! They are actually stored in the DB however I do not store them as individual colums anymore. Instead it's stored as the original XML result from PMS in the XML column. This has been something I have been doing since the initial public release. Most of the existing columns are maily cruft (even though they are updated on the initial insert). I end up parsing the XML on the fly from the DB instead of storing them every time. With version 0.0.18-dev I am updating the XML column every time the script is run with the most recent data, where previously it was just the initial result on insert. I know this might seem odd, but it's been very useful in many ways. I don't have to change the DB structure every time I want to include something. It also allows things to be added in new versions and usually make them compatitiable with data collected in previous versions.

The perl needs some cleanup ( and possible logic ) - but you can look at my logic inside of the " info_from_xml()" sub routine. This is where I parse the XML from Plex and come up with the variables your are looking for.  I hope this helps, even though it's probably not the answer you were hoping for.

Thanks for the feedback, your sub routine helped me out quite a bit. Once I figured out how to extract and parse the xml element from a sqlite query it was pretty simple to get those variables for the site. Thanks again!

Thanks for the feedback, your sub routine helped me out quite a bit. Once I figured out how to extract and parse the xml element from a sqlite query it was pretty simple to get those variables for the site. Thanks again!

Perfect! Any chance you are going to share this? I'd love to extend the features of plexWatch, i.e. some sort of front end or emailer like plex reporter, but I know the time involved to keep up with features in those might be too much for now. 

Perfect! Any chance you are going to share this? I'd love to extend the features of plexWatch, i.e. some sort of front end or emailer like plex reporter, but I know the time involved to keep up with features in those might be too much for now. 

I'm not sure anyone would specifically want what I'm making. Basically it's a bunch of php scripts that parse my Plex Media Server's API and the plexWatch db to populate various pages on a Wordpress website. It's more or less a front end website to my personal Plex/Web. I'm developing the site so I have a reason to learn PHP parsing. Most Plex users are probably perfectly happy just having their family and friends log right into Plex/Web but I wanted to try and offer a bit more.

Currently I'm parsing the plexWatch db to give individually logged in users a "Viewing Activity" history much like Netflix does. I'm still playing around with what details to offer but here is an example of what is currently being displayed to the user. 

viewingActivity.jpg

The title link takes the user to a page that gives information on that specific episode or movie. This is off topic but I'd like to provide my users with a way to rate content, add/manage content to their "favorites", "recommendations" and "queue" but I think that's something the Plex devs would need to do; multi-user favorites, recommendations and queue management using content from local and shared servers instead of just web based content. I need to read through feature requests and see if these ideas have been requested before but I can see content like this being included with email reports of their viewing activity.

I suppose the code could be altered to create a static monitoring webpage if that's what you had in mind. I'm not sure what plexWatch users would find most useful. I personally can see configurable email reports (daily, weekly, monthly, annual, etc) being a cool feature. I'd personally like to be able to offer reports to my users if we can get the devs to add more multi-user based features like I mentioned above.

I'd like to have specifically what your making but my scripting knowledge might not be specific.  Heck, I'm not sure where to find the PMS API documentation.

Do the notifications not also work for audio?