Guest User

Extract Closed Captions

a guest
Feb 14th, 2025
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.02 KB | Source Code | 0 0
  1. # Create a table that holds the exported URLs
  2. $table = Import-CSV C:\path\to\csvfile.csv
  3.  
  4. # Create an array to store all JSON objects
  5.  $masterArray = @()
  6.  
  7.  # Iterate through each row in the table
  8.  foreach ($row in $table) {
  9.      # Create the JSON structure
  10.      $jsonObject = [PSCustomObject]@{
  11.          Title       = $row.Title
  12.          URL         = $row.URL
  13.          video_id    = $row.video_id
  14.          Transcript  = (youtube_transcript_api.exe $row.video_id --format text)
  15.      }
  16.  
  17.      # Add the object to the master array
  18.      $masterArray += $jsonObject
  19.  
  20.      # Save individual JSONs if needed
  21.      $jsonOutput = $jsonObject | ConvertTo-Json -Depth 3
  22.      $fileName = ($row.Title -replace '[^\w\d]', '_') + "1" + ".json"
  23.      Set-Content -Path "C:\temp\transcripts\$fileName" -Value $jsonOutput
  24.  }
  25.  
  26.  # Convert the master array to JSON format
  27.  $masterJson = $masterArray | ConvertTo-Json -Depth 3
  28.  
  29.  # Save the master JSON file
  30.  Set-Content -Path "C:\temp\transcripts\master_transcripts.json" -Value $masterJson
  31.  
Advertisement
Add Comment
Please, Sign In to add comment