(ATV_udid, authtoken)
| 309 | -> by design this leads to numerous threads ending in URLErrors like <timed out> or <Connection refused> |
| 310 | """ |
| 311 | def getPMSListFromMyPlex(ATV_udid, authtoken): |
| 312 | dprint(__name__, 0, "***") |
| 313 | dprint(__name__, 0, "poke plex.tv - request Plex Media Server list") |
| 314 | dprint(__name__, 0, "***") |
| 315 | |
| 316 | XML = getXMLFromPMS('https://plex.tv', '/api/resources?includeHttps=1', {}, authtoken) |
| 317 | |
| 318 | if XML==False: |
| 319 | pass # no data from MyPlex |
| 320 | else: |
| 321 | queue = Queue.Queue() |
| 322 | threads = [] |
| 323 | PMSsPoked = 0 |
| 324 | |
| 325 | for Dir in XML.getiterator('Device'): |
| 326 | if Dir.get('product','') == "Plex Media Server" and Dir.get('provides','') == "server": |
| 327 | uuid = Dir.get('clientIdentifier') |
| 328 | name = Dir.get('name') |
| 329 | token = Dir.get('accessToken', authtoken) |
| 330 | owned = Dir.get('owned', '0') |
| 331 | |
| 332 | if Dir.find('Connection') == None: |
| 333 | continue # no valid connection - skip |
| 334 | |
| 335 | PMSsPoked +=1 |
| 336 | |
| 337 | # multiple connection possible - poke either one, fastest response wins |
| 338 | for Con in Dir.getiterator('Connection'): |
| 339 | protocol = Con.get('protocol') |
| 340 | ip = Con.get('address') |
| 341 | port = Con.get('port') |
| 342 | uri = Con.get('uri') |
| 343 | local = Con.get('local') |
| 344 | |
| 345 | # change protocol and uri if in local |
| 346 | if local == "1": |
| 347 | protocol = "http" |
| 348 | uri = protocol + "://" + ip + ":" + port |
| 349 | |
| 350 | # poke PMS, own thread for each poke |
| 351 | PMSInfo = { 'uuid': uuid, 'name': name, 'token': token, 'owned': owned, 'local': local, \ |
| 352 | 'protocol': protocol, 'ip': ip, 'port': port, 'uri': uri } |
| 353 | PMS = { 'baseURL': uri, 'path': '/', 'options': None, 'token': token, \ |
| 354 | 'data': PMSInfo } |
| 355 | dprint(__name__, 0, "poke {0} ({1}) at {2}", name, uuid, uri) |
| 356 | t = Thread(target=getXMLFromPMSToQueue, args=(PMS, queue)) |
| 357 | t.start() |
| 358 | threads.append(t) |
| 359 | |
| 360 | # wait for requests being answered |
| 361 | # - either all communication threads done |
| 362 | # - or at least one response received from every PMS (early exit) |
| 363 | ThreadsAlive = -1 |
| 364 | PMSsCnt = 0 |
| 365 | while ThreadsAlive != 0 and PMSsPoked != PMSsCnt: |
| 366 | # check for "living" threads - basically a manual t.join() |
| 367 | ThreadsAlive = 0 |
| 368 | for t in threads: |
no test coverage detected