Created
July 13, 2025 18:21
-
-
Save camwest/3d65d9fb0ebcb6f8efc774f379531147 to your computer and use it in GitHub Desktop.
Deterministic file naming in video-to-transcript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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