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

Merge pull request #45 from deathbybandaid/dev

Dev
This commit is contained in:
Deathbybandaid 2020-11-09 14:34:53 -05:00 committed by GitHub
commit 931dc6bd52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 14 deletions

View File

@ -37,6 +37,10 @@ def run(settings, logger, db):
fhdhr = fHDHR_OBJ(settings, logger, db)
fhdhrweb = fHDHR_HTTP_Server(fhdhr)
# Ensure spawn on Windows instead of fork
if settings.dict["main"]["opersystem"] in ["Windows"]:
multiprocessing.set_start_method('spawn')
try:
print("HTTP Server Starting")

View File

@ -4,9 +4,10 @@ import configparser
import pathlib
import logging
import subprocess
import platform
import fHDHR.exceptions
from fHDHR.tools import isint, isfloat, is_arithmetic
from fHDHR.tools import isint, isfloat, is_arithmetic, is_docker
class Config():
@ -158,6 +159,22 @@ class Config():
if self.dict["fhdhr"]["stream_type"] not in ["direct", "ffmpeg"]:
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"],
@ -173,6 +190,8 @@ class Config():
except FileNotFoundError:
ffmpeg_version = None
self.dict["ffmpeg"]["version"] = ffmpeg_version
else:
self.dict["ffmpeg"]["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"]

View File

@ -108,7 +108,11 @@ class SSDPServer():
(host, port) = address
header, payload = data.decode().split('\r\n\r\n')[:2]
try:
header, payload = data.decode().split('\r\n\r\n')[:2]
except ValueError:
self.logger.error("Error with Received packet from {}: {}".format(address, data))
return
lines = header.split('\r\n')
cmd = lines[0].split(' ')

View File

@ -31,20 +31,18 @@ class Version_HTML():
fakefile.write(" <th></th>\n")
fakefile.write(" </tr>\n")
fakefile.write(" <tr>\n")
fakefile.write(" <td>%s</td>\n" % ("fHDHR"))
fakefile.write(" <td>%s</td>\n" % (str(self.fhdhr.version)))
fakefile.write(" </tr>\n")
table_guts = [
["fHDHR", self.fhdhr.version],
["Python", sys.version],
["Operating System", self.fhdhr.config.dict["main"]["opersystem"]],
["Using Docker", self.fhdhr.config.dict["main"]["isdocker"]],
["ffmpeg", self.fhdhr.config.dict["ffmpeg"]["version"]]
]
fakefile.write(" <tr>\n")
fakefile.write(" <td>%s</td>\n" % ("Python"))
fakefile.write(" <td>%s</td>\n" % (str(sys.version)))
fakefile.write(" </tr>\n")
if self.fhdhr.config.dict["fhdhr"]["stream_type"] == "ffmpeg":
for item in table_guts:
fakefile.write(" <tr>\n")
fakefile.write(" <td>%s</td>\n" % ("ffmpeg"))
fakefile.write(" <td>%s</td>\n" % (str(self.fhdhr.config.dict["ffmpeg"]["version"])))
fakefile.write(" <td>%s</td>\n" % (str(item[0])))
fakefile.write(" <td>%s</td>\n" % (str(item[1])))
fakefile.write(" </tr>\n")
for line in page_elements["end"]:

View File

@ -1,3 +1,5 @@
import os
import re
import ast
import requests
import xml.etree.ElementTree
@ -6,6 +8,17 @@ UNARY_OPS = (ast.UAdd, ast.USub)
BINARY_OPS = (ast.Add, ast.Sub, ast.Mult, ast.Div, ast.Mod)
def is_docker():
path = "/proc/self/cgroup"
if not os.path.isfile(path):
return False
with open(path) as f:
for line in f:
if re.match("\d+:[\w=]+:/docker(-[ce]e)?/\w+", line):
return True
return False
def sub_el(parent, name, text=None, **kwargs):
el = xml.etree.ElementTree.SubElement(parent, name, **kwargs)
if text: