Skip to content

Instantly share code, notes, and snippets.

@BarDweller
Created July 3, 2024 23:19
Show Gist options
  • Save BarDweller/1667704d984f37fe1842baa989c8ddaf to your computer and use it in GitHub Desktop.
Save BarDweller/1667704d984f37fe1842baa989c8ddaf to your computer and use it in GitHub Desktop.
Convert Plex Playlist into Plex Collection
from plexapi.server import PlexServer
# If needed, do
# pip install plexapi
#
# Update PLEX_URL / PLEX_TOKEN / PLAYLIST_NAME / COLLECTION_NAME as required.
#
# Get PLEX_URL & PLEX_TOKEN by viewing a movie on the server, and doing 'Get Info' from the "..." menu
# Then open 'View XML' in a new tab, and extract the token and host & port from the url in the address bar.
# Ignore all the other gorp in the url.
#
# Tested with movies only, but you can likely update it for music if needed.
PLEX_URL = 'https://localhost:32400/'
PLEX_TOKEN = 'xxxxxxxxx'
PLEX_LIBRARY_NAME = 'Movies'
PLAYLIST_NAME = 'Stuff For Xmas' #Name of playlist to build collection from
COLLECTION_NAME = 'Stuff For Xmas' #Name of collection to add playlist items to.
def main():
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
ratingKeys=[]
playlists = plex.playlists()
for playlist in playlists:
if playlist.isVideo:
if playlist.title == PLAYLIST_NAME:
for item in playlist:
ratingKeys.append(item.ratingKey)
items = plex.fetchItems(ratingKeys)
library = plex.library.section(PLEX_LIBRARY_NAME)
library.batchMultiEdits(items).addCollection(COLLECTION_NAME).saveMultiEdits()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment