61 lines
1.4 KiB
Python
61 lines
1.4 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')
|
|
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()
|