mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 12:24:59 +00:00
style: Format code with linter
This commit is contained in:
parent
8404165db3
commit
791dc213fa
1 changed files with 17 additions and 15 deletions
|
@ -84,29 +84,32 @@ def generate_audio_openai(text, output_file, voice=VOICE):
|
||||||
def load_metadata(output_dir):
|
def load_metadata(output_dir):
|
||||||
"""Load the audio metadata JSON file if it exists."""
|
"""Load the audio metadata JSON file if it exists."""
|
||||||
metadata_file = os.path.join(output_dir, "metadata.json")
|
metadata_file = os.path.join(output_dir, "metadata.json")
|
||||||
|
|
||||||
if os.path.exists(metadata_file):
|
if os.path.exists(metadata_file):
|
||||||
try:
|
try:
|
||||||
with open(metadata_file, "r") as f:
|
with open(metadata_file, "r") as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
print(f"Warning: Could not parse metadata file {metadata_file}, will recreate it")
|
print(f"Warning: Could not parse metadata file {metadata_file}, will recreate it")
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def save_metadata(output_dir, metadata):
|
def save_metadata(output_dir, metadata):
|
||||||
"""Save the audio metadata to JSON file."""
|
"""Save the audio metadata to JSON file."""
|
||||||
metadata_file = os.path.join(output_dir, "metadata.json")
|
metadata_file = os.path.join(output_dir, "metadata.json")
|
||||||
|
|
||||||
with open(metadata_file, "w") as f:
|
with open(metadata_file, "w") as f:
|
||||||
json.dump(metadata, f, indent=2)
|
json.dump(metadata, f, indent=2)
|
||||||
|
|
||||||
|
|
||||||
def get_timestamp_key(time_sec):
|
def get_timestamp_key(time_sec):
|
||||||
"""Generate a consistent timestamp key format for metadata."""
|
"""Generate a consistent timestamp key format for metadata."""
|
||||||
minutes = time_sec // 60
|
minutes = time_sec // 60
|
||||||
seconds = time_sec % 60
|
seconds = time_sec % 60
|
||||||
return f"{minutes:02d}-{seconds:02d}"
|
return f"{minutes:02d}-{seconds:02d}"
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Generate TTS audio for recording commentary.")
|
parser = argparse.ArgumentParser(description="Generate TTS audio for recording commentary.")
|
||||||
parser.add_argument("markdown_file", help="Path to the recording markdown file")
|
parser.add_argument("markdown_file", help="Path to the recording markdown file")
|
||||||
|
@ -145,19 +148,19 @@ def main():
|
||||||
|
|
||||||
# Load existing metadata
|
# Load existing metadata
|
||||||
metadata = load_metadata(output_dir)
|
metadata = load_metadata(output_dir)
|
||||||
|
|
||||||
# Create a dictionary of current markers for easier comparison
|
# Create a dictionary of current markers for easier comparison
|
||||||
current_markers = {}
|
current_markers = {}
|
||||||
for time_sec, message in markers:
|
for time_sec, message in markers:
|
||||||
timestamp_key = get_timestamp_key(time_sec)
|
timestamp_key = get_timestamp_key(time_sec)
|
||||||
current_markers[timestamp_key] = message
|
current_markers[timestamp_key] = message
|
||||||
|
|
||||||
# Track files that need to be deleted (no longer in the markdown)
|
# Track files that need to be deleted (no longer in the markdown)
|
||||||
files_to_delete = []
|
files_to_delete = []
|
||||||
for timestamp_key in metadata:
|
for timestamp_key in metadata:
|
||||||
if timestamp_key not in current_markers:
|
if timestamp_key not in current_markers:
|
||||||
files_to_delete.append(f"{timestamp_key}.mp3")
|
files_to_delete.append(f"{timestamp_key}.mp3")
|
||||||
|
|
||||||
# Delete files that are no longer needed
|
# Delete files that are no longer needed
|
||||||
if files_to_delete and not args.dry_run:
|
if files_to_delete and not args.dry_run:
|
||||||
for filename in files_to_delete:
|
for filename in files_to_delete:
|
||||||
|
@ -173,22 +176,21 @@ def main():
|
||||||
timestamp_key = get_timestamp_key(time_sec)
|
timestamp_key = get_timestamp_key(time_sec)
|
||||||
filename = f"{timestamp_key}.mp3"
|
filename = f"{timestamp_key}.mp3"
|
||||||
output_file = os.path.join(output_dir, filename)
|
output_file = os.path.join(output_dir, filename)
|
||||||
|
|
||||||
# Check if we need to generate this file
|
# Check if we need to generate this file
|
||||||
needs_update = args.force or (
|
needs_update = args.force or (
|
||||||
timestamp_key not in metadata or
|
timestamp_key not in metadata or metadata[timestamp_key] != message
|
||||||
metadata[timestamp_key] != message
|
|
||||||
)
|
)
|
||||||
|
|
||||||
minutes = time_sec // 60
|
minutes = time_sec // 60
|
||||||
seconds = time_sec % 60
|
seconds = time_sec % 60
|
||||||
|
|
||||||
print(f"Marker at {minutes}:{seconds:02d} - {message}")
|
print(f"Marker at {minutes}:{seconds:02d} - {message}")
|
||||||
|
|
||||||
if not needs_update:
|
if not needs_update:
|
||||||
print(f" ✓ Audio file already exists with correct content")
|
print(f" ✓ Audio file already exists with correct content")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
print(f" Would generate: {output_file}")
|
print(f" Would generate: {output_file}")
|
||||||
else:
|
else:
|
||||||
|
@ -200,14 +202,14 @@ def main():
|
||||||
metadata[timestamp_key] = message
|
metadata[timestamp_key] = message
|
||||||
else:
|
else:
|
||||||
print(f" ✗ Failed to generate audio")
|
print(f" ✗ Failed to generate audio")
|
||||||
|
|
||||||
# Save updated metadata
|
# Save updated metadata
|
||||||
if not args.dry_run:
|
if not args.dry_run:
|
||||||
# Remove entries for deleted files
|
# Remove entries for deleted files
|
||||||
for timestamp_key in list(metadata.keys()):
|
for timestamp_key in list(metadata.keys()):
|
||||||
if timestamp_key not in current_markers:
|
if timestamp_key not in current_markers:
|
||||||
del metadata[timestamp_key]
|
del metadata[timestamp_key]
|
||||||
|
|
||||||
save_metadata(output_dir, metadata)
|
save_metadata(output_dir, metadata)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue