Skip to content

Instantly share code, notes, and snippets.

@murat3
Last active February 11, 2024 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save murat3/1eace37a6c4a681f19fb044690c2aaac to your computer and use it in GitHub Desktop.
Save murat3/1eace37a6c4a681f19fb044690c2aaac to your computer and use it in GitHub Desktop.
Plex: copy a named playlist from a managed users account to an admin account
#!/usr/bin/env python
#
# Description: Copy a named playlist to another user
# Author: murat3
# Requires:
# - python >=3.9
# - pip >=3.x
# - plexapi >=4.x
# - plex >=4.x
#
# Usage: python3 copy-playlist.py
#
# Tested with Plex 4.69.1
from plexapi.server import PlexServer
baseurl = 'http://plexhost:32400'
plexAdminToken = 'adminToken'
targetUser = 'targetUser'
nameOfPlaylistToCopy = 'aPlaylist'
plexAdmin = PlexServer(baseurl, plexAdminToken)
def main():
aPlaylist = plexAdmin.playlist(nameOfPlaylistToCopy)
aPlaylist.copyToUser(targetUser)
print('Playlist ' + aPlaylist.title + ' copied to user: ' + targetUser)
if __name__ == "__main__":
main()
print("Done")
@murat3
Copy link
Author

murat3 commented Dec 2, 2020

Plex Media Server does not support copying a Playlist from a managed user to an admin user.
This script can copy a named Playlist from one managed account to an admin account.

@bbccdd
Copy link

bbccdd commented Jun 27, 2022

Hi @murat3 how can one extract the token for a managed user please? Your script seems to be addressing exactly my challenge: copy a playlist from a managed user to an admin user. The use case is a physical album with pictures for our parents. https://github.com/evolve700/PlexPlaylistDownload allows downloading of playlists (which works fine) but only works for admin playlists. Thank you for your effort!

@murat3
Copy link
Author

murat3 commented Jun 27, 2022

@bbccdd
Copy link

bbccdd commented Jun 28, 2022

Hi @murat3 thanks for your quick reply, unexpected after having posted 2 years ago! I had already checked out that site but I did not find how to find a token for a non-admin (hence: managed) user. How to do that please?

The URL you've shared - to my understanding - only shows "Once you are signed into your Plex Media Server as an admin, it is easy to get the Plex token."

Also this official plex site does not show how to get a non-admin user token https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/

According to this post, non-admins do not have tokens, so how did you manage please?
jacobwgillespie/plex-sync#57 (comment)

@murat3
Copy link
Author

murat3 commented Jun 28, 2022

Hi @bbccdd
You can use Chrome Developer tools to inspect the HTTP GET request parameters generated using the Plex Web app, logged in as a non-admin user.
X-Plex-Token is part of the URL GET request.

@bbccdd
Copy link

bbccdd commented Jun 28, 2022

Hi @murat3 that is perfect! Indeed, the token could easily be extracted that way :-) Plexapi is not happy yet however:

plexapi.exceptions.BadRequest: Must include items to add when creating new playlist.

python3 copy-playlist.py

Traceback (most recent call last):
  File "copy-playlist.py", line 26, in <module>
    main()
  File "copy-playlist.py", line 22, in main
    plexAdmin.createPlaylist(aPlaylist.title, aPlaylist.items())
  File "/usr/local/lib/python3.8/dist-packages/plexapi/server.py", line 491, in createPlaylist
    return Playlist.create(
  File "/usr/local/lib/python3.8/dist-packages/plexapi/playlist.py", line 417, in create
    return cls._create(server, title, items)
  File "/usr/local/lib/python3.8/dist-packages/plexapi/playlist.py", line 338, in _create
    raise BadRequest('Must include items to add when creating new playlist.')
plexapi.exceptions.BadRequest: Must include items to add when creating new playlist.

Would you happen to have a clue how to add a wildcard to select all items, or perhaps anohter way around this 'BadRequest' please?
https://python-plexapi.readthedocs.io/en/latest/modules/playlist.html#

@murat3
Copy link
Author

murat3 commented Jun 28, 2022

@bbccdd use the new version; this copies a named playlist to another user; pls check the requirements

@jasehigh
Copy link

Hi @murat3 this is great, but the playlist list presented often has non numeric (hex) identifiers, but the "Select the number of the playlist to copy from" prompt only accepts a numeric. Is there a work around for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment