Fix getting pms_url when multiple connections published

* Fixes bug grabbing the wrong pms_url when multiple local/remote
connections are published to plex.tv
* This tries to find the connection with the matching address first,
otherwise grabs the first valid local/remote connection (prior
behaviour)
This commit is contained in:
JonnyWong16 2016-04-12 22:52:08 -07:00
parent 6a72923182
commit 2f5f0ba1e1
2 changed files with 23 additions and 23 deletions

View file

@ -39,7 +39,6 @@ function showMsg(msg,loader,timeout,ms,error) {
} }
if (error) { if (error) {
feedback.css("background-color", "rgba(255,0,0,0.5)"); feedback.css("background-color", "rgba(255,0,0,0.5)");
console.log('is error');
} }
$(feedback).html(message); $(feedback).html(message);
feedback.fadeIn(); feedback.fadeIn();
@ -49,6 +48,7 @@ function showMsg(msg,loader,timeout,ms,error) {
message.fadeOut(function(){ message.fadeOut(function(){
$(this).remove(); $(this).remove();
feedback.fadeOut(); feedback.fadeOut();
feedback.css("background-color", "");
}); });
},ms); },ms);
} }

View file

@ -71,37 +71,37 @@ def get_real_pms_url():
if plexpy.CONFIG.PMS_SSL: if plexpy.CONFIG.PMS_SSL:
result = PlexTV().get_server_urls(include_https=True) result = PlexTV().get_server_urls(include_https=True)
process_urls = True
elif plexpy.CONFIG.PMS_IS_REMOTE:
result = PlexTV().get_server_urls(include_https=False)
process_urls = True
else: else:
result = PlexTV().get_server_urls(include_https=False) result = PlexTV().get_server_urls(include_https=False)
process_urls = False
if process_urls:
found_url = False
# Only need to retrieve PMS_URL if using SSL
if plexpy.CONFIG.PMS_SSL:
if result: if result:
for item in result: if plexpy.CONFIG.PMS_IS_REMOTE:
if plexpy.CONFIG.PMS_IS_REMOTE and item['local'] == '0': # Get all remote connections
found_url = True connections = [c for c in result if c['local'] == '0' and 'plex.direct' in c['uri']]
plexpy.CONFIG.__setattr__('PMS_URL', item['uri']) else:
plexpy.CONFIG.write() # Get all local connections
logger.info(u"PlexPy PlexTV :: Server URL retrieved.") connections = [c for c in result if c['local'] == '1' and 'plex.direct' in c['uri']]
if not plexpy.CONFIG.PMS_IS_REMOTE and item['local'] == '1' and 'plex.direct' in item['uri']:
found_url = True if connections:
plexpy.CONFIG.__setattr__('PMS_URL', item['uri']) # Get connection with matching address, otherwise return first connection
conn = next((c for c in connections if c['address'] == plexpy.CONFIG.PMS_IP), connections[0])
plexpy.CONFIG.__setattr__('PMS_URL', conn['uri'])
plexpy.CONFIG.write() plexpy.CONFIG.write()
logger.info(u"PlexPy PlexTV :: Server URL retrieved.") logger.info(u"PlexPy PlexTV :: Server URL retrieved.")
if not found_url: # get_server_urls() failed or PMS_URL not found, fallback url doesn't use SSL
if not plexpy.CONFIG.PMS_URL:
plexpy.CONFIG.__setattr__('PMS_URL', fallback_url) plexpy.CONFIG.__setattr__('PMS_URL', fallback_url)
plexpy.CONFIG.write() plexpy.CONFIG.write()
logger.warn(u"PlexPy PlexTV :: Unable to retrieve server URLs. Using user-defined value.") logger.warn(u"PlexPy PlexTV :: Unable to retrieve server URLs. Using user-defined value without SSL.")
# Not using SSL, remote has no effect
else: else:
plexpy.CONFIG.__setattr__('PMS_URL', fallback_url) plexpy.CONFIG.__setattr__('PMS_URL', fallback_url)
plexpy.CONFIG.write() plexpy.CONFIG.write()
logger.info(u"PlexPy PlexTV :: Using user-defined URL.")
class PlexTV(object): class PlexTV(object):