plex-tools/remove_lonely_collections.py
deathbybandaid a000043400 test
2024-02-21 10:05:58 -05:00

62 lines
1.5 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import pathlib
import subprocess
import requests
from plexapi.server import PlexServer
import urllib3
urllib3.disable_warnings()
SCRIPT_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
# PLEX_URL = "http://127.0.0.1:32400"
# PLEX_TOKEN = 'GfMXZTPscfvLazy_pyLP'
class plex_info():
@property
def address(self):
return "127.0.0.1"
@property
def port(self):
return "32400"
@property
def proto(self):
return "http://"
@property
def token(self):
token_script = pathlib.Path(SCRIPT_DIR).joinpath('plex-token.sh')
print(token_script)
token_proc = subprocess.Popen(['/bin/bash', token_script], stdout=subprocess.PIPE)
token = token_proc.stdout.read().decode().strip("\n")
token_proc.terminate()
token_proc.communicate()
token_proc.kill()
# token = subprocess.run(['/bin/bash', token_script], capture_output=True, text=True).stdout
return token
@property
def url(self):
return '%s%s:%s' % (self.proto, self.address, str(self.port))
print(plex_info.token)
#sess = requests.Session()
#sess.verify = False
#plex = PlexServer(plex_info.url, plex_info.token, session=sess)
#all_libraries = plex.library.sections()
#for library in all_libraries:
# for collection in library.search(libtype="collection"):
# if collection.childCount == 0:
# collection.delete()