|
| 1 | +#!/usr/bin/env ruby |
| 2 | +require 'yaml' |
| 3 | +require 'fileutils' |
| 4 | + |
| 5 | +interviews = YAML.load_file("_data/interviews.yml")["items"] |
| 6 | +assets = YAML.load_file("_data/video_assets.yml")["items"] |
| 7 | + |
| 8 | +pending_interviews = interviews.select do |i| |
| 9 | + v = assets.find { |a| a["id"] == i["video_asset_id"] } |
| 10 | + v && (!v["transcript_id"] || v["transcript_id"].empty?) && v["platforms"]&.any? { |p| p["platform"] == "youtube" && p["asset_id"] } |
| 11 | +end |
| 12 | + |
| 13 | +puts "Found #{pending_interviews.size} pending interviews to transcribe." |
| 14 | + |
| 15 | +staging_dir = "tmp/transcript-id-staging" |
| 16 | +FileUtils.mkdir_p(staging_dir) |
| 17 | + |
| 18 | +pending_interviews.each_with_index do |i, idx| |
| 19 | + v = assets.find { |a| a["id"] == i["video_asset_id"] } |
| 20 | + yt = v["platforms"].find { |p| p["platform"] == "youtube" } |
| 21 | + yt_id = yt["asset_id"] |
| 22 | + video_asset_id = v["id"] |
| 23 | + |
| 24 | + puts "[#{idx + 1}/#{pending_interviews.size}] Transcribing Interview: #{i['id']} (YouTube ID: #{yt_id})" |
| 25 | + |
| 26 | + # Run the transcription pipeline |
| 27 | + url = "https://www.youtube.com/watch?v=#{yt_id}" |
| 28 | + cmd = "/Users/mike/.config/zsh/recipes/yt-transcribe \"#{url}\"" |
| 29 | + |
| 30 | + system(cmd) |
| 31 | + |
| 32 | + # Move the output to staging |
| 33 | + # yt-transcribe saves to ~/Downloads/transcripts/<yt_id>/<yt_id>.txt |
| 34 | + source_txt = File.expand_path("~/Downloads/transcripts/#{yt_id}/#{yt_id}.txt") |
| 35 | + |
| 36 | + if File.exist?(source_txt) |
| 37 | + # Prefixing with video_asset_id ensures deterministic mapping during ingest |
| 38 | + dest_txt = File.join(staging_dir, "#{video_asset_id}.txt") |
| 39 | + FileUtils.cp(source_txt, dest_txt) |
| 40 | + puts " ✓ Staged transcript as #{dest_txt}" |
| 41 | + else |
| 42 | + puts " ✕ Failed to find output transcript at #{source_txt}" |
| 43 | + end |
| 44 | +end |
| 45 | + |
| 46 | +puts "\nTranscription batch complete. You can now run './bin/transcripts ingest --source-dir tmp/transcript-id-staging --min-confidence 0.9 --auto-commit'" |
0 commit comments