From 55d10ca6fd992ae76e11a92d920a16c59fedf23f Mon Sep 17 00:00:00 2001 From: Matthew Woodward Date: Wed, 10 Apr 2024 16:43:38 -0400 Subject: [PATCH 1/2] Add more descriptive upnp error --- main.js | 49 +++++++++++++++++++++++++++++++++++++++++++------ mpvDLNA.py | 15 +++++++++++---- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/main.js b/main.js index 5b62dfb..ee08f00 100644 --- a/main.js +++ b/main.js @@ -91,37 +91,74 @@ var DLNA_Browser = function(options) { // Determine how to call python this.python = null; var versions = ["python", "python3"]; + var working_python = [] + var upnp_errored = [] // If the .conf file specifies an option, test it first if (options.python_version) { versions.unshift(options.python_version); } - // Test each option + // Test --version for each python call option for (var i = 0; i < versions.length; i++) { var result = mp.command_native({ name: "subprocess", playback_only: false, capture_stdout: true, capture_stderr: true, - args : [versions[i], mp.get_script_directory()+"/mpvDLNA.py", "-v"] + args : [versions[i], "--version"] }); + if (result.status != 0) { - mp.msg.debug("calling python as " + versions[i] + " errored with: " + result.stderr); + mp.msg.debug("calling python --version as " + versions[i] + " errored with: " + result.stderr); + continue; } else { - this.python = versions[i]; + working_python.push(versions[i]); + } + } + + // test mpvDLNA.py for each working python call + for (var i = 0; i < working_python.length; i++) { + var result = mp.command_native({ + name: "subprocess", + playback_only: false, + capture_stdout: true, + capture_stderr: true, + args : [working_python[i], mp.get_script_directory()+"/mpvDLNA.py", "-v"] + }); + + if (result.status != 0) { + mp.msg.debug("calling mpvDLNA.py using " + working_python[i] + " errored with: " + result.stderr); + } else if (result.stdout.search("upnp import failed") != -1) { + upnp_errored.push(working_python[i]); + mp.msg.debug("python call: " + working_python[i] + " does not have upnp installed correctly "); + } else { + this.python = working_python[i]; + mp.msg.debug("selecting '" + working_python[i] + "' for python call") break; } } // None of the options worked, throw an error - if (this.python == null) { + if (working_python.length == 0) { throw new Error("Unable to find a correctly configured python call: \n \ in the following options: " + versions + "\n Please add the name of your python install to the .conf file \n \ using the format: python_version=python \n \ or run mpv with the --msg-level=mpvDLNA=trace argument to see the errors"); + + // Some of the options worked but couldn't run mpvDLNA.py + } else if (this.python == null){ + // upnpClient is not installed correctly + if (upnp_errored.length > 0) { + throw new Error("The following python calls exist but do not have upnpClient installed properly: " + versions); + + // Some other error occured + } else { + throw new Error("The following python calls exist but failed to run mpvDLNA: " + versions + + "\n Please run mpv with the --msg-level=mpvDLNA=trace argument to see the errors"); + } } // How long to spend searching for DLNA servers @@ -971,7 +1008,7 @@ DLNA_Browser.prototype.command_wake = function(args) { if (sp[0] == "packet sent") { this.typing_output = "Packet Sent"; - } else if (sp[0] == "import failed"){ + } else if (sp[0] == "wakeonlan import failed"){ this.typing_output = Ass.color("FF0000", true) + "wakeonlan python package not installed"; } else { this.typing_output = Ass.color("FF0000", true) + "unspecified error"; diff --git a/mpvDLNA.py b/mpvDLNA.py index 59ca74f..305eaad 100644 --- a/mpvDLNA.py +++ b/mpvDLNA.py @@ -1,7 +1,11 @@ import sys -import upnpclient -from lxml import etree +# Try to import upnp +upnp = True +try: + import upnpclient +except ImportError as error: + upnp = False # Try to import wake on lan wol = True @@ -10,6 +14,7 @@ except ImportError as error: wol = False +from lxml import etree import logging # important information is passed through stdout so we need to supress # the output of the upnp client module @@ -26,7 +31,7 @@ def wake(mac): except: print("send failed") else: - print("import failed") + print("wakeonlan import failed") def info(url, id, count): device = upnpclient.Device(url) @@ -104,7 +109,9 @@ def help(): if len(sys.argv) == 2: if sys.argv[1] == "-v" or sys.argv[1] == "--version": - print("mpvDLNA.py Plugin Version 2.0.0") + print("mpvDLNA.py Plugin Version 2.1.0") + if not upnp: + print("upnp import failed") else: help() elif len(sys.argv) == 3: From f199a93050dce2f0099c14390654b290a5f23281 Mon Sep 17 00:00:00 2001 From: Matthew Woodward Date: Wed, 10 Apr 2024 16:45:55 -0400 Subject: [PATCH 2/2] Update version number --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index ee08f00..3b38f60 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,4 @@ -// mpvDLNA 3.3.1 +// mpvDLNA 3.4.1 "use strict";