├── .gitignore ├── README.md ├── README.windows.md ├── change.log ├── config.pl-dist ├── config.pl-dist-win32 ├── notes ├── TODO └── win32.build.caveats.txt ├── plexWatch.exe ├── plexWatch.notifyDeamon.pl ├── plexWatch.pl ├── plexWatchNotify.vbs ├── plexWatchRecentlyAdded.vbs └── screenshots ├── iOS-plexWatch_boxcar.png ├── iOS-plexWatch_prowl.png ├── iOS-plexWatch_pushover.png └── win7-plexWatch_GNTP.png /.gitignore: -------------------------------------------------------------------------------- 1 | ## plexWatch related # 2 | ###################### 3 | config.pl 4 | plexWatch.db 5 | plexWatch.log 6 | db_backups/* 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | plexWatch - 0.3.2 (2014-11-19) 2 | ========= 3 | ***Notify*** and Log ***'Now Playing'*** and ***'Watched'*** content from a Plex Media Server + ***'Recently Added'*** (...and more) 4 | 5 | [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CHRZ55VCAJSYG) 6 | 7 | 8 | ** windows and linux codebase has been fully merged ** 9 | 10 | ---------------- 11 | 12 | ### Need Help? 13 | * Linux Forum: http://forums.plexapp.com/index.php/topic/72552-plexwatch-plex-notify-script-send-push-alerts-on-new-sessions-and-stopped/ 14 | * Windows Forum: http://forums.plexapp.com/index.php/topic/79616-plexwatch-windows-branch/ 15 | 16 | ### Want a frontend? ***plexWatch/Web*** 17 | * Download: https://github.com/ecleese/plexWatchWeb 18 | * Forums: http://forums.plexapp.com/index.php/topic/82819-plexwatchweb-a-web-front-end-for-plexwatch/ 19 | 20 | ---------------- 21 | 22 | ### Read More about plexWatch 23 | 24 | **Supported Push Notifications** 25 | * Email 26 | * https://pushover.net 27 | * https://prowlapp.com 28 | * http://growl.info/ (via GrowlNotify @ http://growl.info/downloads#generaldownloads) 29 | * https://twitter.com/ (create a new app @ https://dev.twitter.com/apps) 30 | * https://boxcar.io/ & boxcar V2 31 | * https://pushbullet.com 32 | * SNARL/GROWL: GNTP notifications supported. Anything that uses GNTP *should* work 33 | * External Scripts: home automation, pause download clients, etc (rudimentary plugins) 34 | 35 | **What it does** 36 | * notify when a user starts watching a video 37 | * notify when a user stops watching a video 38 | * notify when a user pauses watching a video 39 | * notify when a user resumes watching a video 40 | * notify on recently added content to a PMS server 41 | * notifies via email, prowl, pushover, growl, twitter, boxcar, pushbullet, GNTP and/or a log file 42 | * enable/disable notifications per provider & per notification type (start, stop, paush, resume, recently added) 43 | * backed by a SQLite DB (for state and history) 44 | * CLI to query watched videos, videos being watched and stats on time watched per user 45 | * Limit output per user or exclude users 46 | * ...more to come 47 | 48 | 49 | ###Perl Requirements 50 | 51 | * LWP::UserAgent 52 | * XML::Simple 53 | * DBI 54 | * Time::Duration; 55 | * Time::ParseDate; 56 | * JSON 57 | 58 | #### These should be part of the base Perl install 59 | 60 | * Pod::Usage; (Perl base on rhel/centos) 61 | * Fcntl qw(:flock); (Perl base) 62 | * Getopt::Long; (Perl base) 63 | * POSIX qw(strftime) (Perl base) 64 | * File::Basename (Perl base) 65 | 66 | 67 | #### Required ONLY if you use twitter 68 | 69 | * Net::Twitter::Lite::WithAPIv1_1 70 | * Net::OAuth 71 | 72 | ```sudo cpan Net::Twitter::Lite``` 73 | 74 | ```sudo cpan Net::OAuth``` 75 | 76 | 77 | #### Required ONLY if you use GNTP 78 | 79 | * Growl::GNTP 80 | 81 | ```sudo cpan Growl::GNTP``` 82 | 83 | 84 | #### Required ONLY if you use Email 85 | 86 | * Net::SMTPS 87 | 88 | ```sudo cpan Net::SMTPS``` 89 | 90 | 91 | #### Required ONLY if 'Client IP Logging' is enable 92 | 93 | * File::ReadBackwards 94 | 95 | * To enable: edit config.pl 96 | 97 | ``` 98 | $server_log = '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log'; ## used to log IP address of user (alpha) 99 | $log_client_ip = 1; ## requires $server_log to be available too. 100 | $debug_logging = 1; ## logs to $data_dir/debug.log ( only really helps debug IP logging for now ) 101 | ``` 102 | 103 | ``` 104 | # Debian/Ubuntu: apt-get 105 | sudo apt-get install libfile-readbackwards-perl 106 | 107 | # Rhel/Centos: yum 108 | sudo yum install perl\(File::ReadBackwards\) 109 | 110 | # Others: cpan 111 | sudo cpan File::ReadBackwards 112 | ``` 113 | 114 | 115 |
116 | 117 | ### Install 118 | ---- 119 | 120 | 1. Download plexWatch.pl and config.pl-dist to /opt/plexWatch/ 121 | * WGET 122 | 123 | ``` 124 | sudo wget -P /opt/plexWatch/ https://raw.github.com/ljunkie/plexWatch/master/plexWatch.pl 125 | sudo wget -P /opt/plexWatch/ https://raw.github.com/ljunkie/plexWatch/master/config.pl-dist 126 | ```` 127 | * CURL 128 | 129 | ``` 130 | sudo mkdir -p /opt/plexWatch/ 131 | sudo curl https://raw.github.com/ljunkie/plexWatch/master/plexWatch.pl -o /opt/plexWatch/plexWatch.pl 132 | sudo curl https://raw.github.com/ljunkie/plexWatch/master/config.pl-dist -o /opt/plexWatch/config.pl-dist 133 | ``` 134 | 135 | 2. ```sudo chmod 777 /opt/plexWatch && sudo chmod 755 /opt/plexWatch/plexWatch.pl``` 136 | 137 | 3. ```sudo cp /opt/plexWatch/config.pl-dist /opt/plexWatch/config.pl``` 138 | 1. ```sudo nano /opt/plexWatch/config.pl``` 139 | * Modify Variables as needed 140 | 141 | ```perl 142 | $server = 'localhost'; ## IP of PMS - or localhost 143 | $port = 32400; ## port of PMS 144 | $notify_started = 1; ## notify when a stream is started (first play) 145 | $notify_stopped = 1; ## notify when a stream is stopped 146 | ``` 147 | 148 | ```bash 149 | $notify = {... 150 | * to enable a provider, i.e. file, prowl, pushover 151 | set 'enabled' => 1, under selected provider 152 | * Prowl : 'apikey' required 153 | * Pushover : 'token' and 'user' required 154 | * Growl : 'script' required :: GrowlNotify from http://growl.info/downloads (GNTP replaces this) 155 | * twitter : 'consumer_key', 'consumer_secret', 'access_token', 'access_token_secret' required 156 | * boxcar : 'email' required 157 | * pushover : 'apikey' and 'device' required 158 | * GNTP : 'server', 'port' required. 'password' optional. You must allow network notifications on the Growl Server 159 | ``` 160 | 161 | 4. Install Perl requirements 162 | * Debian/Ubuntu - apt-get 163 | 164 | ```bash 165 | apt-get install libwww-perl libxml-simple-perl libtime-duration-perl libtime-modules-perl libdbd-sqlite3-perl perl-doc libjson-perl 166 | ``` 167 | * RHEL/Centos - yum 168 | 169 | ```bash 170 | yum -y install perl\(LWP::UserAgent\) perl\(XML::Simple\) perl\(Pod::Usage\) perl\(JSON\) 171 | perl\(DBI\) perl\(Time::Duration\) perl\(Time::ParseDate\) perl\(DBD::SQLite\) 172 | ``` 173 | 174 | 5. **run** the script manually to verify it works: /opt/plexWatch/plexWatch.pl 175 | * start video(s) 176 | * ```/opt/plexWatch/plexWatch.pl``` 177 | * stop video(s) 178 | * ```/opt/plexWatch/plexWatch.pl``` 179 | 180 | 181 | 6. setup crontab or launchagent to run the script every minute 182 | * __linux__: /etc/crontab 183 | 184 | ```bash 185 | * * * * * YOUR_USERNAME /opt/plexWatch/plexWatch.pl 186 | ``` 187 | * __OSX__: use a launchagent instead of cron. Refer to the __FAQ__ on the bottom. 188 | 189 | 190 | 7. [*optional*] If you want Recently Added notifiations - setup another crontab or launchagent entry 191 | * __linux__: /etc/crontab 192 | 193 | ```bash 194 | */15 * * * * YOUR_USERNAME /opt/plexWatch/plexWatch.pl --recently_added=movie,tv 195 | ``` 196 | * __OSX__: use a launchagent instead of cron. Refer to the __FAQ__ on the bottom. 197 | 198 | 199 |
200 | 201 | ### Twitter integration 202 | ---- 203 | If you want to use twitter, you will need to install two more Perl modules 204 | 205 | * requires Net::Twitter::Lite::WithAPIv1_1 206 | 207 | ```bash 208 | sudo cpan Net::Twitter::Lite::WithAPIv1_1 209 | 210 | # OR force install it 211 | sudo cpan -f Net::Twitter::Lite::WithAPIv1_1 212 | ``` 213 | 214 | * requires Net::OAuth >= 0.28 215 | 216 | ```bash 217 | sudo cpan Net::OAuth 218 | 219 | # OR force install it 220 | sudo cpan -f Net::OAuth 221 | ``` 222 | 223 | #### Twitter setup 224 | 225 | * create a new app @ https://dev.twitter.com/apps 226 | * click "Create New App" 227 | * Name: unique name for for your app 228 | * Description: fill something in... 229 | * Website: you need some valid website.. 230 | * (read) and accept terms 231 | * click "Create you Twitter Application" 232 | * click "Modify app permission" under the Details Tab 233 | * change to Read and Write 234 | * update settings 235 | * click the "API keys" tab 236 | * click "create my access token" 237 | * click "Test OAuth" button to view the required API keys need for config.pl 238 | * Edit the config.pl 239 | * enable notification for twitter in config.pl 240 | * enter in the required keys, secrets and tokens 241 | 242 | 243 |
244 | ### GNTP integration 245 | ---- 246 | If you want to use GNTP (growl), you will need to install a module 247 | 248 | * requires Growl::GNTP 249 | 250 | ```bash 251 | sudo cpan Growl::GNTP 252 | ``` 253 | * Note: CPAN install failed on centos until I installed perl\(Data::UUID\) 254 | 255 | 256 | 257 |
258 | ## Using the script 259 | 260 | 261 | ### Sending Notifications 262 | 263 | * Follow the install guide above, and refer to step #5 and #6 264 | 265 | * Sending test notifications: 266 | 267 | ``` 268 | /opt/plexWatch/plexWatch.pl --test_notify=start 269 | 270 | /opt/plexWatch/plexWatch.pl --test_notify=stop 271 | ``` 272 | 273 | ### Getting a list of watched shows 274 | 275 | * This will only work for shows this has already notified on. 276 | 277 | ##### list all watched shows - no limit 278 | 279 | ``` 280 | /opt/plexWatch/plexWatch.pl --watched 281 | ======================================== Watched ======================================== 282 | Date Range: Anytime through Now 283 | 284 | User: jimbo 285 | Wed Jun 26 15:56:09 2013: jimbo watched: South Park - A Nightmare on FaceTime [duration: 22 minutes, and 15 seconds] 286 | Wed Jun 26 20:18:34 2013: jimbo watched: The Following - Whips and Regret [duration: 46 minutes, and 45 seconds] 287 | Wed Jun 26 20:55:02 2013: jimbo watched: The Following - The Curse [duration: 46 minutes, and 15 seconds] 288 | 289 | User: carrie 290 | Wed Jun 24 08:55:02 2013: carrie watched: The Following - The Curse [duration: 46 minutes, and 25 seconds] 291 | Wed Jun 26 20:19:48 2013: carrie watched: Dumb and Dumber [1994] [PG-13] [duration: 1 hour, 7 minutes, and 10 seconds] 292 | ``` 293 | 294 | ##### list watched shows - limit by TODAY only 295 | 296 | ``` 297 | /opt/plexWatch/plexWatch.pl --watched --start=today --start=tomorrow 298 | 299 | ======================================== Watched ======================================== 300 | Date Range: Fri Jun 28 00:00:00 2013 through Sat Jun 29 00:00:00 2013 301 | 302 | User: jimbo 303 | Fri Jun 28 09:18:22 2013: jimbo watched: Married ... with Children - Mr. Empty Pants [duration: 1 hour, 23 minutes, and 20 seconds] 304 | ``` 305 | 306 | ##### list watched shows - limit by a start and stop date 307 | 308 | ``` 309 | /opt/plexWatch/plexWatch.pl --watched --start="2 days ago" --stop="1 day ago" 310 | 311 | ======================================== Watched ======================================== 312 | Date Range: Fri Jun 26 00:00:00 2013 through Thu Jun 27 00:00:00 2013 313 | 314 | User: Jimbo 315 | Wed Jun 26 15:56:09 2013: rarflix watched: South Park - A Nightmare on FaceTime [duration: 22 minutes, and 15 seconds] 316 | Wed Jun 26 20:18:34 2013: rarflix watched: The Following - Whips and Regret [duration: 46 minutes, and 45 seconds] 317 | Wed Jun 26 20:55:02 2013: rarflix watched: The Following - The Curse [duration: 46 minutes, and 15 seconds] 318 | 319 | User: Carrie 320 | Wed Jun 26 20:19:48 2013: Carrie watched: Dumb and Dumber [1994] [PG-13] [duration: 1 hour, 7 minutes, and 10 seconds] 321 | ``` 322 | 323 | #### list watched shows: option --nogrouping vs default 324 | 325 | ##### with --nogrouping 326 | ``` 327 | Sun Jun 30 15:12:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 27 minutes and 54 seconds] 328 | Sun Jun 30 15:41:02 2013: exampleUser watched: Your Highness [2011] [R] [duration: 4 minutes and 59 seconds] 329 | Sun Jun 30 15:46:02 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 24 minutes and 17 seconds] 330 | Sun Jun 30 17:48:01 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 1 hour, 44 minutes, and 1 second] 331 | Sun Jun 30 19:45:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 1 hour and 24 minutes] 332 | ``` 333 | 334 | ##### without --nogrouping [default] 335 | ``` 336 | Sun Jun 30 15:12:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 1 hour, 56 minutes, and 53 seconds] 337 | Sun Jun 30 15:46:02 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 2 hours, 8 minutes, and 18 seconds] 338 | ``` 339 | 340 | 341 | ### Stats - users total watched time with total per day 342 | 343 | * --start, --stop, --user options can be supplied to limit the output 344 | 345 | ``` 346 | /opt/plexWatch/plexWatch.pl --stats 347 | 348 | Date Range: Anytime through Now 349 | 350 | ======================================== Stats ======================================== 351 | 352 | user: Stans's total duration 3 hours and 56 seconds 353 | Thu Jul 11 2013: Stan 16 minutes and 58 seconds 354 | Fri Jul 12 2013: Stan 1 hour, 41 minutes, and 59 seconds 355 | Sat Jul 13 2013: Stan 1 hour, 1 minute, and 59 seconds 356 | 357 | user: Franks's total duration 2 hours, 43 minutes, and 2 seconds 358 | Thu Jul 4 2013: Frank 57 minutes and 1 second 359 | Sun Jul 14 2013: Frank 1 hour, 46 minutes, and 1 second 360 | ``` 361 | 362 | 363 | 364 |
365 | ## Additional options 366 | 367 | #### --notify 368 | 369 | ``` 370 | --user=... limit output to a specific user. Must be exact, case-insensitive 371 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2' 372 | ``` 373 | 374 | #### --stats 375 | 376 | ``` 377 | --start=... limit watched status output to content started AFTER/ON said date/time 378 | --stop=... limit watched status output to content started BEFORE/ON said date/time 379 | --user=... limit output to a specific user. Must be exact, case-insensitive 380 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2 381 | ``` 382 | #### --watched 383 | 384 | ``` 385 | --start=... limit watched status output to content started AFTER/ON said date/time 386 | --stop=... limit watched status output to content started BEFORE/ON said date/time 387 | --nogrouping will show same title multiple times if user has watched/resumed title on the same day 388 | --user=... limit output to a specific user. Must be exact, case-insensitive 389 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2' 390 | ``` 391 | 392 | 393 | ### Notification format 394 | 395 | * You can edit the format of your alerts and cli output or --watching --watched. This can be done in the config.pl or on the cli 396 | 397 | ####cli options: 398 | ``` 399 | --format_options : list all available formats for notifications and cli output 400 | 401 | --format_start=".." : modify start notification :: --format_start='{user} watching {title} on {platform}' 402 | 403 | --format_stop=".." : modify stop notification :: --format_stop='{user} watched {title} on {platform} for {duration}' 404 | 405 | --format_watched=".." : modify cli output for --watched :: --format_watched='{user} watched {title} on {platform} for {duration}' 406 | 407 | --format_watching=".." : modify cli output for --watching :: --format_watching='{user} watching {title} on {platform}' 408 | ``` 409 | 410 | ### Advanced --recently_added options 411 | ``` 412 | * All Movie Sections : ```./plexWatch.pl --recently_added=movie``` 413 | 414 | * All Movie / TV Sections : ```./plexWatch.pl --recently_added=movie,show``` 415 | 416 | * Specific Section(s) : ```./plexWatch.pl --recently_added --id=# --id=#``` 417 | 418 | ``` 419 | 420 | ./plexWatch.exe --recently_added 421 | 422 | * Available Sections: 423 | 424 | ID Title Type Path 425 | ------------------------------------------------------------------- 426 | 8 Concerts movie /NFS/Videos/Music 427 | 6 Movies movie /NFS/Videos/Film 428 | 17 Holiday Movies movie /NFS/Videos/Others/Holiday_Movies 429 | 5 TV Shows show /NFS/Videos/TV 430 | 431 | * Usage: 432 | 433 | All Movie Sections : ./plexWatch.pl --recently_added=movie 434 | All Movie/TV Sections : ./plexWatch.pl --recently_added=movie,show 435 | Specific Section(s) : ./plexWatch.pl --recently_added --id=# --id=# 436 | ``` 437 | 438 | 439 | ####config.pl options 440 | 441 | ```perl 442 | $alert_format = { 443 | 'start' => '{user} watching {title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in]', 444 | 'stop' => '{user} watched {title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%]', 445 | 'watched' => '{user} watched {title} [{streamtype}] [{year}] [{length}] [{rating}] on {platform} for {duration} [{percent_complete}%]', 446 | 'watching' => '{user} watching {title} [{streamtype}] [{year}] [{rating}] [{length}] on {platform} [{time_left} left]' 447 | }; 448 | 449 | ``` 450 | 451 | 452 | ####Format options Help 453 | ``` 454 | /opt/plexWatch/plexWatch.pl --format_options 455 | Format Options for alerts 456 | 457 | --start='{user} watching {title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in]' 458 | --stop='{user} watched {title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%]' 459 | --watched='{user} watched {title} [{streamtype}] [{year}] [{length}] [{rating}] on {platform} for {duration} [{percent_complete}%]' 460 | --watching='{user} watching {title} [{streamtype}] [{year}] [{rating}] [{length}] on {platform} [{time_left} left]' 461 | 462 | {percent_complete} Percent of video watched -- user could have only watched 5 minutes, but skipped to end = 100% 463 | {state} playing, paused or buffering [ or stopped ] (useful on --watching) 464 | {rating} rating of video - TV-MA, R, PG-13, etc 465 | {summary} summary or video 466 | {streamtype} T or D - for Transcoded or Direct 467 | {user} user 468 | {time_left} progress of video [only available/correct on --watching and stop events] 469 | {platform} client platform 470 | {transcoded} 1 or 0 - if transcoded 471 | {orig_user} orig_user 472 | {progress} progress of video [only available/correct on --watching and stop events] 473 | {duration} duration watched 474 | {length} length of video 475 | {stop_time} stop_time 476 | {title} title 477 | {start_start} start_time 478 | {year} year of video 479 | 480 | ``` 481 | 482 | 483 | 484 |
485 | ## Advanced options - config.pl 486 | 487 | #### Grouping of watched shows 488 | 489 | ``` 490 | $watched_show_completed = 1; always show completed show/movie as it's own line (default 1) 491 | ``` 492 | 493 | ``` 494 | $watched_grouping_maxhr = 2; do not group shows together if start/restart is > X hours (default is 3 hours) 495 | ``` 496 | 497 | #### SQLite backups 498 | 499 | By default this script will automatically backup the SQLite db to: $data_dir/db_backups/ ( normally: /opt/plexWatch/db_backups/ ) 500 | 501 | * you can force a Daily backup with --backup 502 | 503 | It will keep 2 x Daily , 4 x Weekly and 4 x Monthly backups. You can modify the backup policy by adding the config lines below to your existing config.pl 504 | ```perl 505 | $backup_opts = { 506 | 'daily' => { 507 | 'enabled' => 1, 508 | 'keep' => 2, 509 | }, 510 | 'monthly' => { 511 | 'enabled' => 1, 512 | 'keep' => 4, 513 | }, 514 | 'weekly' => { 515 | 'enabled' => 1, 516 | 'keep' => 4, 517 | }, 518 | }; 519 | ``` 520 | 521 | 522 |
523 | ## Help 524 | ``` 525 | /opt/plexWatch/plexWatch.pl --help 526 | ``` 527 | ``` 528 | PLEXWATCH(1) User Contributed Perl Documentation PLEXWATCH(1) 529 | 530 | NAME 531 | plexWatch.p - Notify and Log ’Now Playing’ and ’Watched’ content from a Plex Media Server + ’Recently Added 532 | 533 | SYNOPSIS 534 | plexWatch.pl [options] 535 | 536 | Options: 537 | 538 | --notify Notify any content watched and or stopped [this is default with NO options given] 539 | --user=... limit output to a specific user. Must be exact, case-insensitive 540 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2' 541 | 542 | --recently_added=show,movie notify when new movies or shows are added to the plex media server (required: config.pl: push_recentlyadded => 1) 543 | * you may specify only one or both on the same line separated by a comma. [--recently_added=show OR --recently_added=movie OR --recently_added=show,movie] 544 | 545 | --stats show total time watched / per day breakout included 546 | --start=... limit watched status output to content started AFTER/ON said date/time 547 | --stop=... limit watched status output to content started BEFORE/ON said date/time 548 | --user=... limit output to a specific user. Must be exact, case-insensitive 549 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2' 550 | 551 | --watched print watched content 552 | --start=... limit watched status output to content started AFTER/ON said date/time 553 | --stop=... limit watched status output to content started BEFORE/ON said date/time 554 | --nogrouping will show same title multiple times if user has watched/resumed title on the same day 555 | --user=... limit output to a specific user. Must be exact, case-insensitive 556 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2' 557 | 558 | --watching print content being watched 559 | 560 | --backup Force a daily backup of the database. 561 | * automatic backups are done daily,weekly,monthly - refer to backups section below 562 | 563 | ############################################################################################# 564 | 565 | --format_options : list all available formats for notifications and cli output 566 | 567 | --format_start=".." : modify start notification :: --format_start='{user} watching {title} on {platform}' 568 | 569 | --format_stop=".." : modify stop nottification :: --format_stop='{user} watched {title} on {platform} for {duration}' 570 | 571 | --format_watched=".." : modify cli output for --watched :: --format_watched='{user} watched {title} on {platform} for {duration}' 572 | 573 | --format_watching=".." : modify cli output for --watching :: --format_watching='{user} watching {title} on {platform}' 574 | 575 | ############################################################################################# 576 | * Debug Options 577 | 578 | --test_notify=start [start,stop,recent] - send a test notifcation for a start,stop or recently added event. 579 | --show_xml show xml result from api query 580 | --version what version is this? 581 | --debug hit and miss - not very useful 582 | 583 | OPTIONS 584 | --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 585 | options are given. 586 | 587 | --watched Print a list of watched content from all users. 588 | 589 | --start * only works with --watched 590 | 591 | limit watched status output to content started AFTER said date/time 592 | 593 | Valid options: dates, times and even fuzzy human times. Make sure you quote an values with spaces. 594 | 595 | -start=2013-06-29 596 | -start="2013-06-29 8:00pm" 597 | -start="today" 598 | -start="today at 8:30pm" 599 | -start="last week" 600 | -start=... give it a try and see what you can use :) 601 | 602 | --stop * only works with --watched 603 | 604 | limit watched status output to content started BEFORE said date/time 605 | 606 | Valid options: dates, times and even fuzzy human times. Make sure you quote an values with spaces. 607 | 608 | -stop=2013-06-29 609 | -stop="2013-06-29 8:00pm" 610 | -stop="today" 611 | -stop="today at 8:30pm" 612 | -stop="last week" 613 | -stop=... give it a try and see what you can use :) 614 | 615 | --nogrouping * only works with --watched 616 | 617 | will show same title multiple times if user has watched/resumed title on the same day 618 | 619 | with --nogrouping 620 | Sun Jun 30 15:12:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 27 minutes and 54 seconds] 621 | Sun Jun 30 15:41:02 2013: exampleUser watched: Your Highness [2011] [R] [duration: 4 minutes and 59 seconds] 622 | Sun Jun 30 15:46:02 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 24 minutes and 17 seconds] 623 | Sun Jun 30 17:48:01 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 1 hour, 44 minutes, and 1 second] 624 | Sun Jun 30 19:45:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 1 hour and 24 minutes] 625 | 626 | without --nogrouping [default] 627 | Sun Jun 30 15:12:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 1 hour, 56 minutes, and 53 seconds] 628 | Sun Jun 30 15:46:02 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 2 hours, 8 minutes, and 18 seconds] 629 | 630 | ---user * works with --watched and --watching 631 | 632 | limit output to a specific user. Must be exact, case-insensitive 633 | 634 | --exclude_user limit output to a specific user. Must be exact, case-insensitive 635 | 636 | --watching Print a list of content currently being watched 637 | 638 | --stats show total watched time and show total watched time per day 639 | 640 | --recently_added 641 | notify when new movies or shows are added to the plex media server (required: config.pl: push_recentlyadded => 1) 642 | 643 | --recently_added=movie :: for movies 644 | --recently_added=show :: for tv show/episodes 645 | 646 | --show_xml Print the XML result from query to the PMS server in regards to what is being watched. Could be useful for troubleshooting.. 647 | 648 | --backup By default this script will automatically backup the SQlite db to: $data_dir/db_backups/ ( normally: /opt/plexWatch/db_backups/ ) 649 | 650 | * you can force a Daily backup with --backup 651 | 652 | It will keep 2 x Daily , 4 x Weekly and 4 x Monthly backups. You can modify the backup policy by adding the config lines below to your existin config.pl 653 | 654 | $backup_opts = { 655 | ’daily’ => { 656 | ’enabled’ => 1, 657 | ’keep’ => 2, 658 | }, 659 | ’monthly’ => { 660 | ’enabled’ => 1, 661 | ’keep’ => 4, 662 | }, 663 | ’weekly’ => { 664 | ’enabled’ => 1, 665 | ’keep’ => 4, 666 | }, 667 | }; 668 | 669 | --debug This can be used. I have not fully set everything for debugging.. so it’s not very useful 670 | 671 | DESCRIPTION 672 | This program will Notify and Log ’Now Playing’ content from a Plex Media Server 673 | 674 | HELP 675 | nothing to see here. 676 | 677 | perl v5.10.1 2013-08-13 PLEXWATCH(1) 678 | ``` 679 | 680 | 681 | 682 |
683 | ## FAQ 684 | 685 | * __How do I test notifications__ 686 | ---- 687 | 688 | __Answer__ 689 | 690 | ``` 691 | Make sure you have enabled a provider in the config.pl 692 | 693 | ./plexWatch.pl --test_notify=start 694 | ./plexWatch.pl --test_notify=stop 695 | ./plexWatch.pl --test_notify=recent 696 | 697 | ``` 698 | 699 | 700 | 701 | * __I receive this error when running a test notification:__ 702 | ---- 703 | 704 | ``` 705 | Can't verify SSL peers without knowning which Certificate Authorities to trust 706 | 707 | This problem can be fixed by either setting the PERL_LWP_SSL_CA_FILE 708 | envirionment variable or by installing the Mozilla::CA module. 709 | ``` 710 | 711 | __Answer__ 712 | 713 | ``` 714 | sudo cpan 715 | install LWP::UserAgent Mozilla::CA 716 | ``` 717 | 718 | __OSX__ 719 | * remove homebrew and macports. Force reinstalled modules, highly recommend installing Mozilla::CA prior to LWP::UserAgent 720 | 721 | 722 | 723 | * __How do I setup a launchagent in OSX__ 724 | ---- 725 | 726 | __Answer__ 727 | 728 | Create a LaunchAgent plist file, called com.rcork.plexwatch.plist. This should be saved in ~/Library/LaunchAgents/ 729 | 730 | ``` 731 | vim ~/Library/LaunchAgents/com.rcork.plexwatch.plist 732 | ``` 733 | Paste this text into the file, changing the /path/to/your/plexWatch variable, as appropriate. If you followed the directions above, this should be /opt/plexWatch/plexWatch.pl 734 | 735 | ```xml 736 | 737 | 738 | 739 | 740 | Label 741 | com.rcork.plexwatch 742 | ProgramArguments 743 | 744 | /usr/bin/perl 745 | /path/to/your/plexWatch/plexWatch.pl 746 | -notify 747 | -recently_added=movie,show 748 | 749 | StartInterval 750 | 30 751 | 752 | 753 | ``` 754 | 755 | After you edit and save the file, you need to load the LaunchAgent: 756 | ``` 757 | launchctl load ~/Library/LaunchAgents/com.rcork.plexwatch.plist 758 | ``` 759 | 760 | 761 | * __How do I install on OSX__ 762 | ---- 763 | 764 | __Answer__ 765 | 766 | : User contribution - Thanks rcork! 767 | 768 | Here are the steps to get it running on OSX. This was done with a clean install of OSX. 769 | * refer to the INSTALL section above for more details. This is a brief rundown. 770 | 771 | 1. Download plexWatch from github and unzip 772 | 2. Copy config.pl-dist to config.pl and modify for your notification options 773 | 3. Install XCode from Mac App Strore 774 | 4. Install XCode command line tools by launching XCode, going to preferences, downloads, Install Command Line Tools 775 | 1. If this does not work, from Terminal, type "xcode-select --install" 776 | 2. Software Update should now prompt you to install the Developer Tools. Install them. 777 | 5. Configure CPAN 778 | 1. Launch Terminal.app 779 | 2. Type "cpan" without the quotes and press enter 780 | 3. If this is first time launching cpan, it will ask if you want to automatically configure. Hit Enter 781 | 1. It will ask if you want to automatically pick download mirrors. Type No and hit enter 782 | 2. Pick mirrors for your region. I've had the best luck with .edu mirrors 783 | 4. Type "install CPAN" without the quotes and hit enter. This will update cpan to the latest version 784 | 5. Type "reload cpan" without the quotes and hit enter. 785 | 6. Type "exit" without the quotes and hit enter 786 | 7. Install required perl modules from Terminal 787 | 788 | ``` 789 | sudo cpan install Time::Duration 790 | sudo cpan install Time::ParseDate 791 | sudo cpan install Net::Twitter::Lite::WithAPIv1_1 792 | sudo cpan install Net::OAuth 793 | sudo cpan install Mozilla::CA 794 | sudo cpan install JSON 795 | ``` 796 | 7. Now create data directory and set permission. Replace [user] with your username 797 | 798 | ``` 799 | sudo mkdir /opt 800 | sudo mkdir /opt/plexWatch 801 | sudo chown [user]:staff /opt/plexWatch 802 | ``` 803 | 8. Run plexWatch from Terminal. You shouldn't receive any errors or warnings 804 | ``` 805 | ./plexWatch.pl 806 | ``` 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | ---- 815 | Idea, thanks to https://github.com/vwieczorek/plexMon. I initially had a really horrible script used to parse the log files... http://IP:PORT/status/sessions is much more useful. This was whipped up in an hour or two.. I am sure it could use some more work. 816 | -------------------------------------------------------------------------------- /README.windows.md: -------------------------------------------------------------------------------- 1 | plexWatch - v0.2.8 - WIN32 2 | ========= 3 | 4 | ***Notify*** and Log ***'Now Playing'*** and ***'Watched'*** content from a Plex Media Server + ***'Recently Added'*** (...and more) 5 | 6 | 7 | [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CHRZ55VCAJSYG) 8 | 9 | http://forums.plexapp.com/index.php/topic/72552-plexwatch-plex-notify-script-send-push-alerts-on-new-sessions-and-stopped/ 10 | 11 | 12 | **Supported Push Notifications** 13 | * https://pushover.net 14 | * https://prowlapp.com 15 | * http://growl.info/ (via GrowlNotify @ http://growl.info/downloads#generaldownloads) 16 | * https://twitter.com/ (create a new app @ https://dev.twitter.com/apps) 17 | * https://boxcar.io/ 18 | * SNARL/GROWL: GNTP notifications supported. Anything that uses GNTP *should* work 19 | 20 | **What it does** 21 | * notify when a user starts watching a video 22 | * notify when a user stops watching a video 23 | * notify on recently added content to a PMS server 24 | * notifies via prowl, pushover, growl, twitter, boxcar, GNTP and/or a log file 25 | * enable/disable notifications per provider & per notification type (watching, watched, recently added) 26 | * backed by a SQLite DB (for state and history) 27 | * CLI to query watched videos, videos being watched and stats on time watched per user 28 | * Limit output per user or exclude users 29 | * ...more to come 30 | 31 | 32 | ###Perl Requirements 33 | 34 | * LWP::UserAgent 35 | * XML::Simple 36 | * DBI 37 | * Time::Duration; 38 | * Time::ParseDate; 39 | 40 | 41 | #### These should be part of the bast Perl install 42 | 43 | * Pod::Usage; (Perl base on rhel/centos) 44 | * Fcntl qw(:flock); (Perl base) 45 | * Getopt::Long; (Perl base) 46 | * POSIX qw(strftime) (Perl base) 47 | * File::Basename (Perl base) 48 | 49 | 50 | #### Required ONLY if you use twitter 51 | 52 | * Net::Twitter::Lite::WithAPIv1_1 53 | * Net::OAuth 54 | 55 | 56 | #### Required ONLY if you use GNTP 57 | 58 | * Growl::GNTP 59 | 60 | 61 | #### Required ONLY if 'Client IP Logging' is enable 62 | 63 | * File::ReadBackwards 64 | 65 | * To enable: edit config.pl 66 | 67 | ``` 68 | $server_log = '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log'; ## used to log IP address of user (alpha) 69 | $log_client_ip = 1; ## requires $server_log to be available too. 70 | $debug_logging = 1; ## logs to $data_dir/debug.log ( only really helps debug IP logging for now ) 71 | ``` 72 | 73 | ``` 74 | # Debian/Ubuntu: apt-get 75 | sudo apt-get install libfile-readbackwards-perl 76 | 77 | # Rhel/Centos: yum 78 | sudo yum install perl\(File::ReadBackwards\) 79 | 80 | # Others: cpan 81 | sudo cpan File::ReadBackwards 82 | ``` 83 | 84 | 85 |
86 | 87 | ### Install 88 | ---- 89 | 90 | 1. Download plexWatch.pl and config.pl-dist to /opt/plexWatch/ 91 | * WGET 92 | 93 | ``` 94 | sudo wget -P /opt/plexWatch/ https://raw.github.com/ljunkie/plexWatch/master/plexWatch.pl 95 | sudo wget -P /opt/plexWatch/ https://raw.github.com/ljunkie/plexWatch/master/config.pl-dist 96 | ```` 97 | * CURL 98 | 99 | ``` 100 | sudo mkdir -p /opt/plexWatch/ 101 | sudo curl https://raw.github.com/ljunkie/plexWatch/master/plexWatch.pl -o /opt/plexWatch/plexWatch.pl 102 | sudo curl https://raw.github.com/ljunkie/plexWatch/master/config.pl-dist -o /opt/plexWatch/config.pl-dist 103 | ``` 104 | 105 | 2. ```sudo chmod 777 /opt/plexWatch && sudo chmod 755 /opt/plexWatch/plexWatch.pl``` 106 | 107 | 3. ```sudo cp /opt/plexWatch/config.pl-dist /opt/plexWatch/config.pl``` 108 | 1. ```sudo nano /opt/plexWatch/config.pl``` 109 | * Modify Variables as needed 110 | 111 | ```perl 112 | $server = 'localhost'; ## IP of PMS - or localhost 113 | $port = 32400; ## port of PMS 114 | $notify_started = 1; ## notify when a stream is started (first play) 115 | $notify_stopped = 1; ## notify when a stream is stopped 116 | ``` 117 | 118 | ```bash 119 | $notify = {... 120 | * to enable a provider, i.e. file, prowl, pushover 121 | set 'enabled' => 1, under selected provider 122 | * Prowl : 'apikey' required 123 | * Pushover : 'token' and 'user' required 124 | * Growl : 'script' required :: GrowlNotify from http://growl.info/downloads (GNTP replaces this) 125 | * twitter : 'consumer_key', 'consumer_secret', 'access_token', 'access_token_secret' required 126 | * boxcar : 'email' required 127 | * GNTP : 'server', 'port' required. 'password' optional. You must allow network notifications on the Growl Server 128 | ``` 129 | 130 | 4. Install Perl requirements 131 | * Debian/Ubuntu - apt-get 132 | 133 | ```bash 134 | sudo apt-get install libwww-perl 135 | 136 | sudo apt-get install libxml-simple-perl 137 | 138 | sudo apt-get install libtime-duration-perl 139 | 140 | sudo apt-get install libtime-modules-perl 141 | 142 | sudo apt-get install libdbd-sqlite3-perl 143 | 144 | sudo apt-get install perl-doc 145 | ``` 146 | * RHEL/Centos - yum 147 | 148 | ```bash 149 | yum -y install perl\(LWP::UserAgent\) perl\(XML::Simple\) \ 150 | perl\(DBI\) perl\(Time::Duration\) perl\(Time::ParseDate\) 151 | ``` 152 | 153 | 5. **run** the script manually to verify it works: /opt/plexWatch/plexWatch.pl 154 | * start video(s) 155 | * ```/opt/plexWatch/plexWatch.pl``` 156 | * stop video(s) 157 | * ```/opt/plexWatch/plexWatch.pl``` 158 | 159 | 160 | 6. setup crontab or launchagent to run the script every minute 161 | * __linux__: /etc/crontab 162 | 163 | ```bash 164 | * * * * * YOUR_USERNAME /opt/plexWatch/plexWatch.pl 165 | ``` 166 | * __OSX__: use a launchagent instead of cron. Refer to the __FAQ__ on the bottom. 167 | 168 | 169 |
170 | 171 | ### Twitter integration 172 | ---- 173 | If you want to use twitter, you will need to install two more Perl modules 174 | 175 | * requires Net::Twitter::Lite::WithAPIv1_1 176 | 177 | ```bash 178 | sudo cpan Net::Twitter::Lite::WithAPIv1_1 179 | 180 | # OR force install it 181 | sudo cpan -f Net::Twitter::Lite::WithAPIv1_1 182 | ``` 183 | 184 | * requires Net::OAuth >= 0.28 185 | 186 | ```bash 187 | sudo cpan Net::OAuth 188 | 189 | # OR force install it 190 | sudo cpan -f Net::OAuth 191 | ``` 192 | 193 | #### Twitter setup 194 | * create a new app @ https://dev.twitter.com/apps 195 | * make sure to set set ApplicationType to read/write 196 | * enable notification for twitter in config.pl 197 | 198 | 199 | 200 |
201 | ### GNTP integration 202 | ---- 203 | If you want to use GNTP (growl), you will need to install a module 204 | 205 | * requires Growl::GNTP 206 | 207 | ```bash 208 | sudo cpan Growl::GNTP 209 | ``` 210 | * Note: CPAN install failed on centos until I installed perl\(Data::UUID\) 211 | 212 | 213 | 214 |
215 | ## Using the script 216 | 217 | 218 | ### Sending Notifications 219 | 220 | * Follow the install guide above, and refer to step #5 and #6 221 | 222 | * Sending test notifications: 223 | 224 | ``` 225 | /opt/plexWatch/plexWatch.pl --test_notify=start 226 | 227 | /opt/plexWatch/plexWatch.pl --test_notify=stop 228 | ``` 229 | 230 | ### Getting a list of watched shows 231 | 232 | * This will only work for shows this has already notified on. 233 | 234 | ##### list all watched shows - no limit 235 | 236 | ``` 237 | /opt/plexWatch/plexWatch.pl --watched 238 | ======================================== Watched ======================================== 239 | Date Range: Anytime through Now 240 | 241 | User: jimbo 242 | Wed Jun 26 15:56:09 2013: jimbo watched: South Park - A Nightmare on FaceTime [duration: 22 minutes, and 15 seconds] 243 | Wed Jun 26 20:18:34 2013: jimbo watched: The Following - Whips and Regret [duration: 46 minutes, and 45 seconds] 244 | Wed Jun 26 20:55:02 2013: jimbo watched: The Following - The Curse [duration: 46 minutes, and 15 seconds] 245 | 246 | User: carrie 247 | Wed Jun 24 08:55:02 2013: carrie watched: The Following - The Curse [duration: 46 minutes, and 25 seconds] 248 | Wed Jun 26 20:19:48 2013: carrie watched: Dumb and Dumber [1994] [PG-13] [duration: 1 hour, 7 minutes, and 10 seconds] 249 | ``` 250 | 251 | ##### list watched shows - limit by TODAY only 252 | 253 | ``` 254 | /opt/plexWatch/plexWatch.pl --watched --start=today --start=tomorrow 255 | 256 | ======================================== Watched ======================================== 257 | Date Range: Fri Jun 28 00:00:00 2013 through Sat Jun 29 00:00:00 2013 258 | 259 | User: jimbo 260 | Fri Jun 28 09:18:22 2013: jimbo watched: Married ... with Children - Mr. Empty Pants [duration: 1 hour, 23 minutes, and 20 seconds] 261 | ``` 262 | 263 | ##### list watched shows - limit by a start and stop date 264 | 265 | ``` 266 | /opt/plexWatch/plexWatch.pl --watched --start="2 days ago" --stop="1 day ago" 267 | 268 | ======================================== Watched ======================================== 269 | Date Range: Fri Jun 26 00:00:00 2013 through Thu Jun 27 00:00:00 2013 270 | 271 | User: Jimbo 272 | Wed Jun 26 15:56:09 2013: rarflix watched: South Park - A Nightmare on FaceTime [duration: 22 minutes, and 15 seconds] 273 | Wed Jun 26 20:18:34 2013: rarflix watched: The Following - Whips and Regret [duration: 46 minutes, and 45 seconds] 274 | Wed Jun 26 20:55:02 2013: rarflix watched: The Following - The Curse [duration: 46 minutes, and 15 seconds] 275 | 276 | User: Carrie 277 | Wed Jun 26 20:19:48 2013: Carrie watched: Dumb and Dumber [1994] [PG-13] [duration: 1 hour, 7 minutes, and 10 seconds] 278 | ``` 279 | 280 | #### list watched shows: option --nogrouping vs default 281 | 282 | ##### with --nogrouping 283 | ``` 284 | Sun Jun 30 15:12:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 27 minutes and 54 seconds] 285 | Sun Jun 30 15:41:02 2013: exampleUser watched: Your Highness [2011] [R] [duration: 4 minutes and 59 seconds] 286 | Sun Jun 30 15:46:02 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 24 minutes and 17 seconds] 287 | Sun Jun 30 17:48:01 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 1 hour, 44 minutes, and 1 second] 288 | Sun Jun 30 19:45:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 1 hour and 24 minutes] 289 | ``` 290 | 291 | ##### without --nogrouping [default] 292 | ``` 293 | Sun Jun 30 15:12:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 1 hour, 56 minutes, and 53 seconds] 294 | Sun Jun 30 15:46:02 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 2 hours, 8 minutes, and 18 seconds] 295 | ``` 296 | 297 | 298 | ### Stats - users total watched time with total per day 299 | 300 | * --start, --stop, --user options can be supplied to limit the output 301 | 302 | ``` 303 | /opt/plexWatch/plexWatch.pl --stats 304 | 305 | Date Range: Anytime through Now 306 | 307 | ======================================== Stats ======================================== 308 | 309 | user: Stans's total duration 3 hours and 56 seconds 310 | Thu Jul 11 2013: Stan 16 minutes and 58 seconds 311 | Fri Jul 12 2013: Stan 1 hour, 41 minutes, and 59 seconds 312 | Sat Jul 13 2013: Stan 1 hour, 1 minute, and 59 seconds 313 | 314 | user: Franks's total duration 2 hours, 43 minutes, and 2 seconds 315 | Thu Jul 4 2013: Frank 57 minutes and 1 second 316 | Sun Jul 14 2013: Frank 1 hour, 46 minutes, and 1 second 317 | ``` 318 | 319 | 320 | 321 |
322 | ## Additional options 323 | 324 | #### --notify 325 | 326 | ``` 327 | --user=... limit output to a specific user. Must be exact, case-insensitive 328 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2' 329 | ``` 330 | 331 | #### --stats 332 | 333 | ``` 334 | --start=... limit watched status output to content started AFTER/ON said date/time 335 | --stop=... limit watched status output to content started BEFORE/ON said date/time 336 | --user=... limit output to a specific user. Must be exact, case-insensitive 337 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2 338 | ``` 339 | #### --watched 340 | 341 | ``` 342 | --start=... limit watched status output to content started AFTER/ON said date/time 343 | --stop=... limit watched status output to content started BEFORE/ON said date/time 344 | --nogrouping will show same title multiple times if user has watched/resumed title on the same day 345 | --user=... limit output to a specific user. Must be exact, case-insensitive 346 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2' 347 | ``` 348 | 349 | 350 | 351 |
g 352 | ## Notification format 353 | 354 | * You can edit the format of your alerts and cli output or --watching --watched. This can be done in the config.pl or on the cli 355 | 356 | ####cli options: 357 | ``` 358 | --format_options : list all available formats for notifications and cli output 359 | 360 | --format_start=".." : modify start notification :: --format_start='{user} watching {title} on {platform}' 361 | 362 | --format_stop=".." : modify stop notification :: --format_stop='{user} watched {title} on {platform} for {duration}' 363 | 364 | --format_watched=".." : modify cli output for --watched :: --format_watched='{user} watched {title} on {platform} for {duration}' 365 | 366 | --format_watching=".." : modify cli output for --watching :: --format_watching='{user} watching {title} on {platform}' 367 | ``` 368 | 369 | 370 | ####config.pl options 371 | 372 | ```perl 373 | $alert_format = { 374 | 'start' => '{user} watching {title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in]', 375 | 'stop' => '{user} watched {title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%]', 376 | 'watched' => '{user} watched {title} [{streamtype}] [{year}] [{length}] [{rating}] on {platform} for {duration} [{percent_complete}%]', 377 | 'watching' => '{user} watching {title} [{streamtype}] [{year}] [{rating}] [{length}] on {platform} [{time_left} left]' 378 | }; 379 | 380 | ``` 381 | 382 | 383 | ####Format options Help 384 | ``` 385 | /opt/plexWatch/plexWatch.pl --format_options 386 | Format Options for alerts 387 | 388 | --start='{user} watching {title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in]' 389 | --stop='{user} watched {title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%]' 390 | --watched='{user} watched {title} [{streamtype}] [{year}] [{length}] [{rating}] on {platform} for {duration} [{percent_complete}%]' 391 | --watching='{user} watching {title} [{streamtype}] [{year}] [{rating}] [{length}] on {platform} [{time_left} left]' 392 | 393 | {percent_complete} Percent of video watched -- user could have only watched 5 minutes, but skipped to end = 100% 394 | {state} playing, paused or buffering [ or stopped ] (useful on --watching) 395 | {rating} rating of video - TV-MA, R, PG-13, etc 396 | {summary} summary or video 397 | {streamtype} T or D - for Transcoded or Direct 398 | {user} user 399 | {time_left} progress of video [only available/correct on --watching and stop events] 400 | {platform} client platform 401 | {transcoded} 1 or 0 - if transcoded 402 | {orig_user} orig_user 403 | {progress} progress of video [only available/correct on --watching and stop events] 404 | {duration} duration watched 405 | {length} length of video 406 | {stop_time} stop_time 407 | {title} title 408 | {start_start} start_time 409 | {year} year of video 410 | 411 | ``` 412 | 413 | 414 | 415 |
416 | ## Advanced options - config.pl 417 | 418 | #### Grouping of watched shows 419 | 420 | ``` 421 | $watched_show_completed = 1; always show completed show/movie as it's own line (default 1) 422 | ``` 423 | 424 | ``` 425 | $watched_grouping_maxhr = 2; do not group shows together if start/restart is > X hours (default is 3 hours) 426 | ``` 427 | 428 | #### SQLite backups 429 | 430 | By default this script will automatically backup the SQLite db to: $data_dir/db_backups/ ( normally: /opt/plexWatch/db_backups/ ) 431 | 432 | * you can force a Daily backup with --backup 433 | 434 | It will keep 2 x Daily , 4 x Weekly and 4 x Monthly backups. You can modify the backup policy by adding the config lines below to your existing config.pl 435 | ```perl 436 | $backup_opts = { 437 | 'daily' => { 438 | 'enabled' => 1, 439 | 'keep' => 2, 440 | }, 441 | 'monthly' => { 442 | 'enabled' => 1, 443 | 'keep' => 4, 444 | }, 445 | 'weekly' => { 446 | 'enabled' => 1, 447 | 'keep' => 4, 448 | }, 449 | }; 450 | ``` 451 | 452 | 453 |
454 | ## Help 455 | ``` 456 | /opt/plexWatch/plexWatch.pl --help 457 | ``` 458 | ``` 459 | PLEXWATCH(1) User Contributed Perl Documentation PLEXWATCH(1) 460 | 461 | NAME 462 | plexWatch.p - Notify and Log ’Now Playing’ and ’Watched’ content from a Plex Media Server + ’Recently Added 463 | 464 | SYNOPSIS 465 | plexWatch.pl [options] 466 | 467 | Options: 468 | 469 | --notify Notify any content watched and or stopped [this is default with NO options given] 470 | --user=... limit output to a specific user. Must be exact, case-insensitive 471 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2' 472 | 473 | --recently_added=show,movie notify when new movies or shows are added to the plex media server (required: config.pl: push_recentlyadded => 1) 474 | * you may specify only one or both on the same line separated by a comma. [--recently_added=show OR --recently_added=movie OR --recently_added=show,movie] 475 | 476 | --stats show total time watched / per day breakout included 477 | --start=... limit watched status output to content started AFTER/ON said date/time 478 | --stop=... limit watched status output to content started BEFORE/ON said date/time 479 | --user=... limit output to a specific user. Must be exact, case-insensitive 480 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2' 481 | 482 | --watched print watched content 483 | --start=... limit watched status output to content started AFTER/ON said date/time 484 | --stop=... limit watched status output to content started BEFORE/ON said date/time 485 | --nogrouping will show same title multiple times if user has watched/resumed title on the same day 486 | --user=... limit output to a specific user. Must be exact, case-insensitive 487 | --exclude_user=... exclude users - you may specify multiple on the same line. '--notify --exclude_user=user1 --exclude_user=user2' 488 | 489 | --watching print content being watched 490 | 491 | --backup Force a daily backup of the database. 492 | * automatic backups are done daily,weekly,monthly - refer to backups section below 493 | 494 | ############################################################################################# 495 | 496 | --format_options : list all available formats for notifications and cli output 497 | 498 | --format_start=".." : modify start notification :: --format_start='{user} watching {title} on {platform}' 499 | 500 | --format_stop=".." : modify stop nottification :: --format_stop='{user} watched {title} on {platform} for {duration}' 501 | 502 | --format_watched=".." : modify cli output for --watched :: --format_watched='{user} watched {title} on {platform} for {duration}' 503 | 504 | --format_watching=".." : modify cli output for --watching :: --format_watching='{user} watching {title} on {platform}' 505 | 506 | ############################################################################################# 507 | * Debug Options 508 | 509 | --test_notify=start [start,stop,recent] - send a test notifcation for a start,stop or recently added event. 510 | --show_xml show xml result from api query 511 | --version what version is this? 512 | --debug hit and miss - not very useful 513 | 514 | OPTIONS 515 | --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 516 | options are given. 517 | 518 | --watched Print a list of watched content from all users. 519 | 520 | --start * only works with --watched 521 | 522 | limit watched status output to content started AFTER said date/time 523 | 524 | Valid options: dates, times and even fuzzy human times. Make sure you quote an values with spaces. 525 | 526 | -start=2013-06-29 527 | -start="2013-06-29 8:00pm" 528 | -start="today" 529 | -start="today at 8:30pm" 530 | -start="last week" 531 | -start=... give it a try and see what you can use :) 532 | 533 | --stop * only works with --watched 534 | 535 | limit watched status output to content started BEFORE said date/time 536 | 537 | Valid options: dates, times and even fuzzy human times. Make sure you quote an values with spaces. 538 | 539 | -stop=2013-06-29 540 | -stop="2013-06-29 8:00pm" 541 | -stop="today" 542 | -stop="today at 8:30pm" 543 | -stop="last week" 544 | -stop=... give it a try and see what you can use :) 545 | 546 | --nogrouping * only works with --watched 547 | 548 | will show same title multiple times if user has watched/resumed title on the same day 549 | 550 | with --nogrouping 551 | Sun Jun 30 15:12:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 27 minutes and 54 seconds] 552 | Sun Jun 30 15:41:02 2013: exampleUser watched: Your Highness [2011] [R] [duration: 4 minutes and 59 seconds] 553 | Sun Jun 30 15:46:02 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 24 minutes and 17 seconds] 554 | Sun Jun 30 17:48:01 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 1 hour, 44 minutes, and 1 second] 555 | Sun Jun 30 19:45:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 1 hour and 24 minutes] 556 | 557 | without --nogrouping [default] 558 | Sun Jun 30 15:12:01 2013: exampleUser watched: Your Highness [2011] [R] [duration: 1 hour, 56 minutes, and 53 seconds] 559 | Sun Jun 30 15:46:02 2013: exampleUser watched: Star Trek [2009] [PG-13] [duration: 2 hours, 8 minutes, and 18 seconds] 560 | 561 | ---user * works with --watched and --watching 562 | 563 | limit output to a specific user. Must be exact, case-insensitive 564 | 565 | --exclude_user limit output to a specific user. Must be exact, case-insensitive 566 | 567 | --watching Print a list of content currently being watched 568 | 569 | --stats show total watched time and show total watched time per day 570 | 571 | --recently_added 572 | notify when new movies or shows are added to the plex media server (required: config.pl: push_recentlyadded => 1) 573 | 574 | --recently_added=movie :: for movies 575 | --recently_added=show :: for tv show/episodes 576 | 577 | --show_xml Print the XML result from query to the PMS server in regards to what is being watched. Could be useful for troubleshooting.. 578 | 579 | --backup By default this script will automatically backup the SQlite db to: $data_dir/db_backups/ ( normally: /opt/plexWatch/db_backups/ ) 580 | 581 | * you can force a Daily backup with --backup 582 | 583 | It will keep 2 x Daily , 4 x Weekly and 4 x Monthly backups. You can modify the backup policy by adding the config lines below to your existin config.pl 584 | 585 | $backup_opts = { 586 | ’daily’ => { 587 | ’enabled’ => 1, 588 | ’keep’ => 2, 589 | }, 590 | ’monthly’ => { 591 | ’enabled’ => 1, 592 | ’keep’ => 4, 593 | }, 594 | ’weekly’ => { 595 | ’enabled’ => 1, 596 | ’keep’ => 4, 597 | }, 598 | }; 599 | 600 | --debug This can be used. I have not fully set everything for debugging.. so it’s not very useful 601 | 602 | DESCRIPTION 603 | This program will Notify and Log ’Now Playing’ content from a Plex Media Server 604 | 605 | HELP 606 | nothing to see here. 607 | 608 | perl v5.10.1 2013-08-13 PLEXWATCH(1) 609 | ``` 610 | 611 | 612 | 613 |
614 | ## FAQ 615 | 616 | * __How do I test notifications__ 617 | ---- 618 | 619 | __Answer__ 620 | 621 | ``` 622 | Make sure you have enabled a provider in the config.pl 623 | 624 | ./plexWatch.pl --test_notify=start 625 | ./plexWatch.pl --test_notify=stop 626 | ./plexWatch.pl --test_notify=recent 627 | 628 | ``` 629 | 630 | 631 | 632 | * __I receive this error when running a test notification:__ 633 | ---- 634 | 635 | ``` 636 | Can't verify SSL peers without knowning which Certificate Authorities to trust 637 | 638 | This problem can be fixed by either setting the PERL_LWP_SSL_CA_FILE 639 | envirionment variable or by installing the Mozilla::CA module. 640 | ``` 641 | 642 | __Answer__ 643 | 644 | ``` 645 | sudo cpan 646 | install LWP::UserAgent Mozilla::CA 647 | ``` 648 | 649 | __OSX__ 650 | * remove homebrew and macports. Force reinstalled modules, highly recommend installing Mozilla::CA prior to LWP::UserAgent 651 | 652 | 653 | 654 | * __How do I setup a launchagent in OSX__ 655 | ---- 656 | 657 | __Answer__ 658 | 659 | 660 | ```xml 661 | 662 | 663 | 664 | 665 | Label 666 | com.rcork.plexwatch 667 | ProgramArguments 668 | 669 | /usr/bin/perl 670 | /path/to/your/plexWatch/plexWatch.pl 671 | -notify 672 | -recently_added=movie,show 673 | 674 | StartInterval 675 | 30 676 | 677 | 678 | ``` 679 | 680 | 681 | 682 | * __How do I install on OSX__ 683 | ---- 684 | 685 | __Answer__ 686 | 687 | : User contribution - Thanks rcork! 688 | 689 | Here are the steps to get it running on OSX. This was done with a clean install of OSX. 690 | * refer to the INSTALL section above for more details. This is a brief rundown. 691 | 692 | 1. Download plexWatch from github and unzip 693 | 2. Copy config.pl-dist to config.pl and modify for your notification options 694 | 3. Install XCode from Mac App Strore 695 | 4. Install XCode command line tools by launching XCode, going to preferences, downloads, Install Command Line Tools 696 | 5. Configure CPAN 697 | 1. Launch Terminal.app 698 | 2. Type "cpan" without the quotes and press enter 699 | 3. If this is first time launching cpan, it will ask if you want to automatically configure. Hit Enter 700 | 1. It will ask if you want to automatically pick download mirrors. Type No and hit enter 701 | 2. Pick mirrors for your region. I've had the best luck with .edu mirrors 702 | 4. Type "install cpan" without the quotes and hit enter. This will update cpan to the latest version 703 | 5. Type "reload cpan" without the quotes and hit enter. 704 | 6. Type "exit" without the quotes and hit enter 705 | 7. Install required perl modules from Terminal 706 | 707 | ``` 708 | sudo cpan install Time::Duration 709 | sudo cpan install Time::ParseDate 710 | sudo cpan install Net::Twitter::Lite::WithAPIv1_1 711 | sudo cpan install Net::OAuth 712 | sudo cpan install Mozilla::CA 713 | ``` 714 | 7. Now create data directory and set permission. Replace [user] with your username 715 | 716 | ``` 717 | sudo mkdir /opt 718 | sudo mkdir /opt/plexWatch 719 | sudo chown [user]:staff /opt/plexWatch 720 | ``` 721 | 8. Run plexWatch from Terminal. You shouldn't receive any errors or warnings 722 | ``` 723 | ./plexWatch.pl 724 | ``` 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | ---- 733 | Idea, thanks to https://github.com/vwieczorek/plexMon. I initially had a really horrible script used to parse the log files... http://IP:PORT/status/sessions is much more useful. This was whipped up in an hour or two.. I am sure it could use some more work. 734 | -------------------------------------------------------------------------------- /change.log: -------------------------------------------------------------------------------- 1 | # 0.2.1 2 | * new format option '{streamtype_extended}' -- includes the Audio/Video decision: "Direct Play" or "Audio:copy Video:transcode" 3 | * cleanup ipv6 comptable ipv4 address 4 | * twitter fixes (API change) h/t @RaginBajin 5 | 6 | # 0.2.0 7 | * fix logic for grouping table ( important fix -- data could be incorrect prior to version 0.2.0 ) 8 | * when version changes, the DB will auto upgrade/backup 9 | 10 | # 0.1.9 11 | * grouped table was not using the right paused field (paused_counter) -- fixes paused display in plexWatch/Web 12 | * EMAIL now requires Net::SMTPS -- Net::SMTP::TLS is junk (deprecated/abandoned) 13 | 14 | # 0.1.8 15 | * Windows EMAIL fix: TLS/SSL authentication is now supported 16 | * EMAIL notifications now requires Net::SMTPS ( windows is built in ) 17 | 18 | # 0.1.7 19 | * --recently_added allow users to specify specific sections ( more info: --recently_added ) 20 | * --exclude_user will mute a notification, but still be logged to the DB. useful for plexWeb/Watch 21 | * --recently_added empty notifications: skip item if scanner is still processing ( we will come back to it later ) 22 | * speedup: do not autovaccum on every run 23 | * recreate grouped table daily. Any changes made to config.pl will reflect within 24 hours ( or just call --backup ) 24 | 25 | # 0.1.6 26 | * DB update: switch from xml to json for config storage 27 | 28 | # 0.1.5 29 | * DB update: include config in DB for plexWatch/Web 30 | 31 | # 0.1.4 32 | * added config table for plexWatch/Web - or - any other external apps wanted to parse the config 33 | * Added grouped table for plexWatch/Web - or - any other external apps needing to query for a grouped output 34 | * Twitter now works for windows 35 | * Linux and Windows branches are now on the same code base (dev merged in 0.1.1, now master up to date) 36 | 37 | # 0.1.3-dev 38 | * added config table for plexWatch/Web - or - any other external apps wanted to parse the config 39 | 40 | # 0.1.2-dev 41 | * Added grouped table for plexWatch/Web - or - any other external apps needing to query for a grouped output 42 | 43 | # 0.1.1-dev 44 | * Twitter now works for windows 45 | * Linux and Windows branches (dev) are now on the same code base. 46 | 47 | # 0.1.0 - Final 48 | * NEW: Email provider ( NonAuth, Auth, TLS/SSL supported) requires Net::SMTP::TLS 49 | centos: yum install perl\(Net::SMTP::TLS\) 50 | debian: apt-get install libnet-smtp-tls-perl 51 | other: cpan install MIME::Lite 52 | * NEW: paused/resumed state and time are now accounted for 53 | * NEW: paused/resumed push types enabled - push_paused, pushed_resumed added to each provider 54 | * NEW: you can override 'alert_format' per provider ( check out the EMAIL provider for an example ) 55 | * FIX: watched duration corrected going forward (accounts for paused content and can be overridden with $count_paused ) 56 | paused/resumed states have allowed this to work 57 | * FIX: Redundant titles are now fixed - Title/Application also will always show {user} unless overridden in config.pl 58 | $appname is no longer used and replaced with {user} -- {user} if used even if config.pl has $appname ( no need to update config.pl ) 59 | before: title: "plexWatch watched" msg: "user watched title etc...." 60 | after: title: "{user} watched" msg: "title etc...." 61 | * FIX: --test_notify will not print options to test ( and they actually correspond to the right notification type now!) 62 | * FIX: do not print backup info every time --debug is called 63 | * FIX: duration watched when video is paused, then stopped 64 | * FIX: XML UTF-8 decoding/encoding ( only seemd to affect FC18 ) 65 | * FIX: Accent marks/umlauts are allowed 66 | * Screenshots added to screenshots folder for iOS and Windows 67 | 68 | 69 | # 0.0.20-dev 70 | # * NEW: Email provider ( NonAuth, Auth, TLS/SSL supported) requires Net::SMTP::TLS 71 | # centos: yum install perl\(Net::SMTP::TLS\) 72 | # debian: apt-get install libnet-smtp-tls-perl 73 | # other: cpan install MIME::Lite 74 | # * NEW: paused/resumed state and time are now accounted for 75 | # * NEW: paused/resumed push types enabled - push_paused, pushed_resumed added to each provider 76 | # * NEW: you can override 'alert_format' per provider ( check out the EMAIL provider for an example ) 77 | # * FIX: watched duration corrected going forward (accounts for paused content and can be overridden with $count_paused ) 78 | # paused/resumed states have allowed this to work 79 | # * FIX: Redundant titles are now fixed - Title/Application also will always show {user} unless overridden in config.pl 80 | # $appname is no longer used and replaced with {user} -- {user} if used even if config.pl has $appname ( no need to update config.pl ) 81 | # before: title: "plexWatch watched" msg: "user watched title etc...." 82 | # after: title: "{user} watched" msg: "title etc...." 83 | # * FIX: --test_notify will not print options to test ( and they actually correspond to the right notification type now!) 84 | # * FIX: do not print backup info every time --debug is called 85 | # * Screenshots added to screenshots folder for iOS and Windows 86 | 87 | 88 | 89 | # 0.0.19 90 | # * added options for logging IP_Address of client 91 | # * enable this in config.pl with the $server_log, $log_client_ip (enable $debug_logging to see what matched ) 92 | # -- format_options: {ip_address} 93 | # -- REQUIRES perl module File::ReadBackwards - to conserve memory) 94 | # -- Requires parsing of PMS log file. $server_log in config.pl 95 | # -- log file searched in reverse order for most recent line (File::ReadBackwards) 96 | # -- match on itemID+machineIdentifier -or- machineIdentifier 97 | # -- fallback to only itemID (ratingKey) 98 | * Will sleep 5 seconds before searching -- allows PMS to log to it log file before we try again. 99 | # * Could match wrong IP if multiple clients watch the same itemID. 100 | # * mainly for clients in 'List of networks that are allowed without auth' *only time I have seen this 101 | # * Added SSL support (port 32443) 102 | # * friendly name now allows for user+platform(title) (example in config.pl-dist) 103 | # * $debug_logging added to config.pl ( still need to add more debug logging though ) 104 | # * Variables allowed in 'application' for prowl,pushover & 'from' for boxcar 105 | # * Fix: AM/PM for OSX (non GNU) 106 | # * Fix: --watching now calls --notify before it shows now playing content. Fixes issue when content hasn't been logged as started/stopped 107 | # * Fix: allows season/episode fields to be empty for 'show' 108 | # * Fix: Do not update XML in DB if the XML is not valid 109 | # * Fix: --watched: {percent_complete} -- use the last viewOffset instead of the first. 110 | # * Fix: --watched: always display a 100% watched show/movie. I.E. show two lines: if user completes show1 (100%), then restarts said show and stops at < 90% on the same day (advanced config) 111 | # * Fix: --watched: do NOT group shows together IF hours between start of the same show is > 3 hours. (advanced config) 112 | # * 'application' => $appname removed from boxcar ( not used ) 'from' is the equivalent 113 | # * advanced config options available. View README. (Mainly to not convolute the config more than it already is) 114 | # * README: updated instructions to NOT call sudo before running the script. This way the DB is not owned by root and can be run by the 'normal' user. 115 | 116 | 117 | # 0.0.18 118 | # 119 | # * MyPlex Login Token: The script can now be ran from any computer. 120 | # -- Specify a $myPlex_user and $myPlex_pass in config.pl 121 | # -- Will only retrieve a token from my.plexapp.com if the PMS server returns a 401 (authorization required) 122 | # * format_options update/new: 123 | # -- {streamtype} [T|D] for Transcoded/Direct 124 | # -- {transcoded} [1|0] for Transcoded/Direct 125 | # -- {percent_complete} - percent of video watched ( not dependent on time watched, but where progress of video/length. 126 | # -- {state} - playing/paused/buffering 127 | # -- {progress} - exact time spot the user is at (I.E. "15 minutes" ) 128 | # * XML is now updated on every run -- allows us to view current state of content ( i.e. paused, playing, percent_completed, etc) 129 | # * CheckLock fixed: script can NOT to be ran multiple times at once (fixed repeat notifications when providers are offline) 130 | # * Provider notifications: timeout is now 20 seconds instead of 3 minutes (we should not wait 3 minutes to reach a provider!) 131 | # * Backup SQLite DB 132 | # -- automatically happens daily, weekly and monthly 133 | # -- force Daily backup with --backup 134 | # * Fixed: GNTP ProviderEnabled check was broken -- if one was enabled, all were enabled" 135 | # * Fixed: 'Wide character in send at' errors 136 | 137 | # 0.0.17 138 | # * GNTP: Provider added. 139 | # -- Supports multiple destinations. 140 | # -- Currently tested with Growl For Windows as I don't have OSX available. Need to test with others 141 | # -- install centos ( yum install perl\(Data::UUID\) , cpan Growl::GNTP ) -- CPAN install failed until I installed perl\(Data::UUID\) 142 | # -- install Ubuntu ( cpan Growl::GNTP ) 143 | # * --recently_added allows comma separated list. --recently_added=movie,show ( preferred way if you are running multiple cron jobs for RA ) 144 | # -- fixes some SQLite lock issues by running it once 145 | # -- fixes out of order content when running shows/movies 146 | # * fixed --test_notify= -- now works with =start, =stop, =recently_added 147 | # * cleanup of empty variables for notification: stripping "[]" from alert. 148 | # * excluding length of video from notification when Plex API doesn't return length: (00 min) 149 | # * spell check - cleaned up :) 150 | # * cleanup of unitialized values 151 | 152 | # 0.0.16 153 | # * rate limiting: provide mechanisms to back off notifications if provider fails (mainly due to --recently_added) 154 | # -- twitter: no api for writes. If we receive 403, we assume user hit daily limits (unknown hourly limit). Do not process additional notification until next run. 155 | # -- boxcar: on failure -- back of the rest of alerts for provider until next run 156 | # -- prowl: on failure -- back of the rest of alerts for provider until next run 157 | # -- growl: on failure -- back of the rest of alerts for provider until next run 158 | # -- pushover: on failure -- back of the rest of alerts for provider until next run 159 | # * --recently_added: 25 results per section created (multiple sections of same type: two sections with type 'shows' = 50 results ) 160 | # * --recently_added: SKIP notifications for a video if the addedDate is older than 1 day 161 | # * --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) 162 | # * test_notify=recently_added -- option to test notification for recently added content (verify provider even works) 163 | # * config.pl: $notify_started and $notify_stopped deprecated: use per provider settings globally (i.e. push_watched, push_watching) 164 | # * recently_added: bugfix - failed when a section only has 1 video. 165 | # * titles added to notifications ( change titles per type in config.pl $push_titles ) prowl, growl, pushover, boxcar, twitter supported 166 | # * Default titles can be changed globally in config.pl ($push_titles) 167 | 168 | # 0.0.15 169 | # * added recently_added=[movie,show] -- notify on recently added items to PMS 170 | # * Twitter added as a provider 171 | - requires Net::Twitter::Lite::WithAPIv1_1 ( install with: 'cpan Net::Twitter::Lite::WithAPIv1_1' ) 172 | - requires Net::OAuth >= 0.28 ( install with: 'cpan Net::OAuth' ) 173 | - twitter OAUTH required - create a new app @ https://dev.twitter.com/apps 174 | -- make sure to set set ApplicationType to read/write 175 | # * config.pl: added push_watched => 1, push_watching => 1, push_recently_added => 1 to all providers. Enable to disable specific notify types 176 | # * --exclude_user added to all functions. You can specify --exclude_user multiple times.. i.e --exclude_user=user1 --exclude_user=otherUsername 177 | # * Boxcar added as provider 178 | # - All you need is a registered account on boxcar (valid email) 179 | # - If enabled, this script with register your boxcar account to the plexWatch service -- simple right? 180 | # * Twitter/OAuth modules ONLY required if you enable twitter (Net::Twitter::Lite::WithAPIv1_1 , Net::OAuth) 181 | # * removed module WWW::Curl::Easy (replaced with LWP which is more standard) 182 | # * removed module URI::Escape (using my own subroutine) 183 | # * --version added -- easier to debug 184 | 185 | # 0.0.14 186 | # * --watched -- join the same show title in one line if it was watched into the next day. 187 | # I.E. Movie1 watched from 11pm - 1am: would normally show two lines.. 1 from 11pm-11:59pm and 2 from 12am-1am. Now it will just show one 188 | # 189 | 190 | # 0.0.13 191 | # * duration_exact change to durationrr (time precision will be in minutes) 192 | # * --stats time precision will still be seconds 193 | # * formatting options added 194 | # {time_left} :: time left until video is done. works only on --watching 195 | # - {length} :: length of video (works for any) 196 | # - {progress} :: current time watched in video 197 | # * --stats can be used by itself now. No longer required to have --watched 198 | # * Growl added to config.pl -- requires GrowlNotify from http://growl.info/downloads 199 | 200 | # 0.0.12 201 | # * code cleanup - merge same routines in sub (&FriendlyName) 202 | # * alert cleanup - easier to update alert format when needed (and more standardized) 203 | -- $alert_format added to config options (unique for stop and start) 204 | -- can override on cli with --format_stop="..." and --format_start="..." 205 | -- list available format options with --format_options 206 | # * cli --watching --watched format can now be edited by the user or specified on the cli 207 | # * config options moved into config.pl -- should be easier to upgrade version without having to edit the Perl script each time 208 | # * config.pl-dist is included --- one must edit and copy it to config.pl 209 | # * File::Basename required -- to load config.pl 210 | 211 | # 0.0.11 212 | # * Season/Episode appended to alert. 213 | # * fixed bug in '-watching' cli options. friendly name fixed. 214 | 215 | # 0.0.10 216 | # * '-stats' option added to '-watched' - show total watched time per user -- total time and per day 217 | # * '-user' option added to '-watched' and '-watching' -- limit output to a specific user 218 | # * $user_display hash ref added to config - you can now show a 'friendly' username instead of the users email address [excluding @domain.tld] 219 | # * platform title used if exists over platform. I.E. Chrome - Plex/Web (Chrome) will not show 'Plex/Web (Chrome)' -- it was redundant. Roku will still be Roku 220 | # * log file is now hard coded to $data_dir/plexWatch.log instead of $data_dir/$appname.log. Allows users to change $appname to anything or nothing for notification 221 | 222 | # 0.0.9 223 | # * -watched will now show the accumulated duration (if a video has been started/stopped multiple time on the same day) 224 | # * -nogrouping added as an option to -watched. It will show the same video multiple times if it has been started/stopped on the same day) 225 | 226 | # 0.0.8 227 | # * file locking was broking - multiple copies could run at the same time 228 | # * failed attempts to retrieve xml status could result in false stopped notifications and dupes 229 | # * timeout was way too long any possibly indefinite for sessions status. now 20 seconds. 230 | # -- this might fix the dupe stopped notifications. 231 | 232 | # 0.0.7 233 | # * added 'on platform' for alert - i.e. user is watching: movie name on Roku' 234 | # * fixed alerts for prowl when movie has a colon. It was discarding anything after the first colon. 235 | 236 | # 0.0.6 237 | # * fixed pushover notifications -- actually include the alert! 238 | 239 | # 0.0.5 240 | # info: little bugs, nothing major 241 | # 242 | # * updated Perl doc 243 | # * fixed --show_xml to actually show url when no options are given 244 | # * README.md - Fix install instructions and supply yum/apt-get Perl module howto 245 | 246 | # 0.0.4 247 | # * added data_dir in config. Defaults to /opt/plexWeb/ -- this way the script can be run from any location. 248 | 249 | # 0.0.3 250 | # * new requirement: Time::ParseDate 251 | # * date ranges for -watched (-start, -stop) 252 | # * specify human date ranges -- Time::ParseDate -- today, yesterday, last week 253 | 254 | # 0.0.2; 255 | # * new requirement: use Getopt::Long, Pod::Usage, Fcntl qw(:flock), Fcntl qw(:flock) 256 | # * modified DB insert - using Placeholders and Bind Values 257 | # * added 'xml column' to db - if any info is need later or for easier debugging 258 | # * changed stopped from a boolean to actual epoch - used for duration of watched 259 | # * changed sub InitialzeDB (now initDB) and added initDBtable - ability to add/modify column definitions when needed 260 | # * added use Time::Duration -- duration for watched status 261 | # * verify all content has been notified if nothing is playing 262 | # * added lock just in case via Fcntl qw(:flock) 263 | # * new options: added ability to use cli options via get::opt 264 | # - added --watched 265 | # - added --watching 266 | # - added --help 267 | # - added --show_xml 268 | # - added --debug 269 | # - added --notify 270 | 271 | # 0.0.1: 272 | # * initial release 273 | -------------------------------------------------------------------------------- /config.pl-dist: -------------------------------------------------------------------------------- 1 | $data_dir = '/opt/plexWatch/'; ## to store the DB, logfile - can be the same as this script 2 | 3 | $server_log = '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log'; ## used to log IP address of user (alpha) 4 | $log_client_ip = 0; ## requires $server_log to be available too. (requires File::ReadBackwards) 5 | ## also required DEBUG log to be turned on in the PMS 6 | 7 | $debug_logging = 1; ## logs to $data_dir/debug.log ( not verbose enough yet.. still todo ) 8 | 9 | ## myplex user/pass ONLY required if you have set the PMS to 'Require authentication on local networks' and $server is not set to localhost 10 | $myPlex_user = ''; 11 | $myPlex_pass = ''; 12 | 13 | $server = 'localhost'; ## IP of PMS - or localhost 14 | $port = 32400; ## port of PMS 15 | 16 | $notify_started = 1; # !deprecated -- does nothing anymore (use push_watched, push_watching in $notify) 17 | $notify_stopped = 1; # !deprecated -- does nothing anymore (use push_watched, push_watching in $notify) 18 | 19 | $appname = 'plexWatch'; 20 | 21 | ## Give a user a more friendly name. I.E. REAL_USER will now be Frank 22 | ## you may also specify the platform with user+platform 23 | $user_display = {'REAL_USER1' => 'Frank', 24 | 'REAL_USER2' => 'Rob & Carrie', 25 | 'REAL_USER2+Roku 3' => 'Family Room', 26 | 'REAL_USER2+Roku' => 'Family Room', 27 | 'REAL_USER2+iOS' => 'Rob', 28 | }; 29 | 30 | 31 | ## format of alert - default. You can also override this per provider ($notify below) 32 | ## run ./plexWatch.pl --format_options -- to see all 33 | # start = notification for start of video 34 | # stop = notification for stop of video 35 | # watched = cli output for watched content 36 | # watching = cli output content being watched 37 | $alert_format = {'start' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] {ip_address}', 38 | 'paused' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%] {ip_address}', 39 | 'resumed' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%] {ip_address}', 40 | 'stop' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%] {ip_address}', 41 | 'watched' => '{user} watched {title} [{streamtype}] [{year}] [{length}] [{rating}] on {platform} for {duration} [{percent_complete}%] {ip_address}', 42 | 'watching' => '{user} {state} {title} [{streamtype}] [{year}] [{rating}] [{length}] on {platform} for {duration} [{percent_complete}%] [{time_left} left] {ip_address}' 43 | }; 44 | 45 | ## Notification Options 46 | $notify = { 47 | 48 | 'file' => { 49 | 'enabled' => 1, ## 0 or 1 - set to 1 to enable File Logging 50 | 'filename' => "$data_dir/plexWatch.log", ## default is plexWatch.log 51 | }, 52 | 53 | 'prowl' => { 54 | 'enabled' => 0, ## 0 or 1 - set to 1 to enable PROWL 55 | 'push_recentlyadded' => 0, 56 | 'push_watched' => 0, 57 | 'push_watching' => 0, 58 | 'push_paused' => 0, 59 | 'push_resumed' => 0, 60 | 'apikey' => 'YOUR API KEY', ## your API key 61 | 'application' => '{user}', 62 | 'priority' => 0, 63 | 'url' => '', 64 | }, 65 | 66 | 'pushover' => { 67 | 'enabled' => 0, ## set to 1 to enable Pushover 68 | 'push_recentlyadded' => 0, 69 | 'push_watched' => 0, 70 | 'push_watching' => 0, 71 | 'push_paused' => 0, 72 | 'push_resumed' => 0, 73 | 'token' => 'YOUR APP TOKEN', ## your app token 74 | 'user' => 'YOUR USER TOKEN', ## your user token 75 | 'title' => '{user}', 76 | 'sound' => 'intermission', 77 | }, 78 | 79 | 'growl' => { 80 | 'enabled' => 0, ## set to 1 to enable local growl (You should probably used GNTP - growl supported for multiple platforms - below) 81 | 'push_recentlyadded' => 0, 82 | 'push_watched' => 0, 83 | 'push_watching' => 0, 84 | 'push_paused' => 0, 85 | 'push_resumed' => 0, 86 | 'application' => '{user}', 87 | 'script' => '/usr/local/bin/growlnotify', 88 | 'icon' => '/Applications/Plex Media Server.app/Contents/Resources/MyPlex.icns', 89 | }, 90 | 91 | 92 | 'twitter' => { 93 | 'enabled' => 0, ## set to 1 to enable local twitter 94 | 'push_recentlyadded' => 0, 95 | 'push_watched' => 0, 96 | 'push_watching' => 0, 97 | 'push_paused' => 0, 98 | 'push_resumed' => 0, 99 | 'title' => '{user}', 100 | 'consumer_key' => '', 101 | 'consumer_secret' => '', 102 | 'access_token' => '', 103 | 'access_token_secret' => '', 104 | 'alert_format' => { 105 | 'start' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in]', 106 | 'paused' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%]', 107 | 'resumed' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%]', 108 | 'stop' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%]', 109 | }, 110 | }, 111 | 112 | 'boxcar' => { 113 | 'enabled' => 0, ## set to 1 to enable local boxcar 114 | 'push_recentlyadded' => 0, 115 | 'push_watched' => 0, 116 | 'push_watching' => 0, 117 | 'push_paused' => 0, 118 | 'push_resumed' => 0, 119 | 'email' => '', ## YOUR email address registered at boxcar 120 | 'from' => '{user}', ## From Name displayed on boxcar 121 | 'provider_key' => 'o2eI7rcwya5XFETaXdlh', ## plexWatch app is 'o2eI7rcwya5XFETaXdlh'. You may supply your own. 122 | 'provider_secret' => 'h4pJjyBoEMk1rwK2EH3NLemO4fQ0ql9HnRgVfwg4', ## plexWatch app is 'h4pJjyBoEMk1rwK2EH3NLemO4fQ0ql9HnRgVfwg4'. You may supply your own. 123 | 'icon_url' => '', # Leave empty ('') for plexWatch icon. You may supply your own (57x57) 124 | }, 125 | 126 | 'boxcar_v2' => { 127 | 'enabled' => 0, ## set to 1 to enable local boxcar_v2 ( device specific ) 128 | 'push_recentlyadded' => 0, 129 | 'push_watched' => 0, 130 | 'push_watching' => 0, 131 | 'push_paused' => 0, 132 | 'push_resumed' => 0, 133 | 'access_token' => '', ## Access token from your Device 134 | 'from' => '{user}', ## From Name displayed on boxcar 135 | 'sound' => 'bird-1', 136 | 'icon_url' => 'https://rarforge.com/images/plexWatch.57x57.png', 137 | }, 138 | 139 | 'pushbullet' => { 140 | 'enabled' => 0, 141 | 'push_recentlyadded' => 0, 142 | 'push_watched' => 0, 143 | 'push_watching' => 0, 144 | 'push_paused' => 0, 145 | 'push_resumed' => 0, 146 | 'title' => '{user}', 147 | 'apikey' => 'API KEY', # Pushbullet API key https://www.pushbullet.com/account 148 | 'device' => 'DEVICE IDEN', # https://api.pushbullet.com/v2/devices put yor API key as username and password empty - Leave blank to use all or channel 149 | 'channel' => 'CHANNEL_TAG', # Channel tag from https://www.pushbullet.com/my-channels - Leave blank if unused 150 | }, 151 | 152 | 'pushalot' => { 153 | 'enabled' => 0, 154 | 'push_recentlyadded' => 0, 155 | 'push_watched' => 0, 156 | 'push_watching' => 0, 157 | 'push_paused' => 0, 158 | 'push_resumed' => 0, 159 | 'title' => '{user}', 160 | 'token' => 'AUTHORIZATION TOKEN', # Pushalot API authorization token from https://pushalot.com/manager/authorizations 161 | 'isimportant' => 'False', # True or False, Indicator whether the message should be visually marked as important within client app. Does not have any other implication on message delivery. 162 | 'issilent' => 'False', # True or False, If set to True will prevent sending toast notifications to connected devices, resulting in silent delivery, as only badge icon will indicate new message. 163 | 'timetolive' => '0', # Time in minutes after which message automatically gets purged. 164 | }, 165 | 166 | ## GNTP (GROWL) -- multiple destinations are supported 167 | 'GNTP' => { 168 | '1' => { 169 | 'enabled' => 0, ## set to 1 to enable local growl 170 | 'push_recentlyadded' => 0, 171 | 'push_watched' => 0, 172 | 'push_watching' => 0, 173 | 'push_paused' => 0, 174 | 'push_resumed' => 0, 175 | 'application' => $appname, 176 | 'title' => '{user}', 177 | 'server' => '10.0.0.1', # destination ip/host 178 | 'port' => '23053', # default 23053 179 | 'password' => '', # '' for no pass 180 | 'icon_url' => 'https://rarforge.com/images/plexWatch.57x57.png', 181 | 'sticky' => 1, 182 | }, 183 | 184 | '2' => { 185 | 'enabled' => 0, ## set to 1 to enable local growl 186 | 'push_recentlyadded' => 0, 187 | 'push_watched' => 0, 188 | 'push_watching' => 0, 189 | 'push_paused' => 0, 190 | 'push_resumed' => 0, 191 | 'application' => '{user}', 192 | 'server' => '192.168.10.100', # destination ip/host 193 | 'port' => '23053', # default 23053 194 | 'password' => '', # '' for no pass 195 | 'icon_url' => 'https://rarforge.com/images/plexWatch.57x57.png', 196 | 'sticky' => 0, 197 | }, 198 | }, 199 | 200 | 201 | ## EMAIL -- multiple destinations are supported 202 | 'EMAIL' => { 203 | 204 | '1' => { 205 | 'enabled' => 0, ## set to 1 to enable local EMAIL 206 | 'push_recentlyadded' => 0, 207 | 'push_watched' => 1, 208 | 'push_watching' => 1, 209 | 'push_paused' => 1, 210 | 'push_resumed' => 1, 211 | 'server' => '', # your mail server 212 | 'port' => '25', # your mail server port defalt 25 (587 is also a good choice) 213 | 'from' => '', # your From email address: 'user@domain.com' 214 | 'to' => '', # Email address to receive notification: 'user@domain.com' 215 | 'username' => '', # AUTH if needed [optional] 216 | 'password' => '', # AUTH if needed [optional] 217 | 'subject' => '{user} {push_title} {title}', ## push_title is special for EMAIL (for now) 218 | 'enable_tls' => 0, # ENABLE for TLS support ( your smtp server must allow STARTTLS ) 219 | 'alert_format' => { 220 | 'start' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] {ip_address} {all_details}', 221 | 'paused' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%] {ip_address} {all_details}', 222 | 'resumed' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%] {ip_address} {all_details}', 223 | 'stop' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%] {ip_address} {all_details}', 224 | }, 225 | }, 226 | 227 | '2' => { 228 | 'enabled' => 0, ## set to 1 to enable EMAIL 229 | ## fill in the rest if you need more then 1 email notification 230 | }, 231 | 232 | 233 | }, 234 | 235 | 236 | 'external' => { 237 | 238 | 'transmissionServer1' => { 239 | 'enabled' => 0, ## 0 or 1 - set to 1 to enable 240 | 'push_watched' => 1, #stop 241 | 'push_watching' => 1, #start 242 | 'push_paused' => 1, #pause 243 | 'push_resumed' => 1, #resume 244 | 245 | 'script_format' => { 246 | 'start' => '/usr/local/bin/start.pl {user} {state}', 247 | 'paused' => '/usr/local/bin/paused.pl {user} {state}', 248 | 'resumed' => '/usr/local/bin/resumed.pl {user} {state}', 249 | 'stop' => '/usr/local/bin/stop.pl {user} {state}', 250 | }, 251 | }, 252 | 253 | 254 | 'homeAutomation' => { 255 | 'enabled' => 0, ## 0 or 1 - set to 1 to enable homeAutomation script 256 | 'push_watched' => 1, #stop 257 | 'push_watching' => 1, #start 258 | 'push_paused' => 1, #pause 259 | 'push_resumed' => 1, #resume 260 | 261 | 'script_format' => { 262 | 'start' => '/usr/local/bin/homeAutomation.pl {user} {state}', 263 | 'paused' => '/usr/local/bin/homeAutomation.pl {user} {state}', 264 | 'resumed' => '/usr/local/bin/homeAutomation.pl {user} {state}', 265 | 'stop' => '/usr/local/bin/homeAutomation.pl {user} {state}', 266 | }, 267 | }, 268 | 269 | }, 270 | 271 | }; 272 | 273 | $push_titles = { 274 | 'push_watched' => 'Watched', 275 | 'push_watching' => 'Watching', 276 | 'push_resumed' => 'Resumed', 277 | 'push_paused' => 'Paused', 278 | 'push_recentlyadded' => 'New', 279 | }; 280 | 281 | 282 | # Advanced 283 | $watched_show_completed = 1; ## advanced config -- always show completed show/movie as it's own line 284 | $watched_grouping_maxhr = 2; ## advanced config -- do not group shows together if start/restart is > X hours 285 | $count_paused = 0; ## included paused time in time watched ( probably do not want this ) 286 | $inc_non_library_content = 0; ## non library content (channels) are excluded. Set to 1 to include them 287 | #@exclude_library_ids = (999, 998); ## exclude this library section (by id) -- full exclusion 288 | -------------------------------------------------------------------------------- /config.pl-dist-win32: -------------------------------------------------------------------------------- 1 | $data_dir = 'c:\\plexWatch\\'; ## to store the DB, logfile - can be the same as this script 2 | 3 | $server_log = 'c:\\plexWatch\\yourserverlogpath'; ## used to log IP address of user (alpha) 4 | $log_client_ip = 0; ## requires $server_log to be available too. (requires File::ReadBackwards) 5 | ## also required DEBUG log to be turned on in the PMS 6 | 7 | $debug_logging = 1; ## logs to $data_dir/debug.log ( not verbose enough yet.. still todo ) 8 | 9 | ## myplex user/pass ONLY required if you have set the PMS to 'Require authentication on local networks' and $server is not set to localhost 10 | $myPlex_user = ''; 11 | $myPlex_pass = ''; 12 | 13 | $server = 'localhost'; ## IP of PMS - or localhost 14 | $port = 32400; ## port of PMS 15 | 16 | $notify_started = 1; # !deprecated -- does nothing anymore (use push_watched, push_watching in $notify) 17 | $notify_stopped = 1; # !deprecated -- does nothing anymore (use push_watched, push_watching in $notify) 18 | 19 | $appname = 'plexWatch'; 20 | 21 | ## Give a user a more friendly name. I.E. REAL_USER will now be Frank 22 | ## you may also specify the platform with user+platform 23 | $user_display = {'REAL_USER1' => 'Frank', 24 | 'REAL_USER2' => 'Rob & Carrie', 25 | 'REAL_USER2+Roku 3' => 'Family Room', 26 | 'REAL_USER2+Roku' => 'Family Room', 27 | 'REAL_USER2+iOS' => 'Rob', 28 | }; 29 | 30 | 31 | ## format of alert - default. You can also override this per provider ($notify below) 32 | ## run ./plexWatch.pl --format_options -- to see all 33 | # start = notification for start of video 34 | # stop = notification for stop of video 35 | # watched = cli output for watched content 36 | # watching = cli output content being watched 37 | $alert_format = {'start' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] {ip_address}', 38 | 'paused' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%] {ip_address}', 39 | 'resumed' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%] {ip_address}', 40 | 'stop' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%] {ip_address}', 41 | 'watched' => '{user} watched {title} [{streamtype}] [{year}] [{length}] [{rating}] on {platform} for {duration} [{percent_complete}%] {ip_address}', 42 | 'watching' => '{user} {state} {title} [{streamtype}] [{year}] [{rating}] [{length}] on {platform} for {duration} [{percent_complete}%] [{time_left} left] {ip_address}' 43 | }; 44 | 45 | ## Notification Options 46 | $notify = { 47 | 48 | 'file' => { 49 | 'enabled' => 1, ## 0 or 1 - set to 1 to enable File Logging 50 | 'filename' => "$data_dir/plexWatch.log", ## default is plexWatch.log 51 | }, 52 | 53 | 'prowl' => { 54 | 'enabled' => 0, ## 0 or 1 - set to 1 to enable PROWL 55 | 'push_recentlyadded' => 0, 56 | 'push_watched' => 0, 57 | 'push_watching' => 0, 58 | 'push_paused' => 0, 59 | 'push_resumed' => 0, 60 | 'apikey' => 'YOUR API KEY', ## your API key 61 | 'application' => '{user}', 62 | 'priority' => 0, 63 | 'url' => '', 64 | }, 65 | 66 | 'pushover' => { 67 | 'enabled' => 0, ## set to 1 to enable Pushover 68 | 'push_recentlyadded' => 0, 69 | 'push_watched' => 0, 70 | 'push_watching' => 0, 71 | 'push_paused' => 0, 72 | 'push_resumed' => 0, 73 | 'token' => 'YOUR APP TOKEN', ## your app token 74 | 'user' => 'YOUR USER TOKEN', ## your user token 75 | 'title' => '{user}', 76 | 'sound' => 'intermission', 77 | }, 78 | 79 | 'growl' => { 80 | 'enabled' => 0, ## set to 1 to enable local growl (You should probably used GNTP - growl supported for multiple platforms - below) 81 | 'push_recentlyadded' => 0, 82 | 'push_watched' => 0, 83 | 'push_watching' => 0, 84 | 'push_paused' => 0, 85 | 'push_resumed' => 0, 86 | 'application' => '{user}', 87 | 'script' => '/usr/local/bin/growlnotify', 88 | 'icon' => '/Applications/Plex Media Server.app/Contents/Resources/MyPlex.icns', 89 | }, 90 | 91 | 92 | 'twitter' => { 93 | 'enabled' => 0, ## set to 1 to enable local twitter 94 | 'push_recentlyadded' => 0, 95 | 'push_watched' => 0, 96 | 'push_watching' => 0, 97 | 'push_paused' => 0, 98 | 'push_resumed' => 0, 99 | 'title' => '{user}', 100 | 'consumer_key' => '', 101 | 'consumer_secret' => '', 102 | 'access_token' => '', 103 | 'access_token_secret' => '', 104 | 'alert_format' => { 105 | 'start' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in]', 106 | 'paused' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%]', 107 | 'resumed' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%]', 108 | 'stop' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%]', 109 | }, 110 | }, 111 | 112 | 'boxcar' => { 113 | 'enabled' => 0, ## set to 1 to enable local boxcar 114 | 'push_recentlyadded' => 0, 115 | 'push_watched' => 0, 116 | 'push_watching' => 0, 117 | 'push_paused' => 0, 118 | 'push_resumed' => 0, 119 | 'email' => '', ## YOUR email address registered at boxcar 120 | 'from' => '{user}', ## From Name displayed on boxcar 121 | 'provider_key' => 'o2eI7rcwya5XFETaXdlh', ## plexWatch app is 'o2eI7rcwya5XFETaXdlh'. You may supply your own. 122 | 'provider_secret' => 'h4pJjyBoEMk1rwK2EH3NLemO4fQ0ql9HnRgVfwg4', ## plexWatch app is 'h4pJjyBoEMk1rwK2EH3NLemO4fQ0ql9HnRgVfwg4'. You may supply your own. 123 | 'icon_url' => '', # Leave empty ('') for plexWatch icon. You may supply your own (57x57) 124 | }, 125 | 126 | 'boxcar_v2' => { 127 | 'enabled' => 0, ## set to 1 to enable local boxcar_v2 ( device specific ) 128 | 'push_recentlyadded' => 0, 129 | 'push_watched' => 0, 130 | 'push_watching' => 0, 131 | 'push_paused' => 0, 132 | 'push_resumed' => 0, 133 | 'access_token' => '', ## Access token from your Device 134 | 'from' => '{user}', ## From Name displayed on boxcar 135 | 'sound' => 'bird-1', 136 | 'icon_url' => 'https://rarforge.com/images/plexWatch.57x57.png', 137 | }, 138 | 139 | 'pushbullet' => { 140 | 'enabled' => 0, 141 | 'push_recentlyadded' => 0, 142 | 'push_watched' => 0, 143 | 'push_watching' => 0, 144 | 'push_paused' => 0, 145 | 'push_resumed' => 0, 146 | 'title' => '{user}', 147 | 'apikey' => 'API KEY', # Pushbullet API key https://www.pushbullet.com/account 148 | 'device' => 'DEVICE IDEN', # https://api.pushbullet.com/v2/devices put yor API key as username and password empty - Leave blank to use all or channel 149 | 'channel' => 'CHANNEL_TAG', # Channel tag from https://www.pushbullet.com/my-channels - Leave blank if unused 150 | }, 151 | 152 | 'pushalot' => { 153 | 'enabled' => 0, 154 | 'push_recentlyadded' => 0, 155 | 'push_watched' => 0, 156 | 'push_watching' => 0, 157 | 'push_paused' => 0, 158 | 'push_resumed' => 0, 159 | 'title' => '{user}', 160 | 'token' => 'AUTHORIZATION TOKEN', # Pushalot API authorization token from https://pushalot.com/manager/authorizations 161 | 'isimportant' => 'False', # True or False, Indicator whether the message should be visually marked as important within client app. Does not have any other implication on message delivery. 162 | 'issilent' => 'False', # True or False, If set to True will prevent sending toast notifications to connected devices, resulting in silent delivery, as only badge icon will indicate new message. 163 | 'timetolive' => '0', # Time in minutes after which message automatically gets purged. 164 | }, 165 | 166 | ## GNTP (GROWL) -- multiple destinations are supported 167 | 'GNTP' => { 168 | '1' => { 169 | 'enabled' => 0, ## set to 1 to enable local growl 170 | 'push_recentlyadded' => 0, 171 | 'push_watched' => 0, 172 | 'push_watching' => 0, 173 | 'push_paused' => 0, 174 | 'push_resumed' => 0, 175 | 'application' => $appname, 176 | 'title' => '{user}', 177 | 'server' => '10.0.0.1', # destination ip/host 178 | 'port' => '23053', # default 23053 179 | 'password' => '', # '' for no pass 180 | 'icon_url' => 'https://rarforge.com/images/plexWatch.57x57.png', 181 | 'sticky' => 1, 182 | }, 183 | 184 | '2' => { 185 | 'enabled' => 0, ## set to 1 to enable local growl 186 | 'push_recentlyadded' => 0, 187 | 'push_watched' => 0, 188 | 'push_watching' => 0, 189 | 'push_paused' => 0, 190 | 'push_resumed' => 0, 191 | 'application' => '{user}', 192 | 'server' => '192.168.10.100', # destination ip/host 193 | 'port' => '23053', # default 23053 194 | 'password' => '', # '' for no pass 195 | 'icon_url' => 'https://rarforge.com/images/plexWatch.57x57.png', 196 | 'sticky' => 0, 197 | }, 198 | }, 199 | 200 | 201 | ## EMAIL -- multiple destinations are supported 202 | 'EMAIL' => { 203 | 204 | '1' => { 205 | 'enabled' => 0, ## set to 1 to enable local EMAIL 206 | 'push_recentlyadded' => 0, 207 | 'push_watched' => 1, 208 | 'push_watching' => 1, 209 | 'push_paused' => 1, 210 | 'push_resumed' => 1, 211 | 'server' => '', # your mail server 212 | 'port' => '25', # your mail server port defalt 25 (587 is also a good choice) 213 | 'from' => '', # your From email address: 'user@domain.com' 214 | 'to' => '', # Email address to receive notification: 'user@domain.com' 215 | 'username' => '', # AUTH if needed [optional] 216 | 'password' => '', # AUTH if needed [optional] 217 | 'subject' => '{user} {push_title} {title}', ## push_title is special for EMAIL (for now) 218 | 'enable_tls' => 0, # ENABLE for TLS support ( your smtp server must allow STARTTLS ) 219 | 'alert_format' => { 220 | 'start' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] {ip_address} {all_details}', 221 | 'paused' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%] {ip_address} {all_details}', 222 | 'resumed' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} [{progress} in] [{percent_complete}%] {ip_address} {all_details}', 223 | 'stop' => '{title} [{streamtype}] [{year}] [{rating}] on {platform} for {duration} [{percent_complete}%] {ip_address} {all_details}', 224 | }, 225 | }, 226 | 227 | '2' => { 228 | 'enabled' => 0, ## set to 1 to enable EMAIL 229 | ## fill in the rest if you need more then 1 email notification 230 | }, 231 | 232 | 233 | }, 234 | 235 | 236 | }; 237 | 238 | $push_titles = { 239 | 'push_watched' => 'Watched', 240 | 'push_watching' => 'Watching', 241 | 'push_resumed' => 'Resumed', 242 | 'push_paused' => 'Paused', 243 | 'push_recentlyadded' => 'New', 244 | }; 245 | 246 | 247 | # Advanced 248 | $watched_show_completed = 1; ## advanced config -- always show completed show/movie as it's own line 249 | $watched_grouping_maxhr = 2; ## advanced config -- do not group shows together if start/restart is > X hours 250 | $count_paused = 0; ## included paused time in time watched ( probably do not want this ) 251 | $inc_non_library_content = 0; ## non library content (channels) are excluded. Set to 1 to include them 252 | #@exclude_library_ids = (999, 998); ## exclude this library section (by id) -- full exclusion 253 | -------------------------------------------------------------------------------- /notes/TODO: -------------------------------------------------------------------------------- 1 | # verify test_notify=pause|resume|start|stop|recent all page correctly.. easier for troubleshooting 2 | 3 | 4 | 5 | ## on start, set viewOffset -- do not update this field on any run after 6 | 7 | 8 | ########################################################################################### 9 | ### TODO 10 | 11 | * re-work plexWatch.log: only include --recently_added, --watched, --watching 12 | -- create plexWatch.debug to include ALL actions - failures and success. Easier to ... debug 13 | * ADD OSX instructions: http://forums.plexapp.com/index.php/topic/72552-plexwatch-plex-notify-script-send-push-alerts-on-new-sessions-and-stopped/?p=436554 14 | ### 15 | ########################################################################################### 16 | 17 | 18 | 19 | ########################################################################################### 20 | ### Long Term 21 | * failed,452 status for --watching, --watched ( keep trying notification if failed... set failed and skip after X number of failures or if notification is X old) 22 | --- show current time if notification is OLD 'user watching movie (36 minutes / 120 minutes)' -- requires the pause status update 23 | --- this is already true for --recenlty_added ( we need to keep status per provider for --watched,--watching: db changes) 24 | 25 | * rate limiting: slow down before 452.. not a high priority as the current version works 26 | 27 | * add more options to --format_options (will probably have to use XML in db going backwards -- maybe even forwards instead of messing with DB table) 28 | -- XML is not used to pull info for all alerts and to display cli info. This means the above is now possible without too much work (i think) 29 | 30 | * code cleanup - always available 31 | 32 | ### 33 | ########################################################################################### 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | ###### DONE -- cruft -- this is part of the change log (verify and remove) 43 | * code for --recently_added=movie,show 44 | 45 | * code cleanup - merge same routines in sub 46 | -- added &FriendlyName 47 | -- still more to do 48 | 49 | * alert cleanup - easier to update alert format when needed 50 | -- $alert_format added to config options 51 | -- can also override on cli with --format_stop="..." and --format_start="..." 52 | -- list available format options with --format_options 53 | 54 | * cli --watching --watched format can now be edited by the user or specified on the cli 55 | 56 | * config options moved into config.pl -- should be easier to upgrade version without having to edit the perl script each time 57 | 58 | * config.pl-dist is included --- one must edit and copy it to config.pl 59 | 60 | * merge growl changes from forum - http://forums.plexapp.com/index.php/topic/72552-plexwatch-plex-notify-script-send-push-alerts-on-new-sessions-and-stopped/?p=423033 61 | 62 | * update alert format to be included in --cli options (--watching, --watched). Currently only works for notifications 63 | 64 | * display more info --watching. I.E. durations, 'user watching movie (36 minutes / 120 minutes) anything else useful? 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /notes/win32.build.caveats.txt: -------------------------------------------------------------------------------- 1 | == Added Modules == 2 | Net::OAuth::SignatureMethod::HMAC_SHA1 3 | Net::OAuth::ProtectedResourceRequest 4 | Net::OAuth::ProtectedResourceRequest 5 | 6 | == Trim Modules == 7 | Net::SMTP::TLS 8 | 9 | == raw == 10 | --trim Time::ParseDate;Net::SMTP::TLS 11 | --add Net::OAuth::SignatureMethod::HMAC_SHA1;Net::OAuth::ProtectedResourceRequest;Net::Twitter::Lite::API::V1_1 12 | --shared public 13 | --norunlib 14 | --dyndll 15 | -------------------------------------------------------------------------------- /plexWatch.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljunkie/plexWatch/471dcda9c91a18ae6398549609b1148378a9223a/plexWatch.exe -------------------------------------------------------------------------------- /plexWatch.notifyDeamon.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use strict; 3 | use POSIX qw(setsid); 4 | use Fcntl qw(:flock); 5 | 6 | my $plexWatch_script = '/opt/plexWatch/plexWatch.pl'; 7 | 8 | 9 | ########################################################################### 10 | my $debug = 0; 11 | my $script_fh; 12 | &CheckLock; 13 | chdir '/'; 14 | umask 0; 15 | 16 | 17 | #open STDIN, '/dev/null'; 18 | #open STDERR, '>/dev/null'; 19 | #open STDOUT, '>/dev/null'; 20 | defined(my $pid = fork); 21 | exit if $pid; 22 | close STDIN; 23 | close STDOUT; 24 | close STDERR; 25 | 26 | setsid or die "Can't start a new session: $!"; 27 | umask(0027); # create files with perms -rw-r----- 28 | chdir '/' or die "Can't chdir to /: $!"; 29 | 30 | open STDIN, '<', '/dev/null' or die $!; 31 | open STDOUT, '>', '/dev/null' or die $!; 32 | open STDERR, '>>', '/tmp/plexWatch.log'; 33 | 34 | setsid; 35 | while(1) { 36 | sleep(5); 37 | my $cmd = $plexWatch_script; 38 | $cmd .= ' ' . join(' ',@ARGV) if @ARGV; 39 | system($cmd); 40 | } 41 | 42 | sub CheckLock { 43 | open($script_fh, '<', $0) 44 | or die("Unable to open script source: $!\n"); 45 | while (!flock($script_fh, LOCK_EX|LOCK_NB)) { 46 | print "$0 is already running. waiting.\n" if $debug; 47 | exit; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /plexWatchNotify.vbs: -------------------------------------------------------------------------------- 1 | 2 | Set WshShell = CreateObject("WScript.Shell") 3 | WshShell.Run "C:\plexWatch\plexWatch.exe --notify", 0, True 4 | 5 | Set WshShell = Nothing 6 | -------------------------------------------------------------------------------- /plexWatchRecentlyAdded.vbs: -------------------------------------------------------------------------------- 1 | 2 | Set WshShell = CreateObject("WScript.Shell") 3 | WshShell.Run "C:\plexWatch\plexWatch.exe --recently_added=tv,movie", 0, True 4 | Set WshShell = Nothing 5 | -------------------------------------------------------------------------------- /screenshots/iOS-plexWatch_boxcar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljunkie/plexWatch/471dcda9c91a18ae6398549609b1148378a9223a/screenshots/iOS-plexWatch_boxcar.png -------------------------------------------------------------------------------- /screenshots/iOS-plexWatch_prowl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljunkie/plexWatch/471dcda9c91a18ae6398549609b1148378a9223a/screenshots/iOS-plexWatch_prowl.png -------------------------------------------------------------------------------- /screenshots/iOS-plexWatch_pushover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljunkie/plexWatch/471dcda9c91a18ae6398549609b1148378a9223a/screenshots/iOS-plexWatch_pushover.png -------------------------------------------------------------------------------- /screenshots/win7-plexWatch_GNTP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljunkie/plexWatch/471dcda9c91a18ae6398549609b1148378a9223a/screenshots/win7-plexWatch_GNTP.png --------------------------------------------------------------------------------