Exemplo n.º 1
0
    def load_versions(self):

        self.register_version("fHDHR", fHDHR_VERSION, "fHDHR")
        self.register_version("fHDHR_web", self.fHDHR_web.fHDHR_web_VERSION,
                              "fHDHR")

        self.register_version("Python", sys.version, "env")

        opersystem = platform.system()
        self.register_version("Operating System", opersystem, "env")
        if opersystem in ["Linux", "Darwin"]:
            # Linux/Mac
            if os.getuid() == 0 or os.geteuid() == 0:
                print('Warning: Do not run fHDHR with root privileges.')
        elif opersystem in ["Windows"]:
            # Windows
            if os.environ.get("USERNAME") == "Administrator":
                print('Warning: Do not run fHDHR as Administrator.')
        else:
            print("Uncommon Operating System, use at your own risk.")

        isdocker = is_docker()
        self.register_version("Docker", isdocker, "env")
Exemplo n.º 2
0
    def config_verification(self):

        if self.dict["main"]["required"]:
            required_missing = []
            if isinstance(self.dict["main"]["required"], str):
                self.dict["main"]["required"] = [self.dict["main"]["required"]]
            if len(self.dict["main"]["required"]):
                for req_item in self.dict["main"]["required"]:
                    req_section = req_item.split("/")[0]
                    req_key = req_item.split("/")[1]
                    if not self.dict[req_section][req_key]:
                        required_missing.append(req_item)
            if len(required_missing):
                raise fHDHR.exceptions.ConfigurationError(
                    "Required configuration options missing: " +
                    ", ".join(required_missing))

        self.dict["origin"] = self.dict.pop(self.dict["main"]["dictpopname"])

        if isinstance(self.dict["main"]["valid_epg_methods"], str):
            self.dict["main"]["valid_epg_methods"] = [
                self.dict["main"]["valid_epg_methods"]
            ]

        if self.dict["epg"]["method"] and self.dict["epg"]["method"] not in [
                "None"
        ]:
            if isinstance(self.dict["epg"]["method"], str):
                self.dict["epg"]["method"] = [self.dict["epg"]["method"]]
            epg_methods = []
            for epg_method in self.dict["epg"]["method"]:
                if epg_method == self.dict["main"][
                        "dictpopname"] or epg_method == "origin":
                    epg_methods.append("origin")
                elif epg_method in ["None"]:
                    raise fHDHR.exceptions.ConfigurationError(
                        "Invalid EPG Method. Exiting...")
                elif epg_method in self.dict["main"]["valid_epg_methods"]:
                    epg_methods.append(epg_method)
                else:
                    raise fHDHR.exceptions.ConfigurationError(
                        "Invalid EPG Method. Exiting...")
        self.dict["epg"]["def_method"] = self.dict["epg"]["method"][0]

        # generate UUID here for when we are not using docker
        if not self.dict["main"]["uuid"]:
            # from https://pynative.com/python-generate-random-string/
            # create a string that wouldn't be a real device uuid for
            self.dict["main"]["uuid"] = ''.join(
                random.choice("hijklmnopqrstuvwxyz") for i in range(8))
            self.write('main', 'uuid', self.dict["main"]["uuid"])

        if self.dict["main"]["cache_dir"]:
            if not pathlib.Path(self.dict["main"]["cache_dir"]).is_dir():
                raise fHDHR.exceptions.ConfigurationError(
                    "Invalid Cache Directory. Exiting...")
            self.dict["filedir"]["cache_dir"] = pathlib.Path(
                self.dict["main"]["cache_dir"])
        cache_dir = self.dict["filedir"]["cache_dir"]

        logs_dir = pathlib.Path(cache_dir).joinpath('logs')
        self.dict["filedir"]["logs_dir"] = logs_dir
        if not logs_dir.is_dir():
            logs_dir.mkdir()

        self.dict["database"]["path"] = pathlib.Path(cache_dir).joinpath(
            'fhdhr.db')

        for epg_method in self.dict["main"]["valid_epg_methods"]:
            if epg_method and epg_method != "None":
                epg_cache_dir = pathlib.Path(cache_dir).joinpath(epg_method)
                if not epg_cache_dir.is_dir():
                    epg_cache_dir.mkdir()
                if epg_method not in list(
                        self.dict["filedir"]["epg_cache"].keys()):
                    self.dict["filedir"]["epg_cache"][epg_method] = {}
                self.dict["filedir"]["epg_cache"][epg_method][
                    "top"] = epg_cache_dir
                epg_web_cache_dir = pathlib.Path(epg_cache_dir).joinpath(
                    "web_cache")
                if not epg_web_cache_dir.is_dir():
                    epg_web_cache_dir.mkdir()
                self.dict["filedir"]["epg_cache"][epg_method][
                    "web_cache"] = epg_web_cache_dir
                self.dict["filedir"]["epg_cache"][epg_method][
                    "epg_json"] = pathlib.Path(epg_cache_dir).joinpath(
                        'epg.json')

        if self.dict["fhdhr"]["stream_type"] not in [
                "direct", "ffmpeg", "vlc"
        ]:
            raise fHDHR.exceptions.ConfigurationError(
                "Invalid stream type. Exiting...")

        opersystem = platform.system()
        self.dict["main"]["opersystem"] = opersystem
        if opersystem in ["Linux", "Darwin"]:
            # Linux/Mac
            if os.getuid() == 0 or os.geteuid() == 0:
                print('Warning: Do not run fHDHR with root privileges.')
        elif opersystem in ["Windows"]:
            # Windows
            if os.environ.get("USERNAME") == "Administrator":
                print('Warning: Do not run fHDHR as Administrator.')
        else:
            print("Uncommon Operating System, use at your own risk.")

        isdocker = is_docker()
        self.dict["main"]["isdocker"] = isdocker

        if self.dict["fhdhr"]["stream_type"] == "ffmpeg":
            try:
                ffmpeg_command = [
                    self.dict["ffmpeg"]["ffmpeg_path"], "-version",
                    "pipe:stdout"
                ]

                ffmpeg_proc = subprocess.Popen(ffmpeg_command,
                                               stdout=subprocess.PIPE)
                ffmpeg_version = ffmpeg_proc.stdout.read()
                ffmpeg_proc.terminate()
                ffmpeg_proc.communicate()
                ffmpeg_version = ffmpeg_version.decode().split(
                    "version ")[1].split(" ")[0]
            except FileNotFoundError:
                ffmpeg_version = None
            self.dict["ffmpeg"]["version"] = ffmpeg_version
        else:
            self.dict["ffmpeg"]["version"] = "N/A"

        if self.dict["fhdhr"]["stream_type"] == "vlc":
            try:
                vlc_command = [
                    self.dict["vlc"]["vlc_path"], "--version", "pipe:stdout"
                ]

                vlc_proc = subprocess.Popen(vlc_command,
                                            stdout=subprocess.PIPE)
                vlc_version = vlc_proc.stdout.read()
                vlc_proc.terminate()
                vlc_proc.communicate()
                vlc_version = vlc_version.decode().split("version ")[1].split(
                    '\n')[0]
            except FileNotFoundError:
                vlc_version = None
            self.dict["vlc"]["version"] = vlc_version
        else:
            self.dict["vlc"]["version"] = "N/A"

        if not self.dict["fhdhr"]["discovery_address"] and self.dict["fhdhr"][
                "address"] != "0.0.0.0":
            self.dict["fhdhr"]["discovery_address"] = self.dict["fhdhr"][
                "address"]
        if not self.dict["fhdhr"]["discovery_address"] or self.dict["fhdhr"][
                "discovery_address"] == "0.0.0.0":
            self.dict["fhdhr"]["discovery_address"] = None
Exemplo n.º 3
0
    def load_versions(self):

        self.internal["versions"] = {}

        self.internal["versions"]["fHDHR"] = fHDHR_VERSION

        self.internal["versions"][
            "fHDHR_web"] = self.fHDHR_web.fHDHR_web_VERSION

        self.internal["versions"][
            self.origin.ORIGIN_NAME] = self.origin.ORIGIN_VERSION

        self.internal["versions"]["Python"] = sys.version

        opersystem = platform.system()
        self.internal["versions"]["Operating System"] = opersystem
        if opersystem in ["Linux", "Darwin"]:
            # Linux/Mac
            if os.getuid() == 0 or os.geteuid() == 0:
                print('Warning: Do not run fHDHR with root privileges.')
        elif opersystem in ["Windows"]:
            # Windows
            if os.environ.get("USERNAME") == "Administrator":
                print('Warning: Do not run fHDHR as Administrator.')
        else:
            print("Uncommon Operating System, use at your own risk.")

        isdocker = is_docker()
        self.internal["versions"]["Docker"] = isdocker

        if self.dict["fhdhr"]["stream_type"] == "ffmpeg":
            try:
                ffmpeg_command = [
                    self.dict["ffmpeg"]["path"], "-version", "pipe:stdout"
                ]

                ffmpeg_proc = subprocess.Popen(ffmpeg_command,
                                               stdout=subprocess.PIPE)
                ffmpeg_version = ffmpeg_proc.stdout.read()
                ffmpeg_proc.terminate()
                ffmpeg_proc.communicate()
                ffmpeg_version = ffmpeg_version.decode().split(
                    "version ")[1].split(" ")[0]
            except FileNotFoundError:
                ffmpeg_version = "Missing"
                print("Failed to find ffmpeg.")
            self.internal["versions"]["ffmpeg"] = ffmpeg_version

        if self.dict["fhdhr"]["stream_type"] == "vlc":
            try:
                vlc_command = [
                    self.dict["vlc"]["path"], "--version", "pipe:stdout"
                ]

                vlc_proc = subprocess.Popen(vlc_command,
                                            stdout=subprocess.PIPE)
                vlc_version = vlc_proc.stdout.read()
                vlc_proc.terminate()
                vlc_proc.communicate()
                vlc_version = vlc_version.decode().split("version ")[1].split(
                    '\n')[0]
            except FileNotFoundError:
                vlc_version = "Missing"
                print("Failed to find vlc.")
            self.internal["versions"]["vlc"] = vlc_version