-
-
Save JonnyWong16/2607abf0e3431b6f133861bbe1bb694e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# | |
# Description: Sync Plex playlists to shared users. | |
# Author: /u/SwiftPanda16 | |
# Requires: plexapi | |
from plexapi.exceptions import NotFound | |
from plexapi.server import PlexServer | |
### EDIT SETTINGS ### | |
PLEX_URL = 'http://localhost:32400' | |
PLEX_TOKEN = 'xxxxxxxxxx' | |
# List of playlists to sync, set PLAYLISTS = None to sync all playlists | |
PLAYLISTS = ['Playlist 1', 'Playlist 2', 'Playlist 3'] | |
# List of users to sync the playlists to, set USERS = None to sync to all users | |
USERS = ['Username 1', 'Username 2', 'Username 3'] | |
### CODE BELOW ### | |
def sync_playlists(): | |
plex = PlexServer(PLEX_URL, PLEX_TOKEN) | |
account = plex.myPlexAccount() | |
if PLAYLISTS is None: | |
playlists = plex.playlists() | |
else: | |
playlists = [plex.playlist(playlist) for playlist in PLAYLISTS] | |
if USERS is None: | |
users = account.users() | |
else: | |
users = [account.user(username) for username in USERS] | |
for user in users: | |
user_plex = plex.switchUser(user.username or user.title) | |
for playlist in playlists: | |
print(f"Syncing playlist '{playlist.title}' to user '{user.username or user.title}'...") | |
# Delete the old playlist | |
try: | |
user_plex.playlist(playlist.title).delete() | |
except NotFound: | |
pass | |
# Create a new playlist | |
user_plex.createPlaylist(playlist.title, items=playlist.items()) | |
if __name__ == "__main__": | |
sync_playlists() | |
print("Done.") |
brettwatson77
commented
Dec 8, 2021
via email
if youre using the newest version of PlexAPI you probably need to change user_plex.createPlaylist(playlist, playlist_items)
to user_plex.createPlaylist(playlist, items=playlist_items)
the items need to be specified as they no longer just the second argument
@meisnate12 that would be great if you updated your github repo. I'm really interested in using your library to share my playlists with my managed users.
THX
@meisnate12
Thank you for the tip. With that correction the script worked perfect for me.
@meisnate12 that would be great if you updated your github repo. I'm really interested in using your library to share my playlists with my managed users. THX
not really sure what any of my repos have to do with this file.
@meisnate12 Thank you for the tip. With that correction the script worked perfect for me.
no problem glad it worked for you
I'm getting the following error when running the script:
User 'FirstName LastName' not found in shared users. Skipping.
However, that user is one of my shared users. Not sure why I'm getting that error. Also, that user is the only one that has their first and last name set in their account, in addition to their username. I'm wondering if that has something to do with it; the error is showing the first and last name in the output, instead of their username like all the others.
I got this working on my synology nas on plexapi 4.15.4. awesome job man. cheers!
When I run this, it syncs the playlist to my managed user, but it seems to hang the server. Immediately after running, the Movies and TV pages say "Your home screen is empty" or "Not Authorized". Then when I immediately restart the plex server, everything is as it should be, sync'd playlists and all. Has anyone experienced anything like this, and is there a fix?
And it's not just the user, it's all users, including the admin user, which get empty library screens.
I am running PMS version: v1.40.2.8351-9938371be
Thanks!