mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 16:58:12 +00:00
Misc cleanup (#73)
* Stop previously running zeroconf instances * Lots of formatting fixes * Use f-strings for time delta * More line fixes * Update requirements.txt * More misc cleanup * Simplify README.md
This commit is contained in:
@@ -38,7 +38,7 @@ class Config:
|
||||
|
||||
@classmethod
|
||||
def config_dir(cls):
|
||||
# Setup the config path
|
||||
# Set up the config path
|
||||
if current_system_os() == 'macos':
|
||||
local_config_path = os.path.expanduser('~/Library/Application Support/Zordon')
|
||||
elif current_system_os() == 'windows':
|
||||
@@ -49,7 +49,7 @@ class Config:
|
||||
|
||||
@classmethod
|
||||
def setup_config_dir(cls):
|
||||
# Setup the config path
|
||||
# Set up the config path
|
||||
local_config_dir = cls.config_dir()
|
||||
if os.path.exists(local_config_dir):
|
||||
return
|
||||
@@ -71,4 +71,4 @@ class Config:
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred while setting up the config directory: {e}")
|
||||
raise
|
||||
raise
|
||||
|
||||
@@ -4,9 +4,10 @@ from src.engines.ffmpeg.ffmpeg_engine import FFMPEG
|
||||
|
||||
def image_sequence_to_video(source_glob_pattern, output_path, framerate=24, encoder="prores_ks", profile=4,
|
||||
start_frame=1):
|
||||
subprocess.run([FFMPEG.default_renderer_path(), "-framerate", str(framerate), "-start_number", str(start_frame), "-i",
|
||||
f"{source_glob_pattern}", "-c:v", encoder, "-profile:v", str(profile), '-pix_fmt', 'yuva444p10le',
|
||||
output_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
||||
subprocess.run([FFMPEG.default_renderer_path(), "-framerate", str(framerate), "-start_number",
|
||||
str(start_frame), "-i", f"{source_glob_pattern}", "-c:v", encoder, "-profile:v", str(profile),
|
||||
'-pix_fmt', 'yuva444p10le', output_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
check=True)
|
||||
|
||||
|
||||
def save_first_frame(source_path, dest_path, max_width=1280):
|
||||
|
||||
@@ -36,9 +36,9 @@ def file_exists_in_mounts(filepath):
|
||||
path = os.path.normpath(path)
|
||||
components = []
|
||||
while True:
|
||||
path, component = os.path.split(path)
|
||||
if component:
|
||||
components.append(component)
|
||||
path, comp = os.path.split(path)
|
||||
if comp:
|
||||
components.append(comp)
|
||||
else:
|
||||
if path:
|
||||
components.append(path)
|
||||
@@ -64,20 +64,17 @@ def file_exists_in_mounts(filepath):
|
||||
|
||||
def get_time_elapsed(start_time=None, end_time=None):
|
||||
|
||||
from string import Template
|
||||
|
||||
class DeltaTemplate(Template):
|
||||
delimiter = "%"
|
||||
|
||||
def strfdelta(tdelta, fmt='%H:%M:%S'):
|
||||
d = {"D": tdelta.days}
|
||||
days = tdelta.days
|
||||
hours, rem = divmod(tdelta.seconds, 3600)
|
||||
minutes, seconds = divmod(rem, 60)
|
||||
d["H"] = '{:02d}'.format(hours)
|
||||
d["M"] = '{:02d}'.format(minutes)
|
||||
d["S"] = '{:02d}'.format(seconds)
|
||||
t = DeltaTemplate(fmt)
|
||||
return t.substitute(**d)
|
||||
|
||||
# Using f-strings for formatting
|
||||
formatted_str = fmt.replace('%D', f'{days}')
|
||||
formatted_str = formatted_str.replace('%H', f'{hours:02d}')
|
||||
formatted_str = formatted_str.replace('%M', f'{minutes:02d}')
|
||||
formatted_str = formatted_str.replace('%S', f'{seconds:02d}')
|
||||
return formatted_str
|
||||
|
||||
# calculate elapsed time
|
||||
elapsed_time = None
|
||||
@@ -95,7 +92,7 @@ def get_time_elapsed(start_time=None, end_time=None):
|
||||
def get_file_size_human(file_path):
|
||||
size_in_bytes = os.path.getsize(file_path)
|
||||
|
||||
# Convert size to a human readable format
|
||||
# Convert size to a human-readable format
|
||||
if size_in_bytes < 1024:
|
||||
return f"{size_in_bytes} B"
|
||||
elif size_in_bytes < 1024 ** 2:
|
||||
|
||||
@@ -22,6 +22,10 @@ class ZeroconfServer:
|
||||
cls.service_type = service_type
|
||||
cls.server_name = server_name
|
||||
cls.server_port = server_port
|
||||
try: # Stop any previously running instances
|
||||
socket.gethostbyname(socket.gethostname())
|
||||
except socket.gaierror:
|
||||
cls.stop()
|
||||
|
||||
@classmethod
|
||||
def start(cls, listen_only=False):
|
||||
@@ -82,7 +86,7 @@ class ZeroconfServer:
|
||||
def found_hostnames(cls):
|
||||
fetched_hostnames = [x.split(f'.{cls.service_type}')[0] for x in cls.client_cache.keys()]
|
||||
local_hostname = socket.gethostname()
|
||||
# Define a sort key function
|
||||
|
||||
def sort_key(hostname):
|
||||
# Return 0 if it's the local hostname so it comes first, else return 1
|
||||
return False if hostname == local_hostname else True
|
||||
@@ -98,6 +102,7 @@ class ZeroconfServer:
|
||||
decoded_server_info = {key.decode('utf-8'): value.decode('utf-8') for key, value in server_info.items()}
|
||||
return decoded_server_info
|
||||
|
||||
|
||||
# Example usage:
|
||||
if __name__ == "__main__":
|
||||
ZeroconfServer.configure("_zordon._tcp.local.", "foobar.local", 8080)
|
||||
|
||||
Reference in New Issue
Block a user