add plex library update. Fixes #566

This commit is contained in:
clinton-hall 2015-05-27 22:03:13 +09:30
commit 042fcce6b7
5 changed files with 51 additions and 3 deletions

View file

@ -8,7 +8,7 @@ import core
from subprocess import Popen
from core import logger, nzbToMediaDB
from core.nzbToMediaUtil import convert_to_ascii, CharReplace
from core.nzbToMediaUtil import convert_to_ascii, CharReplace, plex_update
from core.nzbToMediaUserScript import external_script
def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent):
@ -217,6 +217,8 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
elif sectionName == 'Gamez':
result = core.autoProcessGames().process(sectionName,outputDestination, inputName, status, clientAgent, inputCategory)
plex_update(inputCategory)
if result[0] != 0:
if clientAgent != 'manual':
logger.error(

View file

@ -246,6 +246,15 @@
audioExtensions = .mp3, .aac, .ogg, .ape, .m4a, .asf, .wma, .flac
metaExtensions = .nfo,.sub,.srt,.jpg,.gif
[Plex]
plex_host = localhost
plex_port = 32400
plex_token =
plex_ssl = 0
# Enter Plex category to section mapping as Category,section and separate each pair with '|'
# e.g. plex_sections = movie,3|tv,4
plex_sections =
[Transcoder]
# getsubs. enable to download subtitles.
getSubs = 0

View file

@ -116,6 +116,12 @@ DELUGEPORT = None
DELUGEUSR = None
DELUGEPWD = None
PLEXSSL = None
PLEXHOST = None
PLEXPORT = None
PLEXTOKEN = None
PLEXSEC = None
EXTCONTAINER = []
COMPRESSEDCONTAINER = []
MEDIACONTAINER = []
@ -206,7 +212,8 @@ def initialize(section=None):
NICENESS, LOG_DEBUG, FORCE_CLEAN, FFMPEG_PATH, FFMPEG, FFPROBE, AUDIOCONTAINER, EXTCONTAINER, TORRENT_CLASS, \
DELETE_ORIGINAL, PASSWORDSFILE, USER_DELAY, USER_SCRIPT, USER_SCRIPT_CLEAN, USER_SCRIPT_MEDIAEXTENSIONS, \
USER_SCRIPT_PARAM, USER_SCRIPT_RUNONCE, USER_SCRIPT_SUCCESSCODES, DOWNLOADINFO, CHECK_MEDIA, SAFE_MODE, \
TORRENT_DEFAULTDIR, NZB_DEFAULTDIR, REMOTEPATHS, LOG_ENV, PID_FILE, MYAPP, ACHANNELS, ACHANNELS2, ACHANNELS3
TORRENT_DEFAULTDIR, NZB_DEFAULTDIR, REMOTEPATHS, LOG_ENV, PID_FILE, MYAPP, ACHANNELS, ACHANNELS2, ACHANNELS3, \
PLEXSSL, PLEXHOST, PLEXPORT, PLEXTOKEN, PLEXSEC
if __INITIALIZED__:
return False
@ -351,6 +358,15 @@ def initialize(section=None):
if isinstance(REMOTEPATHS, list): REMOTEPATHS = ','.join(REMOTEPATHS) # fix in case this imported as list.
REMOTEPATHS = [ tuple(item.split(',')) for item in REMOTEPATHS.split('|') ] # /volume1/Public/,E:\|/volume2/share/,\\NAS\
PLEXSSL = int(CFG["Plex"]["plex_ssl"])
PLEXHOST = CFG["Plex"]["plex_host"]
PLEXPORT = CFG["Plex"]["plex_port"]
PLEXTOKEN = CFG["Plex"]["plex_token"]
PLEXSEC = CFG["Plex"]["plex_sections"] or None
if PLEXSEC:
if isinstance(PLEXSEC, list): PLEXSEC = ','.join(PLEXSEC) # fix in case this imported as list.
PLEXSEC = [ tuple(item.split(',')) for item in PLEXSEC.split('|') ]
devnull = open(os.devnull, 'w')
try:
subprocess.Popen(["nice"], stdout=devnull, stderr=devnull).communicate()

View file

@ -1053,6 +1053,25 @@ def server_responding(baseURL):
except (requests.ConnectionError, requests.exceptions.Timeout):
return False
def plex_update(category):
logger.debug("Attempting to update Plex Library for category %s." %(category), 'PLEX')
if core.PLEXSSL:
ulr = 'https://'
else:
url = 'http://'
url = url + core.PLEXHOST + ':' + core.PLEXPORT + '/library/sections/'
section = None
for item in core.PLEXSEC:
if item[0] == category:
section = item[1]
if section:
url = url + section + '/refresh?X-Plex-Token=' + core.PLEXTOKEN
requests.get(url, timeout=(60, 120), verify=False)
logger.debug("Plex Library has been refreshed.", 'PLEX')
else:
logger.debug("Could not identify section for plex update", 'PLEX')
def backupVersionedFile(old_file, version):
numTries = 0

View file

@ -506,7 +506,7 @@ from core.autoProcess.autoProcessGames import autoProcessGames
from core.autoProcess.autoProcessMovie import autoProcessMovie
from core.autoProcess.autoProcessMusic import autoProcessMusic
from core.autoProcess.autoProcessTV import autoProcessTV
from core.nzbToMediaUtil import getDirs, extractFiles, cleanDir, update_downloadInfoStatus, get_downloadInfo, CharReplace, convert_to_ascii, get_nzoid
from core.nzbToMediaUtil import getDirs, extractFiles, cleanDir, update_downloadInfoStatus, get_downloadInfo, CharReplace, convert_to_ascii, get_nzoid, plex_update
from core.nzbToMediaUserScript import external_script
from core import logger, nzbToMediaDB
@ -608,6 +608,8 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down
else:
result = [-1, ""]
plex_update(inputCategory)
if result[0] == 0:
if clientAgent != 'manual':
# update download status in our DB