Skip to content

Instantly share code, notes, and snippets.

@JonnyWong16
Last active November 9, 2024 07:56
Show Gist options
  • Save JonnyWong16/148b5a5dc39211bd6a871cb8f9df8c48 to your computer and use it in GitHub Desktop.
Save JonnyWong16/148b5a5dc39211bd6a871cb8f9df8c48 to your computer and use it in GitHub Desktop.
Create a Plex collection from a text file list of rating keys.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Description: Create a Plex collection from a text file list of rating keys.
# Author: /u/SwiftPanda16
# Requires: plexapi
from plexapi.server import PlexServer
### EDIT SETTINGS ###
PLEX_URL = 'http://localhost:32400'
PLEX_TOKEN = 'xxxxxxxxxx'
PLEX_LIBRARY_NAME = 'Movies'
COLLECTION_NAME = 'New Collection'
TEXT_FILE_LIST = '/path/to/rating_keys.txt' # One rating key (media ID) per line
### CODE BELOW ###
def main():
with open(TEXT_FILE_LIST, 'r') as f:
ratingKeys = [int(r.strip()) for r in f.readlines()]
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
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