1
0
mirror of https://github.com/fHDHR/fHDHR_NextPVR.git synced 2025-12-06 03:16:58 -05:00

Improve Detection of ffmpeg/vlc application paths

This commit is contained in:
deathbybandaid 2021-01-31 15:24:19 -05:00
parent 884d4b6e27
commit ab51ea02a1
6 changed files with 108 additions and 22 deletions

View File

@ -85,7 +85,7 @@ class Tuner():
def get_stream(self, stream_args, tuner):
stream = Stream(self.fhdhr, stream_args, tuner)
return stream.get()
return stream
def set_status(self, stream_args):
if self.status["status"] != "Active":

View File

@ -132,7 +132,15 @@ class Tuners():
tuner.set_status(stream_args)
session["tuner_used"] = tunernum
return Response(stream_with_context(tuner.get_stream(stream_args, tuner)), mimetype=stream_args["content_type"])
try:
stream = tuner.get_stream(stream_args, tuner)
except TunerError as e:
response.headers["X-fHDHR-Error"] = str(e)
self.fhdhr.logger.error(response.headers["X-fHDHR-Error"])
tuner.close()
abort(response)
return Response(stream_with_context(stream.get()), mimetype=stream_args["content_type"])
elif method == "close":

View File

@ -1,23 +1,59 @@
import os
import sys
import subprocess
from fHDHR.exceptions import TunerError
def setup(plugin):
try:
ffmpeg_command = [plugin.config.dict["ffmpeg"]["path"],
"-version",
"pipe:stdout"
]
ffmpeg_proc = subprocess.Popen(ffmpeg_command, stdout=subprocess.PIPE)
ffmpeg_version = ffmpeg_proc.stdout.read()
# Check config for ffmpeg path
ffmpeg_path = None
if plugin.config.dict["ffmpeg"]["path"]:
# verify path is valid
if os.path.isfile(plugin.config.dict["ffmpeg"]["path"]):
ffmpeg_path = plugin.config.dict["ffmpeg"]["path"]
else:
plugin.logger.warning("Failed to find ffmpeg at %s." % plugin.config.dict["ffmpeg"]["path"])
if not ffmpeg_path:
plugin.logger.info("Attempting to find ffmpeg in PATH.")
if plugin.config.internal["versions"]["Operating System"]["version"] in ["Linux", "Darwin"]:
find_ffmpeg_command = ["which", "ffmpeg"]
elif plugin.config.internal["versions"]["Operating System"]["version"] in ["Windows"]:
find_ffmpeg_command = ["where", "ffmpeg"]
ffmpeg_proc = subprocess.Popen(find_ffmpeg_command, stdout=subprocess.PIPE)
ffmpeg_path = ffmpeg_proc.stdout.read().decode().strip("\n")
ffmpeg_proc.terminate()
ffmpeg_proc.communicate()
ffmpeg_proc.kill()
ffmpeg_version = ffmpeg_version.decode().split("version ")[1].split(" ")[0]
except FileNotFoundError:
if not ffmpeg_path:
ffmpeg_path = None
elif ffmpeg_path.isspace():
ffmpeg_path = None
if ffmpeg_path:
plugin.config.dict["ffmpeg"]["path"] = ffmpeg_path
if ffmpeg_path:
ffmpeg_command = [ffmpeg_path, "-version", "pipe:stdout"]
try:
ffmpeg_proc = subprocess.Popen(ffmpeg_command, stdout=subprocess.PIPE)
ffmpeg_version = ffmpeg_proc.stdout.read().decode().split("version ")[1].split(" ")[0]
except FileNotFoundError:
ffmpeg_version = None
except PermissionError:
ffmpeg_version = None
finally:
ffmpeg_proc.terminate()
ffmpeg_proc.communicate()
ffmpeg_proc.kill()
if not ffmpeg_version:
ffmpeg_version = "Missing"
plugin.logger.warning("Failed to find ffmpeg.")
plugin.config.register_version("ffmpeg", ffmpeg_version, "env")
@ -29,6 +65,9 @@ class Plugin_OBJ():
self.stream_args = stream_args
self.tuner = tuner
if self.plugin_utils.config.internal["versions"]["ffmpeg"] == "Missing":
raise TunerError("806 - Tune Failed: FFMPEG Missing")
self.bytes_per_read = int(plugin_utils.config.dict["streaming"]["bytes_per_read"])
self.ffmpeg_command = self.ffmpeg_command_assemble(stream_args)

View File

@ -1,7 +1,7 @@
{
"ffmpeg":{
"path":{
"value": "ffmpeg",
"value": "none",
"config_file": true,
"config_web": true
}

View File

@ -1,23 +1,59 @@
import os
import sys
import subprocess
from fHDHR.exceptions import TunerError
def setup(plugin):
try:
vlc_command = [plugin.config.dict["vlc"]["path"],
"--version",
"pipe:stdout"
]
vlc_proc = subprocess.Popen(vlc_command, stdout=subprocess.PIPE)
vlc_version = vlc_proc.stdout.read()
# Check config for vlc path
vlc_path = None
if plugin.config.dict["vlc"]["path"]:
# verify path is valid
if os.path.isfile(plugin.config.dict["vlc"]["path"]):
vlc_path = plugin.config.dict["vlc"]["path"]
else:
plugin.logger.warning("Failed to find vlc at %s." % plugin.config.dict["vlc"]["path"])
if not vlc_path:
plugin.logger.info("Attempting to find vlc in PATH.")
if plugin.config.internal["versions"]["Operating System"]["version"] in ["Linux", "Darwin"]:
find_vlc_command = ["which", "vlc"]
elif plugin.config.internal["versions"]["Operating System"]["version"] in ["Windows"]:
find_vlc_command = ["where", "vlc"]
vlc_proc = subprocess.Popen(find_vlc_command, stdout=subprocess.PIPE)
vlc_path = vlc_proc.stdout.read().decode().strip("\n")
vlc_proc.terminate()
vlc_proc.communicate()
vlc_proc.kill()
vlc_version = vlc_version.decode().split("version ")[1].split('\n')[0]
except FileNotFoundError:
if not vlc_path:
vlc_path = None
elif vlc_path.isspace():
vlc_path = None
if vlc_path:
plugin.config.dict["vlc"]["path"] = vlc_path
if vlc_path:
vlc_command = [vlc_path, "--version", "pipe:stdout"]
try:
vlc_proc = subprocess.Popen(vlc_command, stdout=subprocess.PIPE)
vlc_version = vlc_proc.stdout.read().decode().split("version ")[1].split('\n')[0]
except FileNotFoundError:
vlc_version = None
except PermissionError:
vlc_version = None
finally:
vlc_proc.terminate()
vlc_proc.communicate()
vlc_proc.kill()
if not vlc_version:
vlc_version = "Missing"
plugin.logger.warning("Failed to find vlc.")
plugin.config.register_version("vlc", vlc_version, "env")
@ -29,6 +65,9 @@ class Plugin_OBJ():
self.stream_args = stream_args
self.tuner = tuner
if self.plugin_utils.config.internal["versions"]["vlc"] == "Missing":
raise TunerError("806 - Tune Failed: VLC Missing")
self.bytes_per_read = int(self.plugin_utils.config.dict["streaming"]["bytes_per_read"])
self.vlc_command = self.vlc_command_assemble(stream_args)

View File

@ -1,7 +1,7 @@
{
"vlc":{
"path":{
"value": "cvlc",
"value": "none",
"config_file": true,
"config_web": true
}