Last active
April 24, 2025 18:53
-
-
Save jmarhee/c2d2d9bff9ba545ba214b6a4fd70da5d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from plexapi.myplex import MyPlexAccount | |
import os | |
plex_auth_info = { | |
"username" : os.environ['PLEX_USERNAME'], | |
"password" : os.environ['PLEX_PASSWORD'], | |
"server" : os.environ['PLEX_SERVER_NAME'] | |
} | |
account = MyPlexAccount(plex_auth_info['username'], plex_auth_info['password']) | |
plex = account.resource(plex_auth_info['server']).connect() | |
collections = plex.library.section("Movies").collections() | |
for idx, val in enumerate(collections): | |
if plex.library.section("Movies").collection(title=collections[idx].title).childCount != 0: | |
continue | |
else: | |
plex.library.section("Movies").collection(title=collections[idx].title).delete() |
The script assumes these are set in your environment when you run the script:
plex_auth_info = {
"username" : os.environ['PLEX_USERNAME'],
"password" : os.environ['PLEX_PASSWORD'],
"server" : os.environ['PLEX_SERVER_NAME']
}
so something like:
PLEX_USERNAME="" PLEX_PASSWORD="" PLEX_SERVER_NAME="" python3 ./delete-empty-collections.py
But you can also just modify lines 4-8 of the script like this:
plex_auth_info = {
"username" : "YOUR_USERNAME"
"password" : "YOUR_PASSWORD",
"server" : "YOUR_SERVER_NAME"
}
Ahh, I understand much better now, thank you for clarifying! Excellent script by the way, so I thank you for all your hard work on it. Cheers
How do I use the script with 2FA on? Could you set it up to use "X-Plex-Token"?
How do I use the script with 2FA on? Could you set it up to use "X-Plex-Token"?
Thanks, I had already modified the script based on another script that used X-Plex-Token. It works fine.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a readme for this script? I'm not sure exactly where to replace my username, password, and server name in the code. Any help would be greatly appreciated. Thank you!