blacktwin / JBOPS

Just a Bunch Of Plex Scripts
1.66k stars 308 forks source link

Please add the ability to set exclusion labels per user #336

Closed khaosx closed 2 years ago

khaosx commented 2 years ago

Is your feature request an improvement on an existing script? Please link to script.

This request is for modification of utility/plex_api_share.py to allow for setting any/all users' exclusion labels within Plex. I've seen a couple of commits that appear to set the stage for this, but I don't see anything that completely enables it. I use this script to declaratively assign permissions for remote users to ensure recoverability and config management. Every morning at 02:00 I unshare everything from all users and reassign based on rules I've built in my script. I've recently been playing around with excluding content based off the sharing tag within Plex and would like to incorporate this into my workflow by adding an exclude tag for all users (e.g. "TotallyUsingThisTagToKeepMyKidsFromSeeingMyWifesFreakyPornStash").

Is your feature request related to a problem? Please describe. No, but I am always frustrated when I think about my kids seeing my wife's freaky porn stash. Yep. Not trying to hide my questionable anime. Not at all.

Describe alternatives you've considered I've considered selling them to the circus, but I don't think the circus actually exists anymore. I've also considered setting the inclusion tags on 99% of my media to "TotesNotPorn", but that's a lot of management. There are various ways I could accomplish this with other tools, or even manually, but this script is perfect for my needs except for this minor piece. Thank you for your consideration!

blacktwin commented 2 years ago

Try https://github.com/blacktwin/JBOPS/pull/262 and the latest version of PlexAPI. Let me know if it works and I'll merge it.

khaosx commented 2 years ago

@blacktwin Tested and verified. Thanks!

edit: Spoke too soon. Movies works perfectly, TV throws the following error:


No Plex Pass moving on...
Traceback (most recent call last):
  File "/home/kris/scripts/jbops/utility/plex_api_share.py", line 456, in <module>
    share(user, addedLibraries, sync, camera, channels, filterMovies, filterTelevision,
  File "/home/kris/scripts/jbops/utility/plex_api_share.py", line 228, in share
    plex.myPlexAccount().updateFriend(user=user, server=plex, sections=sections, allowSync=allowSync,
  File "/home/kris/.local/lib/python3.9/site-packages/plexapi/myplex.py", line 475, in updateFriend
    params['filterTelevision'] = self._filterDictToStr(filterTelevision or {})
  File "/home/kris/.local/lib/python3.9/site-packages/plexapi/myplex.py", line 570, in _filterDictToStr
    values.append('%s=%s' % (key, '%2C'.join(vals)))
TypeError: sequence item 0: expected str instance, list found```
khaosx commented 2 years ago

@blacktwin Any thoughts on this?

blacktwin commented 2 years ago

Do you have a Plex Pass? Also can you provide your entire command string?

khaosx commented 2 years ago

Correct - I have Plex Pass. As noted, the exclude labels work on movies, just not on TV episodes.

Commands I have tried: python3 /home/kris/scripts/jbops/utility/plex_api_share.py --user "Kris Newman" --add --movieLabels label!=Restricted --tvLabels label!=Restricted - never works, same error as below

python3 /home/kris/scripts/jbops/utility/plex_api_share.py --user "Kris Newman" --add --movieLabels label!=Restricted - works every time

python3 /home/kris/scripts/jbops/utility/plex_api_share.py --user "Kris Newman" --add --tvLabels label!=Restricted

This returns:

No Plex Pass moving on...
Traceback (most recent call last):
  File "/home/kris/scripts/jbops/utility/plex_api_share.py", line 456, in <module>
    share(user, addedLibraries, sync, camera, channels, filterMovies, filterTelevision,
  File "/home/kris/scripts/jbops/utility/plex_api_share.py", line 228, in share
    plex.myPlexAccount().updateFriend(user=user, server=plex, sections=sections, allowSync=allowSync,
  File "/home/kris/.local/lib/python3.9/site-packages/plexapi/myplex.py", line 475, in updateFriend
    params['filterTelevision'] = self._filterDictToStr(filterTelevision or {})
  File "/home/kris/.local/lib/python3.9/site-packages/plexapi/myplex.py", line 570, in _filterDictToStr
    values.append('%s=%s' % (key, '%2C'.join(vals)))
TypeError: sequence item 0: expected str instance, list found

Weirdly, I can set them manually in Plex, and then run a backup from the same script, and those values are present in the JSON, and respected on restore. Not sure if that's connected or not, but I thought I'd mention it.

blacktwin commented 2 years ago

@khaosx try now, please

khaosx commented 2 years ago

Tested and verified. Thank you for this addition! Closing the issue.