2017-04-03 01:02:41 +10:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-07-13 02:46:02 +10:00
|
|
|
from __future__ import absolute_import, division, unicode_literals
|
2017-04-03 01:02:41 +10:00
|
|
|
from logging import getLogger
|
|
|
|
|
2018-10-20 23:49:04 +11:00
|
|
|
from . import common
|
|
|
|
from .. import plex_functions as PF, backgroundthread, utils
|
2017-04-03 01:02:41 +10:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
2018-04-18 04:18:25 +10:00
|
|
|
LOG = getLogger("PLEX." + __name__)
|
2017-04-03 01:02:41 +10:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
2018-10-20 23:49:04 +11:00
|
|
|
class GetMetadataTask(backgroundthread.Task, common.libsync_mixin):
|
2017-04-03 01:02:41 +10:00
|
|
|
"""
|
|
|
|
Threaded download of Plex XML metadata for a certain library item.
|
2018-10-20 23:49:04 +11:00
|
|
|
Fills the queue with the downloaded etree XML objects
|
2017-04-03 01:02:41 +10:00
|
|
|
|
|
|
|
Input:
|
2018-10-20 23:49:04 +11:00
|
|
|
queue Queue.Queue() object where this thread will store
|
2017-04-03 01:02:41 +10:00
|
|
|
the downloaded metadata XMLs as etree objects
|
|
|
|
"""
|
2018-10-20 23:49:04 +11:00
|
|
|
def setup(self, queue, plex_id, get_children=False):
|
2017-04-03 01:02:41 +10:00
|
|
|
self.queue = queue
|
2018-10-20 23:49:04 +11:00
|
|
|
self.plex_id = plex_id
|
|
|
|
self.get_children = get_children
|
2017-04-03 01:02:41 +10:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
"""
|
|
|
|
Do the work
|
|
|
|
"""
|
2018-10-20 23:49:04 +11:00
|
|
|
if self.isCanceled():
|
|
|
|
return
|
|
|
|
# Download Metadata
|
2018-10-26 03:14:35 +11:00
|
|
|
item = {
|
|
|
|
'xml': PF.GetPlexMetadata(self.plex_id),
|
|
|
|
'children': None
|
|
|
|
}
|
|
|
|
if item['xml'] is None:
|
2018-10-20 23:49:04 +11:00
|
|
|
# Did not receive a valid XML - skip that item for now
|
|
|
|
LOG.error("Could not get metadata for %s. Skipping that item "
|
|
|
|
"for now", self.plex_id)
|
2018-10-25 02:54:10 +11:00
|
|
|
return
|
2018-10-26 03:14:35 +11:00
|
|
|
elif item['xml'] == 401:
|
2018-10-20 23:49:04 +11:00
|
|
|
LOG.error('HTTP 401 returned by PMS. Too much strain? '
|
|
|
|
'Cancelling sync for now')
|
|
|
|
utils.window('plex_scancrashed', value='401')
|
|
|
|
return
|
|
|
|
if not self.isCanceled() and self.get_children:
|
|
|
|
children_xml = PF.GetAllPlexChildren(self.plex_id)
|
2017-04-03 01:02:41 +10:00
|
|
|
try:
|
2018-10-20 23:49:04 +11:00
|
|
|
children_xml[0].attrib
|
|
|
|
except (TypeError, IndexError, AttributeError):
|
|
|
|
LOG.error('Could not get children for Plex id %s',
|
|
|
|
self.plex_id)
|
|
|
|
else:
|
2018-10-26 03:14:35 +11:00
|
|
|
item['children'] = children_xml
|
|
|
|
self.queue.put(item)
|