What started as an attempt to learn Python ended up with a slight obsession with creating useful and fun scripts to that interact with Plex and/or PlexPy. My favorite script so far is the ips_to_map.py.
I’ve posted some of these scripts on /r/plex and got some positive buzz so I thought I’d share them here as well. This repo is a collection of all the scripts I’ve created.
I’m adding more and am taking requests. So let me know what you think, any improvements, suggestions, requests, etc.
Create a Plex Playlist with what was aired on this today's month-day, sort by oldest first. If Playlist from yesterday exists delete and create today's. If today's Playlist exists exit.
Receive session_key from PlexPy when paused. Use sub-script wait_kill_pause_notify_sub
to wait for X time then check if still paused. If so, kill. Toggle whether you'd like to be notified through a PlexPy notification agent.
Receive session_key and IP from PlexPy when playback starts. Use IP to check against whitelist. If not in whitelist use session_key to determine stream and kill.
If user has 2 or more concurrent streams and the IP of the 2nd stream differs from 1st kill 2nd. If 2nd stream IP is the same as 1st stream don't kill.
Send an email with what was added to Plex in the past week using PlexPy. Email includes title (TV: Show Name: Episode Name; Movie: Movie Title), time added, image, and summary.
If a new IP is found send notification via the Email Notification Agent. Email contains User's Avatar image, link to location, IP address, and User's Email address.
Post to Twitter when TV/Movie is added to Plex. Include custom message and embed poster image. Option to tweet to TWITTER_USER if title is inside TITLE_FIND.
From a list of TV shows, check if users in a list has watched shows episodes. If all users in list have watched an episode of listed show, then delete episode.
Grab media (videos, pictures) from Google Drive. All videos and pictures were automatically synced from Google Photos to Google Drive. Puts media into MEDIA_TYPE/YEAR/MONTH-DAY/FILE.ext directory structure.
This is indented to restrict a user to the LIMIT amount of concurrent streams. User will be warned, punished, and banned completely if violations continue.
@Blacktwin I am getting the following error for every internal IP when I run the ips_to_maps.py script:
PlexPy API ‘get_geoip_lookup’ request failed: The address x.x.x.x is not in the database…User: John IP: x.x.x.x caused error in geo_dict.
I get this for all internal IPs but the chart produces my external connections just find. Is there a way to exclude the internal addresses if the error is expected because these are internal IPs?
@almontef You would use the REPLACEMENT_WAN_IP variable to substitute your LAN_SUBNET. The error is there to simply let you know that the local addresses aren’t being mapped.
If you don’t mind could you PM me your map? Just curious how others maps turn out. I like maps.
Thanks for the info! Love the script. I’ll PM you my map, not very interesting since I only got a few remote users, but will be sharing with more family in the upcoming weeks, but even then most connections will be from the northeast.
@Blacktwin there was a recent major update to Plexpy and the ips_to_maps script not longer works. It produces the following error:
python ips_to_maps.py
PlexPy API ‘get_get_users_tables’ request failed: No JSON object could be decoded.PlexPy API ‘get_get_users_tables’ request failed: No JSON object could be decoded.Traceback (most recent call last):
File “ips_to_maps.py”, line 380, in
user_lst = sorted(get_get_users_tables(‘friendly_name’, user_count))
TypeError: ‘NoneType’ object is not iterable
Is the script not compatible with the latest version of Plexpy? Thanks in advance.
@almontef Thanks for the heads up. I need to go through all my scripts now that Tautulli is out of beta and update them. Some may be removed and some will be improved to work better with Tautulli.
@Blacktwin I’m having issues with the kill_more_than.py script. Wasn’t sure if it was a Tautulli thing or just the way I have it setup. URL and API key are setup correctly.
@Blacktwin Hello, first thanks for your job
I have problem when i run “ips_to_maps.py -l Geo -j (my json file)” i get :
Traceback (most recent call last):
File “ips_to_maps.py”, line 449, in
print(r.json()[‘html_url’])
KeyError: ‘html_url’
And when i try run “ips_to_maps.py -l World -j (my json file)” i get :
Traceback (most recent call last):
File “ips_to_maps.py”, line 453, in
draw_map(opts.location, geo_json, filename, opts.headless)
File “ips_to_maps.py”, line 327, in draw_map
x, y = m([float(data[‘lon’]), float(SERVER_LON)], [float(data[‘lat’]), float(SERVER_LAT)])
ValueError: could not convert string to float:
This is awesome, but I am trying to figure out what the triggers, conditions, and arguments should be for the notify_added_custom.py should be. The script is exactly what I am looking for. I setup the API key and believe I have the other settings correct. Just don’t know how to fire it.
@blacktwin - take modification requests?
I’m looking to use your “kill more than” python script, but with Tautulli’s new conditions capability, I have no want of it looking for the same IP, or (seemingly) hardcoded limit of 2 inside the code itself.
Though I can read and basically understand what Python is doing, I don’t have the experience to change it and have it working myself. (I’ve tried, failure has not helped teach me)
Would you modify the script to simply look to find username’s “x” number stream and kill it?
Or perhaps create another script that does that? “kill_users_Xth_session”
I presume this should be reasonably easy (for you) using Tautulli’s {username} and {current_streams}.
Trigger - Notify on User Concurrent Streams
Arguments {username} {current_streams} (Custom kill message?)
I have 2 particular users who I don’t care if they use separate IPs or not, I simply want to limit them to 2 sessions at once no matter where they are (by setting my user concurrent threshold at 3, and conditional statements to ‘username is blah’ or ‘username is blah2’)
(They do share information I think, but let them punish themselves if the same internet household tries to watch 2 streams while the shared household is already watching something)
Bonus points for including the shutdown message to them indicating the stream limit (like the kill paused does)