Last active
May 16, 2024 21:20
-
-
Save JonnyWong16/148b5a5dc39211bd6a871cb8f9df8c48 to your computer and use it in GitHub Desktop.
Create a Plex collection from a text file list of rating keys.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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