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 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