add new video edit scripts for combine video and spliting video
This commit is contained in:
1 parent
ee93c06f7d
commit
856ab439f7
10 files changed
+199
-32
No files matched your search
+38
-5
@@ -45,12 +45,45 @@ def get_video_id_from_chat(json_path: str | Path) -> str | None:
|
||||
return None
|
||||
|
||||
def write_csv(data: list, file_name: str):
|
||||
# Open file with newline='' to prevent extra blank rows across platforms
|
||||
with open(file_name, "w", newline="", encoding="utf-8") as file:
|
||||
writer = csv.writer(file)
|
||||
"""Writes a list of dictionaries or objects to a CSV file."""
|
||||
|
||||
if not data:
|
||||
print(f"⚠️ Warning: No data provided to write to {file_name}.")
|
||||
return
|
||||
|
||||
# Determine if the data contains objects that need serialization
|
||||
first_item = data[0]
|
||||
|
||||
if hasattr(first_item, '__dict__') and not isinstance(first_item, (str, int, float, bool)):
|
||||
print("ℹ️ Detected object types. Converting objects to dictionary rows for CSV writing.")
|
||||
|
||||
# Write all rows at once
|
||||
writer.writerows(data)
|
||||
# Extract attributes/properties into a list of dictionaries
|
||||
data_to_write = []
|
||||
# We assume all objects in the list have the same structure for simplicity
|
||||
# A more robust solution would require knowing the schema.
|
||||
for item in data:
|
||||
row_dict = {}
|
||||
# Export all instance attributes to the dictionary
|
||||
for key, value in item.__dict__.items():
|
||||
row_dict[key] = value
|
||||
data_to_write.append(row_dict)
|
||||
|
||||
# Since csv.writer doesn't handle dicts directly, we list the keys from the first dict
|
||||
fieldnames = list(data_to_write[0].keys())
|
||||
|
||||
with open(file_name, "w", newline="", encoding="utf-8") as file:
|
||||
writer = csv.DictWriter(file, fieldnames=fieldnames)
|
||||
|
||||
writer.writeheader()
|
||||
writer.writerows(data_to_write)
|
||||
|
||||
else:
|
||||
# Assume data is already a list of lists/tuples
|
||||
with open(file_name, "w", newline="", encoding="utf-8") as file:
|
||||
writer = csv.writer(file)
|
||||
|
||||
# Write all rows at once
|
||||
writer.writerows(data)
|
||||
|
||||
def run_command(cmd_str: str, progress_prefix: str = "Progress", look_for: list = ["frame=", "time=", "fps=", "Rendering frame"]) -> bool:
|
||||
"""Runs a system command, streams its output live, and reports errors on failure."""
|
||||
|
||||
Reference in new issue
Block a user