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

It doesn't need to be 7 days or newer. How about in the 24 hours or newer? that would probably cover things if we are running the processor every 5 minutes.

It doesn't need to be 7 days or newer. How about in the 24 hours or newer? that would probably cover things if we are running the processor every 5 minutes.


I agree. I had 24 hours in mind but figured someone might balk at it :) I could make it configurable, but too many options could be confusing for such a minor issue (mainly the first run)

Thanks for the work on this :)

What commands do you use exactly, to install the requirements on OS X 10.8.4?

Found a bug in the NotifyGrowl subroutine. On line 1322, $growl{'appname'} should be $growl{'application'}

When trying to run 'plexWactch -recently_added=movie, i get the following error:

Can't use string ("2013-03-06") as a HASH ref while "strict refs" in use at ./plexWatch.pl line 186.

When trying to run 'plexWactch -recently_added=movie, i get the following error:

Can't use string ("2013-03-06") as a HASH ref while "strict refs" in use at ./plexWatch.pl line 186.

I hope I can find how this is happening. I haven't replicated that with the 100+  per sections items I have tested.

Found a bug in the NotifyGrowl subroutine. On line 1322, $growl{'appname'} should be $growl{'application'}

Thank you. I will be fixing this.

When trying to run 'plexWactch -recently_added=movie, i get the following error:

Can't use string ("2013-03-06") as a HASH ref while "strict refs" in use at ./plexWatch.pl line 186.

I am now checking to verify the result from the API is what I expect. Please grab a new copy https://raw.github.com/ljunkie/plexWatch/master/plexWatch.pl

* growl now uses 'application'

* bugfix to skip the 'strinct refs' error -- could not replicate issue, but hoping changes will either fix or help debug it further

try running plexWatch --recently_added=movie  (hopefully no errors -- because it ended up skipping the bad/unexpected results from PMS api)

Also, try running it with --debug ( it will print out what it skipped )

I am now checking to verify the result from the API is what I expect. Please grab a new copy https://raw.github.com/ljunkie/plexWatch/master/plexWatch.pl

* growl now uses 'application'

* bugfix to skip the 'strinct refs' error -- could not replicate issue, but hoping changes will either fix or help debug it further

try running plexWatch --recently_added=movie  (hopefully no errors -- because it ended up skipping the bad/unexpected results from PMS api)

Also, try running it with --debug ( it will print out what it skipped )

Same error as before and no debug output. However, i commented out the if (!ref ...) code to force the debug print and then i searched through the output for '2013-03-06' and this is the only thing that matched:

$VAR1 = {
          'mediaTagPrefix' => '/system/bundle/media/flags/',
          'Video' => {
                     'updatedAt' => '1375131660',
                     'viewCount' => '2',
                     'viewOffset' => '17479',
                     'originallyAvailableAt' => '2013-03-06',
                     'art' => '/library/metadata/12472/art/1375131660',
                     'duration' => '19686',
                     'thumb' => '/library/metadata/12472/thumb/1375131660',
                     'Media' => {
                                'videoFrameRate' => '24p',
                                'videoResolution' => '1080',
                                'width' => '1920',
                                'bitrate' => '24187',
                                'audioCodec' => 'dca',
                                'videoCodec' => 'h264',
                                'duration' => '19686',
                                'container' => 'mpegts',
                                'height' => '1080',
                                'Part' => {
                                          'packetLength' => '188',
                                          'file' => '/Users/rob/Movies/Other Plex Videos/DTS Intro.m2ts',
                                          'id' => '11544',
                                          'container' => 'mpegts',
                                          'duration' => '19686',
                                          'size' => '59670528',
                                          'key' => '/library/parts/11544/file.m2ts'
                                        },
                                'aspectRatio' => '1.78',
                                'id' => '11542',
                                'audioChannels' => '6'
                              },
                     'ratingKey' => '12472',
                     'key' => '/library/metadata/12472',
                     'summary' => '',
                     'title' => 'DTS Intro',
                     'type' => 'movie',
                     'addedAt' => '1375131658',
                     'year' => '2013'
                   },
          'viewGroup' => 'movie',
          'viewMode' => '65592',
          'art' => '/:/resources/movie-fanart.jpg',
          'thumb' => '/:/resources/video.png',
          'title2' => 'Recently Added',
          'size' => '1',
          'identifier' => 'com.plexapp.plugins.library',
          'allowSync' => '1',
          'mediaTagVersion' => '1370556419',
          'title1' => 'Sandbox',
          'librarySectionID' => '10',
          'librarySectionUUID' => '86fded9f-7997-4107-885d-0814910822bf'
        };

This is a "Sandbox" section i use to test video files. It's setup to use the Plex Video Files Scanner and Personal Media agent. 

Thanks for the work on this :)

What commands do you use exactly, to install the requirements on OS X 10.8.4?

Does anyone have pointers for OSX how to install perl and required modules

Required:

LWP::UserAgent
XML::Simple
DBI
Time::Duration;
Time::ParseDate;
Pod::Usage;  (maybe -- it's sometimes part of perl base)

 Debian

sudo apt-get install libwww-perl libxml-simple-perl libtime-duration-perl libtime-modules-perl libdbd-sqlite3-perl perl-doc

Centos

yum -y install perl\(LWP::UserAgent\) perl\(XML::Simple\) perl\(DBI\) perl\(Time::Duration\)  perl\(Time::ParseDate\)

OSX:  All done through cpan?

Does anyone have pointers for OSX how to install perl and required modules

Required:

LWP::UserAgent
XML::Simple
DBI
Time::Duration;
Time::ParseDate;
Pod::Usage;  (maybe -- it's sometimes part of perl base)

 Debian

sudo apt-get install libwww-perl libxml-simple-perl libtime-duration-perl libtime-modules-perl libdbd-sqlite3-perl perl-doc

Centos

yum -y install perl\(LWP::UserAgent\) perl\(XML::Simple\) perl\(DBI\) perl\(Time::Duration\)  perl\(Time::ParseDate\)

OSX:  All done through cpan?

I used macports to install most perl modules but used cpan for the ones that weren't in macports (i believe they were LWP::UserAgent, XML::Simple and WWW::Curl::Easy). Some through cpan did not install easily so i had to force the install.  I'll see if i can spin up a VM with a clean OSX and document the steps.

When trying to run 'plexWactch -recently_added=movie, i get the following error:

Can't use string ("2013-03-06") as a HASH ref while "strict refs" in use at ./plexWatch.pl line 186.

This issue has been fixed in Dev and Master. It was due to a section in PMS only having 1 video.

Does anyone have pointers for OSX how to install perl and required modules

Required:

LWP::UserAgent
XML::Simple
DBI
Time::Duration;
Time::ParseDate;
Pod::Usage;  (maybe -- it's sometimes part of perl base)

 Debian

sudo apt-get install libwww-perl libxml-simple-perl libtime-duration-perl libtime-modules-perl libdbd-sqlite3-perl perl-doc

Centos

yum -y install perl\(LWP::UserAgent\) perl\(XML::Simple\) perl\(DBI\) perl\(Time::Duration\)  perl\(Time::ParseDate\)

OSX:  All done through cpan?

On OSX I would recommend using PerlBrew to set up a self-contained Perl installation that is seperate from the version of Perl installed by OS X by default. Using PerlBrew has several advantages over the in built Perl as for one Apple doesn't bundle the latest Perl releases and you don't have to worry about having admin rights when you need to add extra Perl modules.

PerlBrew installs Perl distributions by default under your OSX user home folder (e.g ~/perl5/perlbrew) so you all you have to do to install additional modules is to run

cpan install 
e.g. 

cpan install LWP::UserAgent

Thanks for the work on this :)

What commands do you use exactly, to install the requirements on OS X 10.8.4?

Here are the steps to get it running on OSX. This was done with a clean install of OSX. 

  1. Download plexWatch from github and unzip
  2. Copy config.pl-dist to config.pl and modify for your notification options
  3. Install XCode from Mac App Strore
  4. Install XCode command line tools by launching XCode, going to preferences, downloads, Install Command Line Tools
  5. Configure CPAN
    1. Launch Terminal.app
    2. Type "cpan" without the quotes and press enter
    3. If this is first time launching cpan, it will ask if you want to automatically configure. Hit Enter
      1. It will ask if you want to automatically pick download mirrors. Type No and hit enter
      2. Pick mirrors for your region. I've had the best luck with .edu mirrors
    4. Type "install cpan" without the quotes and hit enter. This will update cpan to the latest version
    5. Type "reload cpan" without the quotes and hit enter.
    6. Type "exit" without the quotes and hit enter
  6. Install required perl modules from Terminal
    sudo cpan install Time::Duration
    sudo cpan install Time::ParseDate
    sudo cpan install Net::Twitter::Lite::WithAPIv1_1
    sudo cpan install Net::OAuth
    sudo cpan install Mozilla::CA
  7. Now create data directory and set permission. Replace [user] with your username
    sudo mkdir /opt
    sudo mkdir /opt/plexWatch
    sudo chown [user]:staff /opt/plexWatch
  8. Run plexWatch from Terminal. You shouldn't receive any errors or warnings
    ./plexWatch.pl
    
    </li>
    

plexWatch  - 0.0.16

https://github.com/ljunkie/plexWatch

config.pl: https://raw.github.com/ljunkie/plexWatch/master/config.pl-dist
plexWatch.pl: https://raw.github.com/ljunkie/plexWatch/master/plexWatch.pl

Change Log:

0.0.16
* rate limiting: provide mechanisms to back off notifications if provider fails (mainly due to --recently_added)
     -- twitter: no api for writes. 403 error, we assume user hit daily limits (unknown hourly limit). Do not process additional notification until next run.
     -- boxcar: on failure -- back of the rest of alerts for provider until next run
     -- prowl:  on failure -- back of the rest of alerts for provider until next run
     -- growl:  on failure -- back of the rest of alerts for provider until next run
     -- pushover: on failure -- back of the rest of alerts for provider until next run
* --recently_added: limited to 25 results per section/per run (multiple sections of same type: two sections with type 'shows' = 50 results )
* --recently_added: SKIP notifications for a video if the addedDate is older than 1 day
* --recently_added: process backlog (failed alerts) of recently added ( if notification failed and more videos were added before we could notify, keep trying -- but only for 2 days)
* test_notify=recently_added  -- option to test notification for recently added content (verify provider even works)
* config.pl: $notify_started and $notify_stopped deprecated: use per provider settings globally (i.e. push_watched, push_watching)
* recently_added: bugfix - failed when a section only has 1 video.
* titles added to notifications ( change titles per type in config.pl $push_titles ) prowl, growl, pushover, boxcar, twitter supported
* Default titles can be changed globally in config.pl ($push_titles)

Sorry guys. I did not get GNTP in this release as I didn't want to wait to push these changes. The rate limiting will drastically help when running this the first time.

Correction to NotifyGrowl line 1374:

-    $extra_cmd = " -t $growl{'title'} " if $growl{'title'};
+    $extra_cmd = "$growl{'title'} " if $growl{'title'};
 
The " -t ..." was causing the title of the growl notification to start with " -t .."

Correction to NotifyGrowl line 1374:

-    $extra_cmd = " -t $growl{'title'} " if $growl{'title'};
+    $extra_cmd = "$growl{'title'} " if $growl{'title'};
 
The " -t ..." was causing the title of the growl notification to start with " -t .."

I wish I had OSX. So I am confused.. I thought that script needed a -t for title.. how would it know it's a title without -t?

rob@RobsUbuntuServer:~/Desktop$ /opt/plexWatch/plexWatch.pl --recently_added=movie --debug

Wed Jul 31 19:11:38 2013: A Haunted House [R] [2013] 86min [720p 6ch] [8:21pm 30 Jul 13]
Wed Jul 31 19:11:38 2013: Emperor [PG-13] [2012] 105min [720p 6ch] [6:14pm 31 Jul 13]
Wed Jul 31 19:11:38 2013: BOXCAR failed: Emperor [PG-13] [2012] 105min [720p 6ch] [6:14pm 31 Jul 13] - setting boxcar to back off additional notifictions

And it is spelled as "notifications" ;)

Seems it's still trying way to fast for Boxcar. I wait a few seconds and try again it then works fine.

And it is spelled as "notifications" ;)

Seems it's still trying way to fast for Boxcar.

I need to spell check my code :)

As for being too fast - I still don't have any idea how fast is too fast, so instead,  it will back off the provider when it fails. The next run of the script will start from where it left off (backlog). The idea is to have this run on an interval, so from what it looks like, the code is working properly.

Looks like you may need to just pause for 2 seconds between notifications, at least for Boxcar anyways.

But indeed, does appear to be functioning correctly as it was indeed picked up the second go around.

Looks like you may need to just pause for 2 seconds between notifications, at least for Boxcar anyways.

But indeed, does appear to be functioning correctly as it was indeed picked up the second go around.

I'll put it on the todo list to have another look at limits. I just am not excited about putting a 2 second delay in for every notification. It would make sense however to maybe start the delay after the first failure instead of backing off entirely. I want to get some other things coded first, GNTP, paused status, etc.. since this is technically working.