python service http refactor start

This commit is contained in:
michalcourson
2026-02-14 11:24:09 -05:00
parent 5516ce9212
commit f3b883602e
27 changed files with 415 additions and 205 deletions

View File

@ -0,0 +1,48 @@
import os
import json
class MetaDataManager:
_instance = None
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance
def __init__(self):
# read metadata file from executing directory
self.metadata_file = os.path.join(os.getcwd(), "metadata.json")
if os.path.exists(self.metadata_file):
with open(self.metadata_file, "r") as f:
self.collections = json.load(f)
else:
self.collections = {}
def create_collection(self, name):
if name in self.collections:
raise ValueError(f"Collection '{name}' already exists.")
self.collections[name] = []
self.save_metadata()
def delete_collection(self, name):
if name not in self.collections:
raise ValueError(f"Collection '{name}' does not exist.")
del self.collections[name]
self.save_metadata()
def add_clip_to_collection(self, collection_name, clip_metadata):
if collection_name not in self.collections:
raise ValueError(f"Collection '{collection_name}' does not exist.")
self.collections[collection_name].append(clip_metadata)
self.save_metadata()
def get_collections(self):
return list(self.collections.keys())
def get_clips_in_collection(self, collection_name):
if collection_name not in self.collections:
raise ValueError(f"Collection '{collection_name}' does not exist.")
return self.collections[collection_name]
def save_metadata(self):
with open(self.metadata_file, "w") as f:
json.dump(self.collections, f, indent=4)