Skip to content

Instantly share code, notes, and snippets.

@camwest
Created July 13, 2025 18:21
Show Gist options
  • Save camwest/3d65d9fb0ebcb6f8efc774f379531147 to your computer and use it in GitHub Desktop.
Save camwest/3d65d9fb0ebcb6f8efc774f379531147 to your computer and use it in GitHub Desktop.
Deterministic file naming in video-to-transcript
// Deterministic file naming in video-to-transcript
// From: https://github.com/camwest/video-to-transcript/blob/main/src/workspace.ts
/**
* Extract a safe directory name from a YouTube URL or file path
*/
function extractProjectId(input: string): string {
// Try to extract YouTube video ID
const videoIdMatch = input.match(/(?:v=|\/)([\w-]{11})(?:\?|&|$)/);
if (videoIdMatch) {
return videoIdMatch[1];
}
// For local files, use the filename without extension
const pathParts = input.split(/[/\\]/);
const filename = pathParts[pathParts.length - 1];
const nameWithoutExt = filename.replace(/\.[^.]+$/, '');
// Sanitize the filename to be filesystem-safe
return nameWithoutExt.replace(/[^a-zA-Z0-9-_]/g, '-').toLowerCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment