Skip to content

Instantly share code, notes, and snippets.

@jmarhee
Last active May 29, 2024 22:54
Show Gist options
  • Save jmarhee/c2d2d9bff9ba545ba214b6a4fd70da5d to your computer and use it in GitHub Desktop.
Save jmarhee/c2d2d9bff9ba545ba214b6a4fd70da5d to your computer and use it in GitHub Desktop.
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()
@mbielech5
Copy link

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!

@jmarhee
Copy link
Author

jmarhee commented Feb 28, 2023

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"
}

@mbielech5
Copy link

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

@TheOne320
Copy link

How do I use the script with 2FA on? Could you set it up to use "X-Plex-Token"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment