Hey folks, there is a new Podcast category for forums https://forums.plex.tv/categories/podcasts
If you have not already, we suggest setting your Plex username to something else rather than email which is displayed on your posts in forum. You can change the username at https://app.plex.tv/desktop#!/account
Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

I made a Plex email notifier for Windows to let people know what's new in your libraries!

sup3rmarksup3rmark Posts: 11Members, Plex Pass Plex Pass

I wrote a Powershell script to report on movies recently added to your Plex library. It uses the Plex API as well as OMDBapi.com (the Open Movie Database) to fetch information on each movie. Powershell is Windows functionality, so this will only work on Windows unfortunately. I have it set up on my server as a Scheduled Task that runs every Friday at 10am, and sends the email to a Google Group I set up to include all the people I share my library with. See notes below for more info.

Here's a screenshot!

Setup:

This should be relatively easy to set up for someone running their Plex Server on a Windows machine, but if you've never used Powershell before, here's what you need to do:

  1. Download PlexCheck.ps1 to your computer from here.
  2. Download Get-CredentialFromWindowsCredentialManager.ps1 from Tobias Burger
  3. Change the .ps1 extension on Get-CredentialFromWindowsCredentialManager.ps1 to .psm1, and save it to C:\Users[username]\Documents\WindowsPowershell\Modules\Get-CredentialFromWindowsCredentialManager.
  4. Open a Powershell prompt and run the command

    Set-ExecutionPolicy Unrestricted
    
  5. Store the credentials of the email address you want to send the email from in Windows Credential Manager. Instructions here. You should store them with the name "PlexCheck" to avoid having to specify a credential name when running the script.

  6. Run the script! You can run from a Powershell prompt, or by right-clicking and selecting Run.

This currently only allows one recipient. To avoid having to modify the script or Scheduled Task all the time, I set up a Google Group, added my friends to that, and set that as the lone recipient in my Scheduled Task.

Default behavior:

.\PlexCheck.ps1

This will run the script with default values:

  • It will assume you're running it from the same box that your Media Server is running on. As such, the default IP is 127.0.0.1.
  • It uses the default Plex port, 32400.
  • The sender email address will be what's defined in your credentials in Windows Credential Manager.
  • The to address, unless otherwise specified, will be the same as the sender address. Change it at run-time.
  • This defaults to Gmail's SMTP server settings, but that can be overridden with parameters. To send from a Gmail account, "Access for less secure apps" must be turned on. Instructions here.
  • This will send over SSL, and this can't be overridden. Just do it.
  • This defaults to a 7-day lookback period, but that can be changed, if that's what you're into.

Here's an example of how to run it with all the values changed:

.\PlexCheck.ps1 -cred foo -url 10.0.0.100 -port 12345 -days 14 -emailTo 'test@email.com' -smtpServer 'smtp.server.com' -smtpPort 132

This is the first time I've publicly shared a script I wrote, so please let me know if you have any questions, comments, or suggestions!

Comments

  • m1e1w1m1e1w1 Posts: 363Members, Plex Pass Plex Pass
    edited January 2016

    @sup3rmark
    I managed to get most of the script working, but ran into a few issues.

    Sometimes, when i run the PlexCheck.ps1 script (as administrator) i get:
    ~windowsCredentialManager.psm1 : No credentials where found in Windows Credential Manager for TargetName:
    At C:\PlexCheck.ps1:56 char:9

    when that does go through, i then and always get:
    Invoke-WebRequest : 401 Unauthorized
    At C:\PlexCheck.ps1:71 char:1
    +Invoke=WebRequest "$url':$port/library/recentlyAdded/"

    so, i tested with how i have my file setup. for my plex location, i have localhost rather then 127.0.0.1 as its the same thing.... but all my pages load as localhost with everything else.

    i then wrote a full url string based on what the code calls for: localhost:32400/library/recentlyAdded/
    and i get 401 Unauthorized.

    is it an SSL issue? a plex user name issue?

    Synology DS1511+ 5x4TB + DX513 5x4TB + DX513 5x4TB (For content) + 4TB External (For PMS Library)

    Dedicated Win 10 64bit PMS - 16GB RAM - intel i7 3770K @ 4.2Ghz (PMS App)
    2 Roku 2 XS, 3 Roku 2 XD, 2 Roku 3, 4 Chromecast
    11 Android Devices, 5 IDevices
    Using browsers - Chrome, Safari, Firefox, Internet Explorer

    130mb Down / 4mb Up

  • sup3rmarksup3rmark Posts: 11Members, Plex Pass Plex Pass

    what is the full command string you're using? localhost instead of the IP shouldn't be a problem. shouldn't be a plex credentials issue either, since you don't need those to make the API call.

  • m1e1w1m1e1w1 Posts: 363Members, Plex Pass Plex Pass
    edited January 2016

    @sup3rmark

    screenshot?
    the credentials (windows Credentials (generic) i entered; might be an issue? i entered Internet or network address as: PlexCheck, User name as the email address i want to send to (as a login?) and password of the email account.
    running in WIN 10, powershell is running as admin, permission is set as unrestricted. only change in the code i made was the email address to send the report instead of test@test.com (default) i entered my gmail.

    Other things to note:
    my plex loads with the url http://localost:32400/web/index.html#
    writing the url with http://localhost:32400/library/recintlyAdded/ = 401 unauthorized.

    I believe my library is not stored on C:\, but is stored on H:\Plex Media Server\plug-in Support\Databases\

    Synology DS1511+ 5x4TB + DX513 5x4TB + DX513 5x4TB (For content) + 4TB External (For PMS Library)

    Dedicated Win 10 64bit PMS - 16GB RAM - intel i7 3770K @ 4.2Ghz (PMS App)
    2 Roku 2 XS, 3 Roku 2 XD, 2 Roku 3, 4 Chromecast
    11 Android Devices, 5 IDevices
    Using browsers - Chrome, Safari, Firefox, Internet Explorer

    130mb Down / 4mb Up

  • sup3rmarksup3rmark Posts: 11Members, Plex Pass Plex Pass

    @m1e1w1 so, the email address you should be putting in Credential Manager should be the From address. you don't need to/shouldn't alter the code to set the To address, just pass that as a parameter. same as the URL: if you don't want to use the 127.0.0.1 IP (which should be totally fine with what you've said about your setup), you can also pass that in:
    .\PlexCheck.ps1 -emailTo recipient@test.com -url localhost

    try downloading the script again and using it as-is, passing in the values you want instead of modifying it. i'd also recommend running it from your Documents folder instead of root c:. if that still doesn't work, try pointing your web browser (on the server itself) at 127.0.0.1:32400/library/RecentlyAdded and see if that returns the expected XML.

  • m1e1w1m1e1w1 Posts: 363Members, Plex Pass Plex Pass

    @sup3rmark
    i just tried 127.0.0.1:32400/library/RecentlyAdded and localhost:32400/library/RecentlyAdded URL and i dont get an XML page. just 401 unauthorized. i will drop new scripts too, but i think i will need to resolve the 401 error before i even get data to email.

    Synology DS1511+ 5x4TB + DX513 5x4TB + DX513 5x4TB (For content) + 4TB External (For PMS Library)

    Dedicated Win 10 64bit PMS - 16GB RAM - intel i7 3770K @ 4.2Ghz (PMS App)
    2 Roku 2 XS, 3 Roku 2 XD, 2 Roku 3, 4 Chromecast
    11 Android Devices, 5 IDevices
    Using browsers - Chrome, Safari, Firefox, Internet Explorer

    130mb Down / 4mb Up

  • m1e1w1m1e1w1 Posts: 363Members, Plex Pass Plex Pass
    edited January 2016


    @sup3rmark
    I corrected the credentials page, per instructions as well as new scripts.

    Synology DS1511+ 5x4TB + DX513 5x4TB + DX513 5x4TB (For content) + 4TB External (For PMS Library)

    Dedicated Win 10 64bit PMS - 16GB RAM - intel i7 3770K @ 4.2Ghz (PMS App)
    2 Roku 2 XS, 3 Roku 2 XD, 2 Roku 3, 4 Chromecast
    11 Android Devices, 5 IDevices
    Using browsers - Chrome, Safari, Firefox, Internet Explorer

    130mb Down / 4mb Up

  • sup3rmarksup3rmark Posts: 11Members, Plex Pass Plex Pass

    @m1e1w1 the 401 is definitely something to do with your server, not the script... you might be using a different port or something. you're running the script on the PMS, right? go to your plex server settings page, hit up the Remote Access tab, and tell me what it says next to Private.

    feel free to hit me up on hangouts to discuss this more easily - [myusername]@gmail.com

  • m1e1w1m1e1w1 Posts: 363Members, Plex Pass Plex Pass

    sure. i started a conversation in hangouts.

    Synology DS1511+ 5x4TB + DX513 5x4TB + DX513 5x4TB (For content) + 4TB External (For PMS Library)

    Dedicated Win 10 64bit PMS - 16GB RAM - intel i7 3770K @ 4.2Ghz (PMS App)
    2 Roku 2 XS, 3 Roku 2 XD, 2 Roku 3, 4 Chromecast
    11 Android Devices, 5 IDevices
    Using browsers - Chrome, Safari, Firefox, Internet Explorer

    130mb Down / 4mb Up

  • m1e1w1m1e1w1 Posts: 363Members, Plex Pass Plex Pass

    @sup3rmark
    after checking the thread you posted, it reviews if i have a pin enabled, and i do not. i did try and enable a pin, and then removed it, rebooted the PMS, still getting 401. I've also tried to see if the network subnet was an issue, and for the PMS machine, i was on the same subnet as my router. i do have a synology nas that has 2 subnet addresses, 1 matches the router and the other is a VPN's subnet. i disabled the VPN, tested and that made no difference.
    i checked my router just to be sure that port 32400 was open for any connection, and it is.

    still have 401 unauthorized when using the url: localhost or 127.0.0.1 and :32400/library/recentlyAdded/ as the script requires.

    Synology DS1511+ 5x4TB + DX513 5x4TB + DX513 5x4TB (For content) + 4TB External (For PMS Library)

    Dedicated Win 10 64bit PMS - 16GB RAM - intel i7 3770K @ 4.2Ghz (PMS App)
    2 Roku 2 XS, 3 Roku 2 XD, 2 Roku 3, 4 Chromecast
    11 Android Devices, 5 IDevices
    Using browsers - Chrome, Safari, Firefox, Internet Explorer

    130mb Down / 4mb Up

  • sup3rmarksup3rmark Posts: 11Members, Plex Pass Plex Pass

    @m1e1w1 unfortunately, i don't know if i can help you with that issue. the problem you're having is with your server, and is unrelated to the script. good luck!

  • sup3rmarksup3rmark Posts: 11Members, Plex Pass Plex Pass
    edited January 2016

    Preview of season-level TV Show support (should be uploaded tonight). Episode-level is possible, but not simple; I can work on that if there's interest.

  • kees2810kees2810 Posts: 7Members, Plex Pass Plex Pass
    edited February 2016

    Sup3rmark script looks nice. But i cant get it work.

    My server is standard Windows 7 with PMS. I get an error when i run it.
    What could it be?

    Could it be the version of powershell or something else?

    I didn't edited something only the emailaddress in param. Its just running on my localhost with standard port internal 32400.


    Just searched the internet and it could be the version. On windows 7 powershell 2.0 is installed. You could install powershell 3.0 manual. I will try today.


    Indeed you have to install Powershell 3.0 or you will get the error like i did. I am going to test it further.

  • kees2810kees2810 Posts: 7Members, Plex Pass Plex Pass
    edited February 2016

    The script creates a library.xml that is fine but i get a few errors with the credentials.
    I created a credential named plexcheck with username: my emailaddress and password.

    But i stil get the following errors.

    I think i did something wrong but don't know what. Could you help me?

    Greetings

  • C.E.WafflesC.E.Waffles Posts: 16Members ✭✭

    What version of Powershell should I have installed?

    Here's the error I am getting. I've gone through the post and cannot send anything, I get the following error. I've tried with and out the arguments.
    http://oi65.tinypic.com/ve9dz6.jpg

  • twilliamsjtwilliamsj Posts: 4Members ✭✭

    This is very cool. I had to massage it a little to get it to work, and it helps to be able to actually read the error messages and understand what it is asking for.
    the one thing that is left out of the instructions (for newbs like me) is that you need to get an APIKey and add that to the $omdbURL so that the website will actually respond to your request. Also, if you are going to schedule this as a task, you should put your token in the script instead of requesting it as a parameter.

    @sup3rmark , thanks for putting this together. This is going to get regular use!

  • twilliamsjtwilliamsj Posts: 4Members ✭✭

    I've found a few things that caused me some pain, and thought i would share: The way this is written, If there is a TV series that has the same name as a movie, the Series will show with the information for the move and not the series. I've been able to correct that, i modified the line (only do this in the $tvshows section) $omdbURL = "omdbapi.com/?apikey=xxxxxxx&t=$($show.name)&r=JSON"
    modify this to: $omdbURL = "omdbapi.com/?apikey=xxxxxxx&t=$($show.name)&type=series&r=JSON"

    adding the type makes is look for the title as a series instead of the default movies.

    Again, this is an awesome script to send a notice to users.

    T

Sign In or Register to comment.