Advertisement
PlowmanPlow

Simply PlexAPI Collections

Jun 19th, 2020
2,556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. from plexapi.myplex import MyPlexAccount
  2. from plexapi.server import PlexServer
  3. from plexapi.media import Media
  4. from pprint import pprint
  5. import requests
  6. import sys
  7.  
  8. if len(sys.argv) != 3:
  9.     print("Input Error! Usage: updatecoll.py {/path/to/videos/folder/} {CollectionName}")
  10.     sys.exit(1)
  11.  
  12. PLEX_URL = 'http://localhost:32400'
  13. PLEX_TOKEN = 'plextokengoeshere'
  14. PATH_FOLDER = sys.argv[1]
  15. COLLECTION_NAME = sys.argv[2]
  16.  
  17. plex = PlexServer(PLEX_URL, PLEX_TOKEN)
  18.  
  19. for video in plex.library.section('Movies').all():
  20.     for part in video.iterParts():
  21.         if part.file[0:len(PATH_FOLDER)] == PATH_FOLDER:
  22.             hasCollection = False
  23.             for tag in video.collections:
  24.                 if tag.tag == COLLECTION_NAME:
  25.                     hasCollection = True
  26.             if hasCollection == True:
  27.                 continue
  28.             video.addCollection(COLLECTION_NAME)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement