Created
April 9, 2020 19:45
-
-
Save Drewster727/43402c386dae2b2ce6415aebbc6a8656 to your computer and use it in GitHub Desktop.
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 | |
from plexapi.server import PlexServer | |
from plexapi.server import CONFIG | |
import requests | |
import argparse | |
import time | |
import os | |
# Using CONFIG file | |
PLEX_URL = '' | |
PLEX_TOKEN = '' | |
IGNORE_FILE = "# Ignoring below file for Plex Dance\n{}" | |
if not PLEX_TOKEN: | |
PLEX_TOKEN = CONFIG.data['auth'].get('server_token') | |
if not PLEX_URL: | |
PLEX_URL = CONFIG.data['auth'].get('server_baseurl') | |
session = requests.Session() | |
# Ignore verifying the SSL certificate | |
session.verify = False # '/path/to/certfile' | |
# If verify is set to a path to a directory, | |
# the directory must have been processed using the c_rehash utility supplied | |
# with OpenSSL. | |
if session.verify is False: | |
# Disable the warning that the request is insecure, we know that... | |
import urllib3 | |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
class Library(object): | |
def __init__(self, data=None): | |
d = data or {} | |
self.title = d['section_name'] | |
self.key = d['section_id'] | |
# add 192.168.0.1/255.255.0.0 to public/known addresses in plex network settings | |
if __name__ == '__main__': | |
plex = PlexServer(PLEX_URL, PLEX_TOKEN) | |
sections = [] | |
sections.append(plex.library.section('TV Shows')) | |
sections.append(plex.library.section('Movies')) | |
for section in sections: | |
# Empty library trash | |
print("Emptying Trash from library... " + section.title) | |
section.emptyTrash() | |
time.sleep(5) | |
# Clean library bundles | |
print("Cleaning Bundles from library...") | |
plex.library.cleanBundles() | |
time.sleep(10) | |
# Optimize DB | |
print("Optimizing library database...") | |
plex.library.optimize() | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment