diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 37564591..fcca9d65 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -650,12 +650,20 @@
- +
- + @@ -738,6 +746,7 @@

+ @@ -2053,7 +2062,7 @@ $(document).ready(function() { } }); - var $select_pms = $('#pms_ip').selectize({ + var $select_pms = $('#pms_ip_selectize').selectize({ createOnBlur: true, openOnFocus: true, maxItems: 1, @@ -2064,13 +2073,19 @@ $(document).ready(function() { dropdownParent: '#selectize-pms-ip-container', render: { item: function (item, escape) { + if (!item.label) { + $.extend(item, + $(this.revertSettings.$children) + .filter('[value=' + item.value + ']').data() + ); + } var label = item.label || item.value; - var caption = item.label ? item.value : null; - return '
' + '' + escape(label) + '' + @@ -2080,11 +2095,11 @@ $(document).ready(function() { option: function (item, escape) { var label = item.label || item.value; var caption = item.label ? item.value : null; - return '
' + escape(label) + @@ -2095,15 +2110,24 @@ $(document).ready(function() { create: function(input) { return {label: '', value: input}; }, + onInitialize: function () { + var s = this; + this.revertSettings.$children.each(function () { + $.extend(s.options[this.value], $(this).data()); + }); + }, onChange: function (item) { var pms_ip_selected = this.getItem(item)[0]; var identifier = $(pms_ip_selected).data('identifier'); + var ip = $(pms_ip_selected).data('ip'); var port = $(pms_ip_selected).data('port'); var local = $(pms_ip_selected).data('local'); var ssl = $(pms_ip_selected).data('ssl'); var is_cloud = $(pms_ip_selected).data('is_cloud'); + var value = $(pms_ip_selected).data('value'); $("#pms_identifier").val(identifier !== 'undefined' ? identifier : ''); + $('#pms_ip').val(ip !== 'undefined' ? ip : value); $('#pms_port').val(port !== 'undefined' ? port : 32400); $('#pms_is_remote_checkbox').prop('checked', (local !== 'undefined' && local === 0)); $('#pms_is_remote').val(local !== 'undefined' && local === 0 ? 1 : 0); @@ -2128,9 +2152,10 @@ $(document).ready(function() { }, success: function (result) { if (result) { - var existing_value = $('#pms_ip').val(); + var existing_ip = $('#pms_ip').val(); + var existing_port = $('#pms_port').val(); result.forEach(function (item) { - if (item.value === existing_value) { + if (item.ip === existing_ip && item.port === existing_port) { select_pms.updateOption(item.value, item); } else { select_pms.addOption(item); diff --git a/data/interfaces/default/welcome.html b/data/interfaces/default/welcome.html index 57186c37..ade397d2 100644 --- a/data/interfaces/default/welcome.html +++ b/data/interfaces/default/welcome.html @@ -86,11 +86,19 @@

- +
- +
@@ -120,6 +128,7 @@
+ Verify @@ -314,7 +323,7 @@ $(document).ready(function() { } }); - var $select_pms = $('#pms_ip').selectize({ + var $select_pms = $('#pms_ip_selectize').selectize({ createOnBlur: true, openOnFocus: true, maxItems: 1, @@ -324,13 +333,19 @@ $(document).ready(function() { inputClass: 'form-control selectize-input', render: { item: function (item, escape) { + if (!item.label) { + $.extend(item, + $(this.revertSettings.$children) + .filter('[value=' + item.value + ']').data() + ); + } var label = item.label || item.value; - var caption = item.label ? item.value : null; - return '
' + '' + escape(label) + '' + @@ -340,11 +355,11 @@ $(document).ready(function() { option: function (item, escape) { var label = item.label || item.value; var caption = item.label ? item.value : null; - return '
' + escape(label) + @@ -355,18 +370,27 @@ $(document).ready(function() { create: function(input) { return {label: '', value: input}; }, + onInitialize: function () { + var s = this; + this.revertSettings.$children.each(function () { + $.extend(s.options[this.value], $(this).data()); + }); + }, onChange: function (item) { var pms_ip_selected = this.getItem(item)[0]; var identifier = $(pms_ip_selected).data('identifier'); + var ip = $(pms_ip_selected).data('ip'); var port = $(pms_ip_selected).data('port'); var local = $(pms_ip_selected).data('local'); var ssl = $(pms_ip_selected).data('ssl'); var is_cloud = $(pms_ip_selected).data('is_cloud'); + var value = $(pms_ip_selected).data('value'); $("#pms_valid").val(identifier !== 'undefined' ? 'valid' : ''); $("#pms-verify-status").html(identifier !== 'undefined' ? '  Server found!' : '').fadeIn('fast'); $("#pms_identifier").val(identifier !== 'undefined' ? identifier : ''); + $('#pms_ip').val(ip !== 'undefined' ? ip : value); $('#pms_port').val(port !== 'undefined' ? port : 32400); $('#pms_is_remote_checkbox').prop('checked', (local !== 'undefined' && local === 0)); $('#pms_is_remote').val(local !== 'undefined' && local === 0 ? 1 : 0); @@ -399,9 +423,10 @@ $(document).ready(function() { }, success: function (result) { if (result) { - var existing_value = $('#pms_ip').val(); + var existing_ip = $('#pms_ip').val(); + var existing_port = $('#pms_port').val(); result.forEach(function (item) { - if (item.value === existing_value) { + if (item.ip === existing_ip && item.port === existing_port) { select_pms.updateOption(item.value, item); } else { select_pms.addOption(item); diff --git a/plexpy/plextv.py b/plexpy/plextv.py index 0d03d7d9..9faf4459 100644 --- a/plexpy/plextv.py +++ b/plexpy/plextv.py @@ -685,6 +685,23 @@ class PlexTV(object): def discover(self, include_cloud=True, all_servers=False): """ Query plex for all servers online. Returns the ones you own in a selectize format """ + + # Try to discover localhost server + pms_connect = pmsconnect.PmsConnect(url='http://127.0.0.1:32400') + pms_connect.request_handler.timeout = 1 + identity = pms_connect.get_server_identity(log=False) + local_machine_identifier = identity.get('machine_identifier') + local_server = {'httpsRequired': '0', + 'clientIdentifier': local_machine_identifier, + 'label': 'Local', + 'ip': '127.0.0.1', + 'port': '32400', + 'uri': 'http://127.0.0.1:32400', + 'local': '1', + 'value': '127.0.0.1:32400', + 'is_cloud': False + } + servers = self.get_plextv_resources(include_https=True, output_format='xml') clean_servers = [] @@ -704,8 +721,8 @@ class PlexTV(object): for d in devices: if helpers.get_xml_attr(d, 'presence') == '1' and \ - helpers.get_xml_attr(d, 'owned') == '1' and \ - helpers.get_xml_attr(d, 'provides') == 'server': + helpers.get_xml_attr(d, 'owned') == '1' and \ + helpers.get_xml_attr(d, 'provides') == 'server': is_cloud = (helpers.get_xml_attr(d, 'platform').lower() == 'cloud') if not include_cloud and is_cloud: @@ -717,14 +734,20 @@ class PlexTV(object): if not all_servers: # If this is a remote server don't show any local IPs. if helpers.get_xml_attr(d, 'publicAddressMatches') == '0' and \ - helpers.get_xml_attr(c, 'local') == '1': + helpers.get_xml_attr(c, 'local') == '1': continue # If this is a local server don't show any remote IPs. if helpers.get_xml_attr(d, 'publicAddressMatches') == '1' and \ - helpers.get_xml_attr(c, 'local') == '0': + helpers.get_xml_attr(c, 'local') == '0': continue + if helpers.get_xml_attr(d, 'clientIdentifier') == local_machine_identifier: + local_server['httpsRequired'] = helpers.get_xml_attr(d, 'httpsRequired') + local_server['label'] = helpers.get_xml_attr(d, 'name') + clean_servers.append(local_server) + local_machine_identifier = None + server = {'httpsRequired': '1' if is_cloud else helpers.get_xml_attr(d, 'httpsRequired'), 'clientIdentifier': helpers.get_xml_attr(d, 'clientIdentifier'), 'label': helpers.get_xml_attr(d, 'name'), @@ -732,11 +755,16 @@ class PlexTV(object): 'port': helpers.get_xml_attr(c, 'port'), 'uri': helpers.get_xml_attr(c, 'uri'), 'local': helpers.get_xml_attr(c, 'local'), - 'value': helpers.get_xml_attr(c, 'address'), + 'value': helpers.get_xml_attr(c, 'address') + ':' + helpers.get_xml_attr(c, 'port'), 'is_cloud': is_cloud } clean_servers.append(server) + if local_machine_identifier: + clean_servers.append(local_server) + + clean_servers.sort(key=lambda s: (s['label'], -int(s['local']), s['ip'])) + return clean_servers def get_plex_downloads(self): diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 3c589e27..552a8fdf 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -2193,7 +2193,7 @@ class PmsConnect(object): return server_info - def get_server_identity(self): + def get_server_identity(self, log=True): """ Return the local machine identity. @@ -2204,7 +2204,8 @@ class PmsConnect(object): try: xml_head = identity.getElementsByTagName('MediaContainer') except Exception as e: - logger.warn(u"Tautulli Pmsconnect :: Unable to parse XML for get_local_server_identity: %s." % e) + if log: + logger.warn(u"Tautulli Pmsconnect :: Unable to parse XML for get_local_server_identity: %s." % e) return {} server_identity = {} diff --git a/plexpy/webserve.py b/plexpy/webserve.py index d893201e..35ce5e67 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -110,6 +110,7 @@ class WebInterface(object): "pms_is_cloud": plexpy.CONFIG.PMS_IS_CLOUD, "pms_token": plexpy.CONFIG.PMS_TOKEN, "pms_uuid": plexpy.CONFIG.PMS_UUID, + "pms_name": plexpy.CONFIG.PMS_NAME, "logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL } @@ -2802,6 +2803,7 @@ class WebInterface(object): "pms_url_manual": checked(plexpy.CONFIG.PMS_URL_MANUAL), "pms_uuid": plexpy.CONFIG.PMS_UUID, "pms_web_url": plexpy.CONFIG.PMS_WEB_URL, + "pms_name": plexpy.CONFIG.PMS_NAME, "date_format": plexpy.CONFIG.DATE_FORMAT, "time_format": plexpy.CONFIG.TIME_FORMAT, "week_start_monday": checked(plexpy.CONFIG.WEEK_START_MONDAY),