MCPcopy
hub / github.com/iBaa/PlexConnect / getXMLFromMultiplePMS

Function getXMLFromMultiplePMS

PlexAPI.py:524–633  ·  view source on GitHub ↗
(ATV_udid, path, type, options={})

Source from the content-addressed store, hash-verified

522 XML
523"""
524def getXMLFromMultiplePMS(ATV_udid, path, type, options={}):
525 queue = Queue.Queue()
526 threads = []
527
528 root = etree.Element("MediaConverter")
529 root.set('friendlyName', type+' Servers')
530
531 for uuid in g_PMS.get(ATV_udid, {}):
532 if (type=='all' and getPMSProperty(ATV_udid, uuid, 'name')!='plex.tv') or \
533 (type=='owned' and getPMSProperty(ATV_udid, uuid, 'owned')=='1') or \
534 (type=='shared' and getPMSProperty(ATV_udid, uuid, 'owned')=='0') or \
535 (type=='local' and getPMSProperty(ATV_udid, uuid, 'local')=='1') or \
536 (type=='remote' and getPMSProperty(ATV_udid, uuid, 'local')=='0'):
537 Server = etree.SubElement(root, 'Server') # create "Server" node
538 Server.set('name', getPMSProperty(ATV_udid, uuid, 'name'))
539 Server.set('address', getPMSProperty(ATV_udid, uuid, 'ip'))
540 Server.set('port', getPMSProperty(ATV_udid, uuid, 'port'))
541 Server.set('baseURL', getPMSProperty(ATV_udid, uuid, 'baseURL'))
542 Server.set('local', getPMSProperty(ATV_udid, uuid, 'local'))
543 Server.set('owned', getPMSProperty(ATV_udid, uuid, 'owned'))
544
545 baseURL = getPMSProperty(ATV_udid, uuid, 'baseURL')
546 token = getPMSProperty(ATV_udid, uuid, 'accesstoken')
547 PMS_mark = 'PMS(' + getPMSProperty(ATV_udid, uuid, 'address') + ')'
548
549 Server.set('searchKey', PMS_mark + getURL('', '', '/Search/Entry.xml'))
550
551 # request XMLs, one thread for each
552 PMS = { 'baseURL':baseURL, 'path':path, 'options':options, 'token':token, \
553 'data': {'uuid': uuid, 'Server': Server} }
554 t = Thread(target=getXMLFromPMSToQueue, args=(PMS, queue))
555 t.start()
556 threads.append(t)
557
558 # wait for requests being answered
559 for t in threads:
560 t.join()
561
562 # add new data to root XML, individual Server
563 while not queue.empty():
564 (data, XML) = queue.get()
565 uuid = data['uuid']
566 Server = data['Server']
567
568 baseURL = getPMSProperty(ATV_udid, uuid, 'baseURL')
569 token = getPMSProperty(ATV_udid, uuid, 'accesstoken')
570 PMS_mark = 'PMS(' + getPMSProperty(ATV_udid, uuid, 'address') + ')'
571
572 if XML==False:
573 Server.set('size', '0')
574 else:
575 Server.set('size', XML.getroot().get('size', '0'))
576
577 for Dir in XML.getiterator('Directory'): # copy "Directory" content, add PMS to links
578
579 if Dir.get('key') is not None and (Dir.get('agent') is not None or Dir.get('share') is not None):
580 key = Dir.get('key') # absolute path
581 Dir.set('key', PMS_mark + getURL('', path, key))

Callers

nothing calls this directly

Calls 3

getPMSPropertyFunction · 0.85
getURLFunction · 0.85
dprintFunction · 0.85

Tested by

no test coverage detected