Fallback connection if plex.direct does not resolve

- Fixes #472
- Partially fixes #478
This commit is contained in:
croneter 2018-05-18 19:31:43 +02:00
parent 5a993a2bf0
commit 0a7752e392

View file

@ -20,6 +20,7 @@ LOG = getLogger("PLEX." + __name__)
CONTAINERSIZE = int(settings('limitindex')) CONTAINERSIZE = int(settings('limitindex'))
REGEX_PLEX_KEY = re_compile(r'''/(.+)/(\d+)$''') REGEX_PLEX_KEY = re_compile(r'''/(.+)/(\d+)$''')
REGEX_PLEX_DIRECT = re_compile(r'''\.plex\.direct:\d+$''')
# For discovery of PMS in the local LAN # For discovery of PMS in the local LAN
PLEX_GDM_IP = '239.0.0.250' # multicast to PMS PLEX_GDM_IP = '239.0.0.250' # multicast to PMS
@ -405,8 +406,15 @@ def _pms_list_from_plex_tv(token):
def _poke_pms(pms, queue): def _poke_pms(pms, queue):
data = pms['connections'][0].attrib data = pms['connections'][0].attrib
url = data['uri'] url = data['uri']
if url.count(':') == 1: if data['local'] == '1' and REGEX_PLEX_DIRECT.findall(url):
url = '%s:%s' % (url, data['port']) # In case DNS resolve of plex.direct does not work, append a new
# connection that will directly access the local IP (e.g. internet down)
conn = deepcopy(pms['connections'][0])
# Overwrite plex.direct
conn.attrib['uri'] = '%s://%s:%s' % (data['protocol'],
data['address'],
data['port'])
pms['connections'].insert(1, conn)
protocol, address, port = url.split(':', 2) protocol, address, port = url.split(':', 2)
address = address.replace('/', '') address = address.replace('/', '')
xml = DU().downloadUrl('%s/identity' % url, xml = DU().downloadUrl('%s/identity' % url,