Files
Membarr/app/bot/helper/plexhelper.py
2021-08-04 19:24:08 -04:00

73 lines
2.4 KiB
Python

from plexapi.myplex import MyPlexAccount
import re
def plexadd(plex, plexname, Plex_LIBS):
try:
if Plex_LIBS[0] == "all":
Plex_LIBS = plex.library.sections()
plex.myPlexAccount().inviteFriend(user=plexname, server=plex, sections=Plex_LIBS, allowSync=False,
allowCameraUpload=False, allowChannels=False, filterMovies=None,
filterTelevision=None, filterMusic=None)
print(plexname +' has been added to plex')
return True
except Exception as e:
print(e)
return False
def plexhomeadd(plex, plexname, Plex_LIBS):
try:
if Plex_LIBS[0] == "all":
Plex_LIBS = plex.library.sections()
plex.myPlexAccount().createHomeUser(user=plexname, server=plex, sections=Plex_LIBS, allowSync=False,
allowCameraUpload=False, allowChannels=False, filterMovies=None,
filterTelevision=None, filterMusic=None)
print(plexname +' has been added to plex home')
return True
except Exception as e:
print(e)
return False
def plexremovehome(plex, plexname):
try:
plex.myPlexAccount().removeFriend(user=plexname)
print(plexname +' has been removed from plex home')
return True
except Exception as e:
print(e)
return False
def plexremove(plex, plexname):
try:
plex.myPlexAccount().removeFriend(user=plexname)
print(plexname +' has been removed from plex')
return True
except Exception as e:
print(e)
return False
'''
plex python api has no tools to remove unaccepted invites...
print("Trying to remove invite...")
removeinvite = plexremoveinvite(plex, plexname)
if removeinvite:
return True
'''
'''
def plexremoveinvite(plex, plexname):
try:
plex.myPlexAccount().removeFriend(user=plexname)
print(plexname +' has been removed from plex')
return True
except Exception as e:
print(e)
return False
'''
def verifyemail(addressToVerify):
regex = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$'
match = re.match(regex, addressToVerify.lower())
if match == None:
return False
else:
return True