ljunkie, is there a way to run a report based on users?
Also would like to see total duration combined for the users? Would be useful to track how much time the kiddos are using plex(considering they like to 'surf plex' by stopping and starting new episodes every 2 minutes. I would love to be able to see who's the top viewers based on duration.
ljunkie, is there a way to run a report based on users?
Also would like to see total duration combined for the users? Would be useful to track how much time the kiddos are using plex(considering they like to 'surf plex' by stopping and starting new episodes every 2 minutes. I would love to be able to see who's the top viewers based on duration.
* '-stats' option added to '-watched' - show total watched time per user -- total time and per day
* '-user' option added to '-watched' and '-watching' -- limit output to a specific user
* $user_display hashref added to config - you can now show a 'friendly' username instead of the users email address [excluding @domain.tld]
* 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
* 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
Example: notice the --stats will work with date ranges, if you want all, don't include the date range.
/plexWatch.pl --watched --stats --user frank --start=yesterday
* Limiting results to frank [real_user]
======================================== Watched ========================================
Date Range: Sun Jun 30 00:00:00 2013 through Now
User: Frank
Sun Jun 30 07:15:02 2013: Frank watched: A Good Day to Die Hard [2013] [R] [duration: 1 hour, 31 minutes, and 59 seconds]
Sun Jun 30 15:12:01 2013: Frank watched: Your Highness [2011] [R] [duration: 1 hour, 56 minutes, and 53 seconds]
Sun Jun 30 15:46:02 2013: Frank watched: Star Trek [2009] [PG-13] [duration: 2 hours, 8 minutes, and 18 seconds]
Sun Jun 30 21:10:01 2013: Frank watched: Judge Dredd [1995] [R] [duration: 1 hour, 41 minutes, and 1 second]
======================================== Stats ========================================
user: Frank's total duration 7 hours, 18 minutes, and 11 seconds
Sun Jun 30 2013: Frank 7 hours, 18 minutes, and 11 seconds
Latest version works great with the stats. I realize my kids are spending too much time on plex heh.
I noticed the season and episode number doesn't show up in the notification. Is there anyway to add it to the nofications? I don't see it stored in the xml so no biggie if you can't.
Latest version works great with the stats. I realize my kids are spending too much time on plex heh.
I noticed the season and episode number doesn't show up in the notification. Is there anyway to add it to the nofications? I don't see it stored in the xml so no biggie if you can't.
Tell your kids I'm sorry :) The season and episode have been added to the alert. Should work going backwards for the cli options.
Thanks ljunkie. I tried to get the script working on OSX 10.8.4. Installed the Perl dependencies via cpan with no problem but when I execute the script (manually) I get the following error message:
DBD::SQLite::db prepare failed: disk I/O error at ./plexWatch.pl line 575.
disk I/O error at ./plexWatch.pl line 575.
Looking at the code, it looks like its failing to establish a connection to the sqllite database file thats in the plexWatch folder. The plexWatch.db is created (empty) and the error seems to occur because table sqlite_master doesn't appear to exist.
Any ideas?
EDIT: Nevermind, I figured out the problem. The path for plexWatch was inside a NAS mounted volume, I moved plexWatch to a local HDD filesystem and hey presto Disk I/O errors have disappeared and all appears to be working well.
Anyone know how to install the dependencies on OSX with macports. I tried cpan but get compile errors with WWW::Curl::Easy. I fear my macport install is impacting cpan.
UPDATE: Ok, i was able to install the dependencies after upgrading cpan to v2. However, i had to force install WWW::Curl::Easy as it would not install on it's own. All other dependencies installed ok. However, when i run the script it says nothing is being watched or has been watched even. Has anyone got this working on OSX?
Anyone know how to install the dependencies on OSX with macports. I tried cpan but get compile errors with WWW::Curl::Easy. I fear my macport install is impacting cpan.
UPDATE: Ok, i was able to install the dependencies after upgrading cpan to v2. However, i had to force install WWW::Curl::Easy as it would not install on it's own. All other dependencies installed ok. However, when i run the script it says nothing is being watched or has been watched even. Has anyone got this working on OSX?
Yep, I had to force install of WWW::Curl::Easy too. I can confirm its working well on OSX 10.8.4.
The script is run in two parts. When run with no parameters or with the --notify flag the script silently collects Plex Now Playing information and logs it to the database and to the log file (default behaviour). This is what the cron job is doing; running ./plexWatch.pl every second, every minute, every day etc.You can also configure the script to integrate with Prowl/Pushover.
Once the script has been running for a while and its collected data (you need to ensure users have started watching some media before you do this) you can run a 2nd instance of the script with the --watched / --watching flags to interrogate the database and output any Now Playing start/stop entries.
I was worried that forcing the install of curl was causing an issue so i actually downloaded the source (https://github.com/szbalint/WWW--Curl) and installed it directly, which installed without error.
So let me make sure i understand correctly. The script needs to continually run so it can capture the Now Playing data. It can't pull it retroactively. So i will need a cron job or other mechanism to continually run it through the day to capture. Is that correct?
I was worried that forcing the install of curl was causing an issue so i actually downloaded the source (https://github.com/szbalint/WWW--Curl) and installed it directly, which installed without error.
So let me make sure i understand correctly. The script needs to continually run so it can capture the Now Playing data. It can't pull it retroactively. So i will need a cron job or other mechanism to continually run it through the day to capture. Is that correct?
Yes, unless plex has some secret log, you have to cron the script. It's lightweight, so running it every minute is safe. Refer to steps #5 and #6.
I'm mobile otherwise I'd have a more detailed response.
I was worried that forcing the install of curl was causing an issue so i actually downloaded the source (https://github.com/szbalint/WWW--Curl) and installed it directly, which installed without error.
So let me make sure i understand correctly. The script needs to continually run so it can capture the Now Playing data. It can't pull it retroactively. So i will need a cron job or other mechanism to continually run it through the day to capture. Is that correct?
Yes. You have one script running (without any flags) every minute via cron to collect data. This is because the published Plex Now Playing information (http://localhost:32400/status/sessions) holds real time data only. No historical data is logged (to my knowledge).
You run a second instance to view historical or currently playing information.
I manually edited the script to create another notification service for growlnotify. That way i get notifications on my desktop as well as through Prowl. I know this is very specific to OSX but if anyone's interested i can share the changes i made.
I manually edited the script to create another notification service for growlnotify. That way i get notifications on my desktop as well as through Prowl. I know this is very specific to OSX but if anyone's interested i can share the changes i made.
Yes. Any additionally notification options that have been tested is much appreciated. I will add the code to a new version so plexWatch will have it ongoing for any future updates.
Thanks for the clarification. I created a LaunchAgent and it's running every second. So far so good.
Every second? that might be a little too quick. If it seems to work though, go for it. It is possible that someone could stop and start a show within a minute... but I wasn't too worried about those as that isn't really watched at all imho.
Yes. Any additionally notification options that have been tested is much appreciated. I will add the code to a new version so plexWatch will have it ongoing for any future updates.
In the variables section i added two variables that are used for growlnotify
## Growl variables
my $growlnotify = '/usr/local/bin/growlnotify';
my $plexIcon = '/Applications/Plex Media Server.app/Contents/Resources/MyPlex.icns';
Under the section ##Notification Options i added:
'growl' => {
'enabled' => 1, ## set to 1 to enable local growl
'application' => $appname
},
In subroutine Notify() i added
if ($notify->{'growl'}->{'enabled'}) { &NotifyGrowl($alert, $extra); }
Then i created a new subroutine called NotifyGrowl:
sub NotifyGrowl() {
my $alert = shift;
my $extra = shift;
my $message = $alert . $extra;
system( "$growlnotify", "-n", $appname, "--image", $plexIcon, "-m", $message);
}
I don't know perl so i pretty much hacked this together so it's not great and could definitely use some cleaning by someone who is good at perl
In the variables section i added two variables that are used for growlnotify
## Growl variables
my $growlnotify = '/usr/local/bin/growlnotify';
my $plexIcon = '/Applications/Plex Media Server.app/Contents/Resources/MyPlex.icns';
Under the section ##Notification Options i added:
'growl' => {
'enabled' => 1, ## set to 1 to enable local growl
'application' => $appname
},
In subroutine Notify() i added
if ($notify->{'growl'}->{'enabled'}) { &NotifyGrowl($alert, $extra); }
Then i created a new subroutine called NotifyGrowl:
sub NotifyGrowl() {
my $alert = shift;
my $extra = shift;
my $message = $alert . $extra;
system( "$growlnotify", "-n", $appname, "--image", $plexIcon, "-m", $message);
}
I don't know perl so i pretty much hacked this together so it's not great and could definitely use some cleaning by someone who is good at perl
Looks good. I will look into adding this in the next release. Can you point me to the source your used for '/usr/local/bin/growlnotify'
Worth mentioning that growlnotify is an Extra package thats not bundled with the standard Growl.app for OSX. You can download growlnotify from here: http://growl.cachefly.net/GrowlNotify-2.0.zip
UPDATE: I also tweaked the 'extra' information to drop the summary field data. I did this for both the console log and the Growl notification message as the summary field data can be quite long in cases and when so causes the summary to span several lines. I left the data in the database though.
UPDATE: Just discovered Growl can chain the notifications to other frameworks including OSX Notificitions, Prowl, SMS, bark and several others. Sweet.